Add c specifier support to integral types (#1652)
This commit is contained in:
parent
6b219a58db
commit
6d66de3805
@ -1235,6 +1235,9 @@ FMT_CONSTEXPR void handle_int_type_spec(char spec, Handler&& handler) {
|
|||||||
case 'L':
|
case 'L':
|
||||||
handler.on_num();
|
handler.on_num();
|
||||||
break;
|
break;
|
||||||
|
case 'c':
|
||||||
|
handler.on_chr();
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
handler.on_error();
|
handler.on_error();
|
||||||
}
|
}
|
||||||
@ -1326,6 +1329,7 @@ template <typename ErrorHandler> class int_type_checker : private ErrorHandler {
|
|||||||
FMT_CONSTEXPR void on_bin() {}
|
FMT_CONSTEXPR void on_bin() {}
|
||||||
FMT_CONSTEXPR void on_oct() {}
|
FMT_CONSTEXPR void on_oct() {}
|
||||||
FMT_CONSTEXPR void on_num() {}
|
FMT_CONSTEXPR void on_num() {}
|
||||||
|
FMT_CONSTEXPR void on_chr() {}
|
||||||
|
|
||||||
FMT_CONSTEXPR void on_error() {
|
FMT_CONSTEXPR void on_error() {
|
||||||
ErrorHandler::on_error("invalid type specifier");
|
ErrorHandler::on_error("invalid type specifier");
|
||||||
@ -1561,6 +1565,8 @@ template <typename OutputIt, typename Char, typename UInt> struct int_writer {
|
|||||||
num_writer{abs_value, size, groups, sep});
|
num_writer{abs_value, size, groups, sep});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void on_chr() { *out++ = static_cast<Char>(abs_value); }
|
||||||
|
|
||||||
FMT_NORETURN void on_error() {
|
FMT_NORETURN void on_error() {
|
||||||
FMT_THROW(format_error("invalid type specifier"));
|
FMT_THROW(format_error("invalid type specifier"));
|
||||||
}
|
}
|
||||||
|
@ -1082,7 +1082,8 @@ TEST(FormatterTest, FormatShort) {
|
|||||||
TEST(FormatterTest, FormatInt) {
|
TEST(FormatterTest, FormatInt) {
|
||||||
EXPECT_THROW_MSG(format("{0:v", 42), format_error,
|
EXPECT_THROW_MSG(format("{0:v", 42), format_error,
|
||||||
"missing '}' in format string");
|
"missing '}' in format string");
|
||||||
check_unknown_types(42, "bBdoxXnL", "integer");
|
check_unknown_types(42, "bBdoxXnLc", "integer");
|
||||||
|
EXPECT_EQ("x", format("{:c}", static_cast<int>('x')));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(FormatterTest, FormatBin) {
|
TEST(FormatterTest, FormatBin) {
|
||||||
|
Loading…
Reference in New Issue
Block a user