about summary refs log tree commit diff
path: root/absl/strings/substitute.h
diff options
context:
space:
mode:
Diffstat (limited to 'absl/strings/substitute.h')
-rw-r--r--absl/strings/substitute.h7
1 files changed, 6 insertions, 1 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) {