summaryrefslogtreecommitdiff
path: root/absl/strings/internal/str_format
diff options
context:
space:
mode:
Diffstat (limited to 'absl/strings/internal/str_format')
-rw-r--r--absl/strings/internal/str_format/arg.cc11
-rw-r--r--absl/strings/internal/str_format/arg.h9
2 files changed, 19 insertions, 1 deletions
diff --git a/absl/strings/internal/str_format/arg.cc b/absl/strings/internal/str_format/arg.cc
index b0e06bfb..967fe9ca 100644
--- a/absl/strings/internal/str_format/arg.cc
+++ b/absl/strings/internal/str_format/arg.cc
@@ -344,7 +344,7 @@ bool ConvertIntArg(T v, FormatConversionSpecImpl conv, FormatSinkImpl *sink) {
return ConvertFloatImpl(static_cast<double>(v), conv, sink);
default:
- ABSL_ASSUME(false);
+ ABSL_ASSUME(false);
}
if (conv.is_basic()) {
@@ -376,6 +376,15 @@ inline bool ConvertStringArg(string_view v, const FormatConversionSpecImpl conv,
} // namespace
+bool ConvertBoolArg(bool v, FormatSinkImpl *sink) {
+ if (v) {
+ sink->Append("true");
+ } else {
+ sink->Append("false");
+ }
+ return true;
+}
+
// ==================== Strings ====================
StringConvertResult FormatConvertImpl(const std::string &v,
const FormatConversionSpecImpl conv,
diff --git a/absl/strings/internal/str_format/arg.h b/absl/strings/internal/str_format/arg.h
index 3c2bb3e6..2dfbf728 100644
--- a/absl/strings/internal/str_format/arg.h
+++ b/absl/strings/internal/str_format/arg.h
@@ -186,6 +186,8 @@ using CharConvertResult = ArgConvertResult<FormatConversionCharSetUnion(
FormatConversionCharSetInternal::kNumeric,
FormatConversionCharSetInternal::kStar)>;
+bool ConvertBoolArg(bool v, FormatSinkImpl* sink);
+
// Floats.
FloatingConvertResult FormatConvertImpl(float v, FormatConversionSpecImpl conv,
FormatSinkImpl* sink);
@@ -234,9 +236,16 @@ IntegralConvertResult FormatConvertImpl(int128 v, FormatConversionSpecImpl conv,
IntegralConvertResult FormatConvertImpl(uint128 v,
FormatConversionSpecImpl conv,
FormatSinkImpl* sink);
+
+// This function needs to be a template due to ambiguity regarding type
+// conversions.
template <typename T, enable_if_t<std::is_same<T, bool>::value, int> = 0>
IntegralConvertResult FormatConvertImpl(T v, FormatConversionSpecImpl conv,
FormatSinkImpl* sink) {
+ if (conv.conversion_char() == FormatConversionCharInternal::v) {
+ return {ConvertBoolArg(v, sink)};
+ }
+
return FormatConvertImpl(static_cast<int>(v), conv, sink);
}