70 #ifndef ABSL_STRINGS_SUBSTITUTE_H_
71 #define ABSL_STRINGS_SUBSTITUTE_H_
75 #include <type_traits>
78 #include "absl/base/macros.h"
79 #include "absl/base/port.h"
80 #include "absl/strings/ascii.h"
81 #include "absl/strings/escaping.h"
82 #include "absl/strings/numbers.h"
83 #include "absl/strings/str_cat.h"
84 #include "absl/strings/str_split.h"
85 #include "absl/strings/string_view.h"
86 #include "absl/strings/strip.h"
90 namespace substitute_internal {
107 template <
typename Allocator>
109 const std::basic_string<
char, std::char_traits<char>, Allocator>&
164 template <
typename T,
167 (std::is_same<T, std::vector<bool>::reference>
::value ||
179 template <
typename T,
180 typename =
typename std::enable_if<
181 std::is_enum<T>{} && !std::is_convertible<T, int>{}>
::type>
201 #if defined(ABSL_BAD_CALL_IF)
202 constexpr
int CalculateOneBit(
const char*
format) {
207 return (*format < '0' || *format >
'9') ? (*
format ==
'$' ? 0 : -1)
211 constexpr
const char* SkipNumber(
const char*
format) {
215 constexpr
int PlaceholderBitmask(
const char*
format) {
219 : (CalculateOneBit(
format + 1) |
220 PlaceholderBitmask(SkipNumber(
format + 1)));
222 #endif // ABSL_BAD_CALL_IF
368 #if defined(ABSL_BAD_CALL_IF)
373 substitute_internal::PlaceholderBitmask(
format) != 0,
374 "There were no substitution arguments "
375 "but this format string either has a $[0-9] in it or contains "
376 "an unescaped $ character (use $$ instead)");
380 ABSL_BAD_CALL_IF(substitute_internal::PlaceholderBitmask(
format) != 1,
381 "There was 1 substitution argument given, but "
382 "this format string is missing its $0, contains "
383 "one of $1-$9, or contains an unescaped $ character (use "
390 substitute_internal::PlaceholderBitmask(
format) != 3,
391 "There were 2 substitution arguments given, but this format string is "
392 "missing its $0/$1, contains one of $2-$9, or contains an "
393 "unescaped $ character (use $$ instead)");
400 substitute_internal::PlaceholderBitmask(
format) != 7,
401 "There were 3 substitution arguments given, but "
402 "this format string is missing its $0/$1/$2, contains one of "
403 "$3-$9, or contains an unescaped $ character (use $$ instead)");
411 substitute_internal::PlaceholderBitmask(
format) != 15,
412 "There were 4 substitution arguments given, but "
413 "this format string is missing its $0-$3, contains one of "
414 "$4-$9, or contains an unescaped $ character (use $$ instead)");
423 substitute_internal::PlaceholderBitmask(
format) != 31,
424 "There were 5 substitution arguments given, but "
425 "this format string is missing its $0-$4, contains one of "
426 "$5-$9, or contains an unescaped $ character (use $$ instead)");
436 substitute_internal::PlaceholderBitmask(
format) != 63,
437 "There were 6 substitution arguments given, but "
438 "this format string is missing its $0-$5, contains one of "
439 "$6-$9, or contains an unescaped $ character (use $$ instead)");
447 substitute_internal::PlaceholderBitmask(
format) != 127,
448 "There were 7 substitution arguments given, but "
449 "this format string is missing its $0-$6, contains one of "
450 "$7-$9, or contains an unescaped $ character (use $$ instead)");
459 substitute_internal::PlaceholderBitmask(
format) != 255,
460 "There were 8 substitution arguments given, but "
461 "this format string is missing its $0-$7, contains one of "
462 "$8-$9, or contains an unescaped $ character (use $$ instead)");
471 substitute_internal::PlaceholderBitmask(
format) != 511,
472 "There were 9 substitution arguments given, but "
473 "this format string is missing its $0-$8, contains a $9, or "
474 "contains an unescaped $ character (use $$ instead)");
484 substitute_internal::PlaceholderBitmask(
format) != 1023,
485 "There were 10 substitution arguments given, but this "
486 "format string either doesn't contain all of $0 through $9 or "
487 "contains an unescaped $ character (use $$ instead)");
488 #endif // ABSL_BAD_CALL_IF
591 SubstituteAndAppend(&
result,
format, a0,
a1,
a2, a3, a4, a5, a6, a7, a8);
603 SubstituteAndAppend(&
result,
format, a0,
a1,
a2, a3, a4, a5, a6, a7, a8, a9);
607 #if defined(ABSL_BAD_CALL_IF)
611 ABSL_BAD_CALL_IF(substitute_internal::PlaceholderBitmask(
format) != 0,
612 "There were no substitution arguments "
613 "but this format string either has a $[0-9] in it or "
614 "contains an unescaped $ character (use $$ instead)");
618 substitute_internal::PlaceholderBitmask(
format) != 1,
619 "There was 1 substitution argument given, but "
620 "this format string is missing its $0, contains one of $1-$9, "
621 "or contains an unescaped $ character (use $$ instead)");
626 substitute_internal::PlaceholderBitmask(
format) != 3,
627 "There were 2 substitution arguments given, but "
628 "this format string is missing its $0/$1, contains one of "
629 "$2-$9, or contains an unescaped $ character (use $$ instead)");
635 substitute_internal::PlaceholderBitmask(
format) != 7,
636 "There were 3 substitution arguments given, but "
637 "this format string is missing its $0/$1/$2, contains one of "
638 "$3-$9, or contains an unescaped $ character (use $$ instead)");
645 substitute_internal::PlaceholderBitmask(
format) != 15,
646 "There were 4 substitution arguments given, but "
647 "this format string is missing its $0-$3, contains one of "
648 "$4-$9, or contains an unescaped $ character (use $$ instead)");
656 substitute_internal::PlaceholderBitmask(
format) != 31,
657 "There were 5 substitution arguments given, but "
658 "this format string is missing its $0-$4, contains one of "
659 "$5-$9, or contains an unescaped $ character (use $$ instead)");
668 substitute_internal::PlaceholderBitmask(
format) != 63,
669 "There were 6 substitution arguments given, but "
670 "this format string is missing its $0-$5, contains one of "
671 "$6-$9, or contains an unescaped $ character (use $$ instead)");
681 substitute_internal::PlaceholderBitmask(
format) != 127,
682 "There were 7 substitution arguments given, but "
683 "this format string is missing its $0-$6, contains one of "
684 "$7-$9, or contains an unescaped $ character (use $$ instead)");
695 substitute_internal::PlaceholderBitmask(
format) != 255,
696 "There were 8 substitution arguments given, but "
697 "this format string is missing its $0-$7, contains one of "
698 "$8-$9, or contains an unescaped $ character (use $$ instead)");
707 substitute_internal::PlaceholderBitmask(
format) != 511,
708 "There were 9 substitution arguments given, but "
709 "this format string is missing its $0-$8, contains a $9, or "
710 "contains an unescaped $ character (use $$ instead)");
720 substitute_internal::PlaceholderBitmask(
format) != 1023,
721 "There were 10 substitution arguments given, but this "
722 "format string either doesn't contain all of $0 through $9 or "
723 "contains an unescaped $ character (use $$ instead)");
724 #endif // ABSL_BAD_CALL_IF
729 #endif // ABSL_STRINGS_SUBSTITUTE_H_