diff --git a/include/fmt/format.h b/include/fmt/format.h index 082a8840..2f8ab84f 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -1413,7 +1413,6 @@ FMT_CONSTEXPR void handle_int_type_spec(char spec, Handler&& handler) { #ifdef FMT_DEPRECATED_N_SPECIFIER case 'n': #endif - case 'L': handler.on_num(); break; case 'c': @@ -1463,7 +1462,6 @@ FMT_CONSTEXPR float_specs parse_float_type_spec( #ifdef FMT_DEPRECATED_N_SPECIFIER case 'n': #endif - case 'L': result.locale = true; break; default: @@ -1676,6 +1674,14 @@ template struct int_writer { return string_view(prefix, prefix_size); } + void write_dec() { + auto num_digits = count_digits(abs_value); + out = write_int( + out, num_digits, get_prefix(), specs, [this, num_digits](iterator it) { + return format_decimal(it, abs_value, num_digits).end; + }); + } + template FMT_CONSTEXPR int_writer(OutputIt output, locale_ref loc, Int value, const basic_format_specs& s) @@ -1697,11 +1703,7 @@ template struct int_writer { FMT_CONSTEXPR void on_dec() { if (specs.localized) return on_num(); - auto num_digits = count_digits(abs_value); - out = write_int( - out, num_digits, get_prefix(), specs, [this, num_digits](iterator it) { - return format_decimal(it, abs_value, num_digits).end; - }); + write_dec(); } FMT_CONSTEXPR void on_hex() { @@ -1746,9 +1748,9 @@ template struct int_writer { void on_num() { std::string groups = grouping(locale); - if (groups.empty()) return on_dec(); + if (groups.empty()) return write_dec(); auto sep = thousands_sep(locale); - if (!sep) return on_dec(); + if (!sep) return write_dec(); int num_digits = count_digits(abs_value); int size = num_digits, n = num_digits; std::string::const_iterator group = groups.cbegin(); @@ -3179,7 +3181,8 @@ struct format_handler : detail::error_handler { return parse_context.begin(); } auto specs = basic_format_specs(); - if (begin + 1 < end && begin[1] == '}' && is_ascii_letter(*begin)) { + if (begin + 1 < end && begin[1] == '}' && is_ascii_letter(*begin) && + *begin != 'L') { specs.type = static_cast(*begin++); } else { using parse_context_t = basic_format_parse_context; diff --git a/test/format-test.cc b/test/format-test.cc index 6c5b1fd0..804ce1b6 100644 --- a/test/format-test.cc +++ b/test/format-test.cc @@ -1408,7 +1408,7 @@ TEST(FormatterTest, FormatLongDouble) { } TEST(FormatterTest, FormatChar) { - const char types[] = "cbBdoxXL"; + const char types[] = "cbBdoxX"; check_unknown_types('a', types, "char"); EXPECT_EQ("a", format("{0}", 'a')); EXPECT_EQ("z", format("{0:c}", 'z')); @@ -1416,7 +1416,8 @@ TEST(FormatterTest, FormatChar) { int n = 'x'; for (const char* type = types + 1; *type; ++type) { std::string format_str = fmt::format("{{:{}}}", *type); - EXPECT_EQ(fmt::format(format_str, n), fmt::format(format_str, 'x')); + EXPECT_EQ(fmt::format(format_str, n), fmt::format(format_str, 'x')) + << format_str; } EXPECT_EQ(fmt::format("{:02X}", n), fmt::format("{:02X}", 'x')); }