From b17d5c4f5d5c7dd9a0f5518f3a45e398098b2026 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Sat, 18 Jul 2020 08:31:38 -0700 Subject: [PATCH] Fix a regression in handling digit separators (#1782) --- include/fmt/format.h | 2 +- test/locale-test.cc | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/include/fmt/format.h b/include/fmt/format.h index decbe756..fc46c9f0 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -1546,7 +1546,7 @@ template struct int_writer { int num_digits = count_digits(abs_value); int size = num_digits, n = num_digits; std::string::const_iterator group = groups.cbegin(); - while (group != groups.cend() && num_digits > *group && *group > 0 && + while (group != groups.cend() && n > *group && *group > 0 && *group != max_value()) { size += sep_size; n -= *group; diff --git a/test/locale-test.cc b/test/locale-test.cc index fcce0091..15a40d99 100644 --- a/test/locale-test.cc +++ b/test/locale-test.cc @@ -61,6 +61,7 @@ TEST(LocaleTest, Format) { std::locale special_grouping_loc(std::locale(), new special_grouping()); EXPECT_EQ("1,23,45,678", fmt::format(special_grouping_loc, "{:L}", 12345678)); + EXPECT_EQ("12,345", fmt::format(special_grouping_loc, "{:L}", 12345)); std::locale small_grouping_loc(std::locale(), new small_grouping()); EXPECT_EQ("4,2,9,4,9,6,7,2,9,5",