From 8c88abde6474ecfdae283fca09ed70c75d0af846 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Sat, 13 Jun 2020 06:57:19 -0700 Subject: [PATCH] Fix sign handling in 'L' --- include/fmt/format.h | 2 ++ test/locale-test.cc | 1 + 2 files changed, 3 insertions(+) diff --git a/include/fmt/format.h b/include/fmt/format.h index 83599907..d2b759c6 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -1552,6 +1552,7 @@ template struct int_writer { char digits[40]; format_decimal(digits, abs_value, num_digits); basic_memory_buffer buffer; + size += prefix_size; buffer.resize(size); basic_string_view s(&sep, sep_size); // Index of a decimal digit with the least significant digit having index 0. @@ -1571,6 +1572,7 @@ template struct int_writer { std::uninitialized_copy(s.data(), s.data() + s.size(), make_checked(p, s.size())); } + if (prefix_size != 0) p[-1] = static_cast('-'); write(out, basic_string_view(buffer.data(), buffer.size()), specs); } diff --git a/test/locale-test.cc b/test/locale-test.cc index a2209a75..f29e897d 100644 --- a/test/locale-test.cc +++ b/test/locale-test.cc @@ -49,6 +49,7 @@ TEST(LocaleTest, Format) { std::locale loc(std::locale(), new numpunct()); EXPECT_EQ("1234567", fmt::format(std::locale(), "{:n}", 1234567)); EXPECT_EQ("1~234~567", fmt::format(loc, "{:n}", 1234567)); + EXPECT_EQ("-1~234~567", fmt::format(loc, "{:n}", -1234567)); fmt::format_arg_store as{1234567}; EXPECT_EQ("1~234~567", fmt::vformat(loc, "{:n}", fmt::format_args(as))); std::string s;