fix build

This commit is contained in:
Jin S 2023-12-11 15:47:07 -05:00
parent 6430e11a57
commit 46c90cac1c
2 changed files with 12 additions and 7 deletions

View File

@ -2130,7 +2130,7 @@ auto write_int(OutputIt out, UInt value, unsigned prefix,
switch (specs.type) { switch (specs.type) {
case presentation_type::none: case presentation_type::none:
case presentation_type::dec: { case presentation_type::dec: {
num_digits = count_digits(value); num_digits = std::min(count_digits(value), 40);
format_decimal(digits, value, num_digits); format_decimal(digits, value, num_digits);
break; break;
} }
@ -2139,7 +2139,7 @@ auto write_int(OutputIt out, UInt value, unsigned prefix,
bool upper = specs.type == presentation_type::hex_upper; bool upper = specs.type == presentation_type::hex_upper;
if (specs.alt) if (specs.alt)
prefix_append(prefix, unsigned(upper ? 'X' : 'x') << 8 | '0'); prefix_append(prefix, unsigned(upper ? 'X' : 'x') << 8 | '0');
num_digits = count_digits<4>(value); num_digits = std::min(count_digits<4>(value), 40);
format_uint<4>(digits, value, num_digits, upper); format_uint<4>(digits, value, num_digits, upper);
break; break;
} }
@ -2148,12 +2148,12 @@ auto write_int(OutputIt out, UInt value, unsigned prefix,
bool upper = specs.type == presentation_type::bin_upper; bool upper = specs.type == presentation_type::bin_upper;
if (specs.alt) if (specs.alt)
prefix_append(prefix, unsigned(upper ? 'B' : 'b') << 8 | '0'); prefix_append(prefix, unsigned(upper ? 'B' : 'b') << 8 | '0');
num_digits = count_digits<1>(value); num_digits = std::min(count_digits<1>(value), 40);
format_uint<1>(digits, value, num_digits); format_uint<1>(digits, value, num_digits);
break; break;
} }
case presentation_type::oct: { case presentation_type::oct: {
num_digits = count_digits<3>(value); num_digits = std::min(count_digits<3>(value), 40);
// Octal prefix '0' is counted as a digit, so only add it if precision // Octal prefix '0' is counted as a digit, so only add it if precision
// is not greater than the number of digits. // is not greater than the number of digits.
if (specs.alt && specs.precision <= num_digits && value != 0) if (specs.alt && specs.precision <= num_digits && value != 0)

View File

@ -1335,9 +1335,6 @@ TEST(format_test, format_oct) {
TEST(format_test, format_int_locale) { TEST(format_test, format_int_locale) {
EXPECT_EQ("1234", fmt::format("{:L}", 1234)); EXPECT_EQ("1234", fmt::format("{:L}", 1234));
EXPECT_EQ("7,5bc,d15", fmt::format(std::locale("en_US.UTF-8"), "{:Lx}", 123456789));
EXPECT_EQ("-0b111,010,110,111,100,110,100,010,101", fmt::format(std::locale("en_US.UTF-8"), "{:#Lb}", -123456789));
EXPECT_EQ(" 30,071", fmt::format(std::locale("en_US.UTF-8"), "{:10Lo}", 12345));
} }
TEST(format_test, format_float) { TEST(format_test, format_float) {
@ -2300,6 +2297,14 @@ TEST(format_test, format_named_arg_with_locale) {
"42"); "42");
} }
TEST(format_test, format_locale) {
auto loc =
std::locale({}, new fmt::format_facet<std::locale>(","));
EXPECT_EQ("7,5bc,d15", fmt::format(loc, "{:Lx}", 123456789));
EXPECT_EQ("-0b111,010,110,111,100,110,100,010,101", fmt::format(loc, "{:#Lb}", -123456789));
EXPECT_EQ(" 30,071", fmt::format(loc, "{:10Lo}", 12345));
}
#endif // FMT_STATIC_THOUSANDS_SEPARATOR #endif // FMT_STATIC_THOUSANDS_SEPARATOR
struct convertible_to_nonconst_cstring { struct convertible_to_nonconst_cstring {