From 0e6df7e5119fe463b2bb692f13b7aff2f67c5660 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Mon, 11 Jul 2016 06:23:17 -0700 Subject: [PATCH] Fix handling of thousands separator (#353) --- fmt/format.h | 3 ++- test/format-test.cc | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/fmt/format.h b/fmt/format.h index 2c0b36ee..a27567a4 100644 --- a/fmt/format.h +++ b/fmt/format.h @@ -933,6 +933,7 @@ inline void format_decimal(Char *buffer, UInt value, unsigned num_digits, } unsigned index = static_cast(value * 2); *--buffer = Data::DIGITS[index + 1]; + thousands_sep(buffer); *--buffer = Data::DIGITS[index]; } @@ -2780,7 +2781,7 @@ void BasicWriter::write_int(T value, Spec spec) { unsigned num_digits = internal::count_digits(abs_value); fmt::StringRef sep = internal::thousands_sep(std::localeconv()); unsigned size = static_cast( - num_digits + sep.size() * (num_digits - 1) / 3); + num_digits + sep.size() * ((num_digits - 1) / 3)); CharPtr p = prepare_int_buffer(size, spec, prefix, prefix_size) + 1; internal::format_decimal(get(p), abs_value, 0, internal::ThousandsSep(sep)); break; diff --git a/test/format-test.cc b/test/format-test.cc index 4a0e85ce..89994c76 100644 --- a/test/format-test.cc +++ b/test/format-test.cc @@ -1229,7 +1229,9 @@ TEST(FormatterTest, FormatIntLocale) { lconv lc = {}; char sep[] = "--"; lc.thousands_sep = sep; - EXPECT_CALL(mock, localeconv()).WillOnce(testing::Return(&lc)); + EXPECT_CALL(mock, localeconv()).Times(3).WillRepeatedly(testing::Return(&lc)); + EXPECT_EQ("123", format("{:n}", 123)); + EXPECT_EQ("1--234", format("{:n}", 1234)); EXPECT_EQ("1--234--567", format("{:n}", 1234567)); }