26 namespace substitute_internal {
33 for (
size_t i = 0;
i < format.
size();
i++) {
34 if (format[
i] ==
'$') {
35 if (
i + 1 >= format.
size()) {
38 "Invalid strings::Substitute() format std::string: \"%s\".",
43 int index = format[
i + 1] -
'0';
44 if (static_cast<size_t>(index) >= num_args) {
48 "Invalid strings::Substitute() format std::string: asked for \"$" 49 "%d\", but only %d args were given. Full format std::string was: " 51 index, static_cast<int>(num_args),
absl::CEscape(format).c_str());
55 size += args_array[index].
size();
57 }
else if (format[
i + 1] ==
'$') {
63 "Invalid strings::Substitute() format std::string: \"%s\".",
73 if (size == 0)
return;
76 size_t original_size = output->size();
78 char* target = &(*output)[original_size];
79 for (
size_t i = 0;
i < format.
size();
i++) {
80 if (format[
i] ==
'$') {
83 target = std::copy(src.
begin(), src.
end(), target);
85 }
else if (format[
i + 1] ==
'$') {
90 *target++ = format[
i];
94 assert(target == output->data() + output->size());
99 static_assert(
sizeof(
scratch_) >=
sizeof(value) * 2 + 2,
100 "fix sizeof(scratch_)");
101 if (value ==
nullptr) {
105 uintptr_t num =
reinterpret_cast<uintptr_t
>(
value);
107 *--ptr = kHexDigits[num & 0xf];
122 *--writer = kHexDigits[value & 0xF];
124 }
while (value != 0);
127 if (end - writer < hex.
width) {
128 beg = end - hex.
width;
129 std::fill_n(beg, writer - beg, hex.
fill);
141 char*
const minfill = end - dec.
width;
146 *--writer =
'0' + (value % 10);
149 *--writer =
'0' +
value;
150 if (neg) *--writer =
'-';
152 ptrdiff_t fillers = writer - minfill;
156 bool add_sign_again =
false;
157 if (neg && dec.
fill ==
'0') {
159 add_sign_again =
true;
162 std::fill_n(writer, fillers, dec.
fill);
163 if (add_sign_again) *--writer =
'-';
std::string CEscape(absl::string_view src)
#define ABSL_RAW_LOG(severity,...)
constexpr size_type size() const noexcept
char scratch_[numbers_internal::kFastToBufferSize]
void STLStringResizeUninitialized(string_type *s, size_t new_size)
std::string format(const std::string &, const time_point< seconds > &, const femtoseconds &, const time_zone &)
constexpr const_iterator begin() const noexcept
static const char kHexDigits[]
bool ascii_isdigit(unsigned char c)
static const int kFastToBufferSize
void SubstituteAndAppendArray(std::string *output, absl::string_view format, const absl::string_view *args_array, size_t num_args)
constexpr const_iterator end() const noexcept