67 #ifndef ABSL_STRINGS_SUBSTITUTE_H_ 68 #define ABSL_STRINGS_SUBSTITUTE_H_ 72 #include <type_traits> 86 namespace substitute_internal {
103 template <
typename Allocator>
105 const std::basic_string<
char, std::char_traits<char>, Allocator>&
151 :
piece_(value ?
"true" :
"false") {}
158 template <
typename T,
161 (std::is_same<T, std::vector<bool>::reference>
::value ||
162 std::is_same<T, std::vector<bool>::const_reference>
::value)>* =
165 :
Arg(static_cast<bool>(value)) {}
169 Arg(
const void* value);
187 #if defined(ABSL_BAD_CALL_IF) 188 constexpr
int CalculateOneBit(
const char*
format) {
189 return (*format < '0' || *format >
'9') ? 0 : (1 << (*format -
'0'));
192 constexpr
const char* SkipNumber(
const char* format) {
193 return !*format ?
format : (format + 1);
196 constexpr
int PlaceholderBitmask(
const char* format) {
197 return !*format ? 0 : *format !=
'$' 198 ? PlaceholderBitmask(format + 1)
199 : (CalculateOneBit(format + 1) |
200 PlaceholderBitmask(SkipNumber(format + 1)));
202 #endif // ABSL_BAD_CALL_IF 348 #if defined(ABSL_BAD_CALL_IF) 352 ABSL_BAD_CALL_IF(substitute_internal::PlaceholderBitmask(format) != 0,
353 "There were no substitution arguments " 354 "but this format std::string has a $[0-9] in it");
358 ABSL_BAD_CALL_IF(substitute_internal::PlaceholderBitmask(format) != 1,
359 "There was 1 substitution argument given, but " 360 "this format std::string is either missing its $0, or " 361 "contains one of $1-$9");
366 ABSL_BAD_CALL_IF(substitute_internal::PlaceholderBitmask(format) != 3,
367 "There were 2 substitution arguments given, but " 368 "this format std::string is either missing its $0/$1, or " 369 "contains one of $2-$9");
375 ABSL_BAD_CALL_IF(substitute_internal::PlaceholderBitmask(format) != 7,
376 "There were 3 substitution arguments given, but " 377 "this format std::string is either missing its $0/$1/$2, or " 378 "contains one of $3-$9");
385 ABSL_BAD_CALL_IF(substitute_internal::PlaceholderBitmask(format) != 15,
386 "There were 4 substitution arguments given, but " 387 "this format std::string is either missing its $0-$3, or " 388 "contains one of $4-$9");
396 ABSL_BAD_CALL_IF(substitute_internal::PlaceholderBitmask(format) != 31,
397 "There were 5 substitution arguments given, but " 398 "this format std::string is either missing its $0-$4, or " 399 "contains one of $5-$9");
408 ABSL_BAD_CALL_IF(substitute_internal::PlaceholderBitmask(format) != 63,
409 "There were 6 substitution arguments given, but " 410 "this format std::string is either missing its $0-$5, or " 411 "contains one of $6-$9");
418 ABSL_BAD_CALL_IF(substitute_internal::PlaceholderBitmask(format) != 127,
419 "There were 7 substitution arguments given, but " 420 "this format std::string is either missing its $0-$6, or " 421 "contains one of $7-$9");
429 ABSL_BAD_CALL_IF(substitute_internal::PlaceholderBitmask(format) != 255,
430 "There were 8 substitution arguments given, but " 431 "this format std::string is either missing its $0-$7, or " 432 "contains one of $8-$9");
441 substitute_internal::PlaceholderBitmask(format) != 511,
442 "There were 9 substitution arguments given, but " 443 "this format std::string is either missing its $0-$8, or contains a $9");
452 ABSL_BAD_CALL_IF(substitute_internal::PlaceholderBitmask(format) != 1023,
453 "There were 10 substitution arguments given, but this " 454 "format std::string doesn't contain all of $0 through $9");
455 #endif // ABSL_BAD_CALL_IF 558 SubstituteAndAppend(&result, format, a0, a1, a2, a3, a4, a5, a6, a7, a8);
570 SubstituteAndAppend(&result, format, a0, a1, a2, a3, a4, a5, a6, a7, a8, a9);
574 #if defined(ABSL_BAD_CALL_IF) 578 ABSL_BAD_CALL_IF(substitute_internal::PlaceholderBitmask(format) != 0,
579 "There were no substitution arguments " 580 "but this format std::string has a $[0-9] in it");
583 ABSL_BAD_CALL_IF(substitute_internal::PlaceholderBitmask(format) != 1,
584 "There was 1 substitution argument given, but " 585 "this format std::string is either missing its $0, or " 586 "contains one of $1-$9");
590 ABSL_BAD_CALL_IF(substitute_internal::PlaceholderBitmask(format) != 3,
591 "There were 2 substitution arguments given, but " 592 "this format std::string is either missing its $0/$1, or " 593 "contains one of $2-$9");
598 ABSL_BAD_CALL_IF(substitute_internal::PlaceholderBitmask(format) != 7,
599 "There were 3 substitution arguments given, but " 600 "this format std::string is either missing its $0/$1/$2, or " 601 "contains one of $3-$9");
607 ABSL_BAD_CALL_IF(substitute_internal::PlaceholderBitmask(format) != 15,
608 "There were 4 substitution arguments given, but " 609 "this format std::string is either missing its $0-$3, or " 610 "contains one of $4-$9");
617 ABSL_BAD_CALL_IF(substitute_internal::PlaceholderBitmask(format) != 31,
618 "There were 5 substitution arguments given, but " 619 "this format std::string is either missing its $0-$4, or " 620 "contains one of $5-$9");
628 ABSL_BAD_CALL_IF(substitute_internal::PlaceholderBitmask(format) != 63,
629 "There were 6 substitution arguments given, but " 630 "this format std::string is either missing its $0-$5, or " 631 "contains one of $6-$9");
640 ABSL_BAD_CALL_IF(substitute_internal::PlaceholderBitmask(format) != 127,
641 "There were 7 substitution arguments given, but " 642 "this format std::string is either missing its $0-$6, or " 643 "contains one of $7-$9");
653 ABSL_BAD_CALL_IF(substitute_internal::PlaceholderBitmask(format) != 255,
654 "There were 8 substitution arguments given, but " 655 "this format std::string is either missing its $0-$7, or " 656 "contains one of $8-$9");
665 substitute_internal::PlaceholderBitmask(format) != 511,
666 "There were 9 substitution arguments given, but " 667 "this format std::string is either missing its $0-$8, or contains a $9");
676 ABSL_BAD_CALL_IF(substitute_internal::PlaceholderBitmask(format) != 1023,
677 "There were 10 substitution arguments given, but this " 678 "format std::string doesn't contain all of $0 through $9");
679 #endif // ABSL_BAD_CALL_IF 683 #endif // ABSL_STRINGS_SUBSTITUTE_H_ string_view NullSafeStringView(const char *p)
char * FastIntToBuffer(int32_t, char *)
Arg(const std::basic_string< char, std::char_traits< char >, Allocator > &value) noexcept
size_t SixDigitsToBuffer(double d, char *buffer)
Arg(absl::string_view value)
typename std::enable_if< B, T >::type enable_if_t
char scratch_[numbers_internal::kFastToBufferSize]
Arg(unsigned long long value)
#define ABSL_MUST_USE_RESULT
std::string format(const std::string &, const time_point< seconds > &, const femtoseconds &, const time_zone &)
Arg(unsigned short value)
absl::string_view piece() const
void SubstituteAndAppend(std::string *output, absl::string_view format)
#define ABSL_ARRAYSIZE(array)
static const int kFastToBufferSize
Arg & operator=(const Arg &)=delete
void SubstituteAndAppendArray(std::string *output, absl::string_view format, const absl::string_view *args_array, size_t num_args)
ABSL_MUST_USE_RESULT std::string Substitute(absl::string_view format)