diff options
Diffstat (limited to 'absl/strings')
-rw-r--r-- | absl/strings/substitute.h | 7 | ||||
-rw-r--r-- | absl/strings/substitute_test.cc | 4 |
2 files changed, 8 insertions, 3 deletions
diff --git a/absl/strings/substitute.h b/absl/strings/substitute.h index 766aca42b313..4d0984d3d1fc 100644 --- a/absl/strings/substitute.h +++ b/absl/strings/substitute.h @@ -190,7 +190,12 @@ void SubstituteAndAppendArray(std::string* output, absl::string_view format, #if defined(ABSL_BAD_CALL_IF) constexpr int CalculateOneBit(const char* format) { - return (*format < '0' || *format > '9') ? 0 : (1 << (*format - '0')); + // Returns: + // * 2^N for '$N' when N is in [0-9] + // * 0 for correct '$' escaping: '$$'. + // * -1 otherwise. + return (*format < '0' || *format > '9') ? (*format == '$' ? 0 : -1) + : (1 << (*format - '0')); } constexpr const char* SkipNumber(const char* format) { diff --git a/absl/strings/substitute_test.cc b/absl/strings/substitute_test.cc index b005f0f47caa..450cd2bcfffe 100644 --- a/absl/strings/substitute_test.cc +++ b/absl/strings/substitute_test.cc @@ -192,10 +192,10 @@ TEST(SubstituteDeathTest, SubstituteDeath) { "Invalid absl::Substitute\\(\\) format std::string: asked for \"\\$2\", " "but only 2 args were given."); EXPECT_DEBUG_DEATH( - static_cast<void>(absl::Substitute("-$z-")), + static_cast<void>(absl::Substitute(absl::string_view("-$z-"))), "Invalid absl::Substitute\\(\\) format std::string: \"-\\$z-\""); EXPECT_DEBUG_DEATH( - static_cast<void>(absl::Substitute("-$")), + static_cast<void>(absl::Substitute(absl::string_view("-$"))), "Invalid absl::Substitute\\(\\) format std::string: \"-\\$\""); } |