// 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 <assert.h> #include <cstddef> #include <cstdint> #include <cstring> #include <initializer_list> #include <limits> #include <string> #include "absl/base/config.h" #include "absl/base/internal/raw_logging.h" #include "absl/base/nullability.h" #include "absl/strings/internal/resize_uninitialized.h" #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 { // Append is merely a version of memcpy that returns the address of the byte // after the area just overwritten. inline absl::Nonnull<char*> Append(absl::Nonnull<char*> out, const AlphaNum& x) { … } inline void STLStringAppendUninitializedAmortized(std::string* dest, size_t to_append) { … } } // namespace std::string StrCat(const AlphaNum& a, const AlphaNum& b) { … } std::string StrCat(const AlphaNum& a, const AlphaNum& b, const AlphaNum& c) { … } std::string StrCat(const AlphaNum& a, const AlphaNum& b, const AlphaNum& c, const AlphaNum& d) { … } namespace strings_internal { // Do not call directly - these are not part of the public API. std::string CatPieces(std::initializer_list<absl::string_view> pieces) { … } // It's possible to call StrAppend with an absl::string_view that is itself a // fragment of the string we're appending to. However the results of this are // random. Therefore, check for this in debug mode. Use unsigned math so we // only have to do one comparison. Note, there's an exception case: appending an // empty string is always allowed. #define ASSERT_NO_OVERLAP(dest, src) … void AppendPieces(absl::Nonnull<std::string*> dest, std::initializer_list<absl::string_view> pieces) { … } } // namespace strings_internal void StrAppend(absl::Nonnull<std::string*> dest, const AlphaNum& a) { … } void StrAppend(absl::Nonnull<std::string*> dest, const AlphaNum& a, const AlphaNum& b) { … } void StrAppend(absl::Nonnull<std::string*> dest, const AlphaNum& a, const AlphaNum& b, const AlphaNum& c) { … } void StrAppend(absl::Nonnull<std::string*> dest, const AlphaNum& a, const AlphaNum& b, const AlphaNum& c, const AlphaNum& d) { … } ABSL_NAMESPACE_END } // namespace absl