diff --git a/include/fmt/format.h b/include/fmt/format.h index 873e98bd..c033c1f1 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -1235,6 +1235,9 @@ FMT_CONSTEXPR void handle_int_type_spec(char spec, Handler&& handler) { case 'L': handler.on_num(); break; + case 'c': + handler.on_chr(); + break; default: handler.on_error(); } @@ -1326,6 +1329,7 @@ template class int_type_checker : private ErrorHandler { FMT_CONSTEXPR void on_bin() {} FMT_CONSTEXPR void on_oct() {} FMT_CONSTEXPR void on_num() {} + FMT_CONSTEXPR void on_chr() {} FMT_CONSTEXPR void on_error() { ErrorHandler::on_error("invalid type specifier"); @@ -1561,6 +1565,8 @@ template struct int_writer { num_writer{abs_value, size, groups, sep}); } + void on_chr() { *out++ = static_cast(abs_value); } + FMT_NORETURN void on_error() { FMT_THROW(format_error("invalid type specifier")); } diff --git a/test/format-test.cc b/test/format-test.cc index dc49f3a8..dfdf2e45 100644 --- a/test/format-test.cc +++ b/test/format-test.cc @@ -1082,7 +1082,8 @@ TEST(FormatterTest, FormatShort) { TEST(FormatterTest, FormatInt) { EXPECT_THROW_MSG(format("{0:v", 42), format_error, "missing '}' in format string"); - check_unknown_types(42, "bBdoxXnL", "integer"); + check_unknown_types(42, "bBdoxXnLc", "integer"); + EXPECT_EQ("x", format("{:c}", static_cast('x'))); } TEST(FormatterTest, FormatBin) {