summaryrefslogtreecommitdiff
path: root/absl/strings/str_cat.cc
blob: 5ec029959a0d4210fe94e573453b6144f495c94a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// Copyright 2017 The Abseil Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include "absl/strings/str_cat.h"

#include <cstdint>
#include <string>

#include "absl/strings/string_view.h"

namespace absl {
ABSL_NAMESPACE_BEGIN

// ----------------------------------------------------------------------
// StrCat()
//    This merges the given strings or integers, with no delimiter. This
//    is designed to be the fastest possible way to construct a string out
//    of a mix of raw C strings, string_views, strings, and integer values.
// ----------------------------------------------------------------------

namespace strings_internal {

bool HaveOverlap(const std::string& x, absl::string_view y) {
  if (y.empty()) return false;
  // TODO(b/290623057): Re-evaluate the check below: it detects when buffers
  // overlap (which is good) but it also introduces undefined behaviour when
  // buffers don't overlap (substracting pointers that do not belong to the same
  // array is UB [expr.add]). In other words, if compiler assumes that a program
  // never has UB, then it can replace `assert(HaveOverlap(x, y))` with
  // `assert(false)`.
  return (uintptr_t(y.data() - x.data()) <= uintptr_t(x.size()));
}

#if defined(__GNUC__) && !defined(__clang__)
char* AppendAlphaNum(char* dst, const AlphaNum& a) {
  return std::copy_n(a.data(), a.size(), dst);
}
#endif

}  // namespace strings_internal

ABSL_NAMESPACE_END
}  // namespace absl