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 ||
193 #if defined(ABSL_BAD_CALL_IF)
194 constexpr
int CalculateOneBit(
const char*
format) {
199 return (*format < '0' || *format >
'9') ? (*
format ==
'$' ? 0 : -1)
203 constexpr
const char* SkipNumber(
const char*
format) {
207 constexpr
int PlaceholderBitmask(
const char*
format) {
211 : (CalculateOneBit(
format + 1) |
212 PlaceholderBitmask(SkipNumber(
format + 1)));
214 #endif // ABSL_BAD_CALL_IF
286 a3.piece(), a4.piece()};
299 a3.piece(), a4.piece(), a5.piece()};
313 a3.piece(), a4.piece(), a5.piece(),
326 a3.piece(), a4.piece(), a5.piece(),
327 a6.piece(), a7.piece()};
340 a3.piece(), a4.piece(), a5.piece(),
341 a6.piece(), a7.piece(), a8.piece()};
354 a0.piece(),
a1.piece(),
a2.piece(), a3.piece(), a4.piece(),
355 a5.piece(), a6.piece(), a7.piece(), a8.piece(), a9.piece()};
360 #if defined(ABSL_BAD_CALL_IF)
364 ABSL_BAD_CALL_IF(substitute_internal::PlaceholderBitmask(
format) != 0,
365 "There were no substitution arguments "
366 "but this format string has a $[0-9] in it");
370 ABSL_BAD_CALL_IF(substitute_internal::PlaceholderBitmask(
format) != 1,
371 "There was 1 substitution argument given, but "
372 "this format string is either missing its $0, or "
373 "contains one of $1-$9");
378 ABSL_BAD_CALL_IF(substitute_internal::PlaceholderBitmask(
format) != 3,
379 "There were 2 substitution arguments given, but "
380 "this format string is either missing its $0/$1, or "
381 "contains one of $2-$9");
387 ABSL_BAD_CALL_IF(substitute_internal::PlaceholderBitmask(
format) != 7,
388 "There were 3 substitution arguments given, but "
389 "this format string is either missing its $0/$1/$2, or "
390 "contains one of $3-$9");
397 ABSL_BAD_CALL_IF(substitute_internal::PlaceholderBitmask(
format) != 15,
398 "There were 4 substitution arguments given, but "
399 "this format string is either missing its $0-$3, or "
400 "contains one of $4-$9");
408 ABSL_BAD_CALL_IF(substitute_internal::PlaceholderBitmask(
format) != 31,
409 "There were 5 substitution arguments given, but "
410 "this format string is either missing its $0-$4, or "
411 "contains one of $5-$9");
420 ABSL_BAD_CALL_IF(substitute_internal::PlaceholderBitmask(
format) != 63,
421 "There were 6 substitution arguments given, but "
422 "this format string is either missing its $0-$5, or "
423 "contains one of $6-$9");
430 ABSL_BAD_CALL_IF(substitute_internal::PlaceholderBitmask(
format) != 127,
431 "There were 7 substitution arguments given, but "
432 "this format string is either missing its $0-$6, or "
433 "contains one of $7-$9");
441 ABSL_BAD_CALL_IF(substitute_internal::PlaceholderBitmask(
format) != 255,
442 "There were 8 substitution arguments given, but "
443 "this format string is either missing its $0-$7, or "
444 "contains one of $8-$9");
453 substitute_internal::PlaceholderBitmask(
format) != 511,
454 "There were 9 substitution arguments given, but "
455 "this format string is either missing its $0-$8, or contains a $9");
464 ABSL_BAD_CALL_IF(substitute_internal::PlaceholderBitmask(
format) != 1023,
465 "There were 10 substitution arguments given, but this "
466 "format string doesn't contain all of $0 through $9");
467 #endif // ABSL_BAD_CALL_IF
570 SubstituteAndAppend(&
result,
format, a0,
a1,
a2, a3, a4, a5, a6, a7, a8);
582 SubstituteAndAppend(&
result,
format, a0,
a1,
a2, a3, a4, a5, a6, a7, a8, a9);
586 #if defined(ABSL_BAD_CALL_IF)
590 ABSL_BAD_CALL_IF(substitute_internal::PlaceholderBitmask(
format) != 0,
591 "There were no substitution arguments "
592 "but this format string has a $[0-9] in it");
595 ABSL_BAD_CALL_IF(substitute_internal::PlaceholderBitmask(
format) != 1,
596 "There was 1 substitution argument given, but "
597 "this format string is either missing its $0, or "
598 "contains one of $1-$9");
602 ABSL_BAD_CALL_IF(substitute_internal::PlaceholderBitmask(
format) != 3,
603 "There were 2 substitution arguments given, but "
604 "this format string is either missing its $0/$1, or "
605 "contains one of $2-$9");
610 ABSL_BAD_CALL_IF(substitute_internal::PlaceholderBitmask(
format) != 7,
611 "There were 3 substitution arguments given, but "
612 "this format string is either missing its $0/$1/$2, or "
613 "contains one of $3-$9");
619 ABSL_BAD_CALL_IF(substitute_internal::PlaceholderBitmask(
format) != 15,
620 "There were 4 substitution arguments given, but "
621 "this format string is either missing its $0-$3, or "
622 "contains one of $4-$9");
629 ABSL_BAD_CALL_IF(substitute_internal::PlaceholderBitmask(
format) != 31,
630 "There were 5 substitution arguments given, but "
631 "this format string is either missing its $0-$4, or "
632 "contains one of $5-$9");
640 ABSL_BAD_CALL_IF(substitute_internal::PlaceholderBitmask(
format) != 63,
641 "There were 6 substitution arguments given, but "
642 "this format string is either missing its $0-$5, or "
643 "contains one of $6-$9");
652 ABSL_BAD_CALL_IF(substitute_internal::PlaceholderBitmask(
format) != 127,
653 "There were 7 substitution arguments given, but "
654 "this format string is either missing its $0-$6, or "
655 "contains one of $7-$9");
665 ABSL_BAD_CALL_IF(substitute_internal::PlaceholderBitmask(
format) != 255,
666 "There were 8 substitution arguments given, but "
667 "this format string is either missing its $0-$7, or "
668 "contains one of $8-$9");
677 substitute_internal::PlaceholderBitmask(
format) != 511,
678 "There were 9 substitution arguments given, but "
679 "this format string is either missing its $0-$8, or contains a $9");
688 ABSL_BAD_CALL_IF(substitute_internal::PlaceholderBitmask(
format) != 1023,
689 "There were 10 substitution arguments given, but this "
690 "format string doesn't contain all of $0 through $9");
691 #endif // ABSL_BAD_CALL_IF
696 #endif // ABSL_STRINGS_SUBSTITUTE_H_