From ee0fed639c78a36686b6cf50ac66fc7a87df9f28 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Sat, 13 Feb 2021 07:08:01 -0800 Subject: [PATCH] Fix handling of the + flag with locales (#2133) --- include/fmt/format.h | 2 +- test/locale-test.cc | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/include/fmt/format.h b/include/fmt/format.h index de0a379e..827b3776 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -1810,7 +1810,7 @@ template struct int_writer { p -= s.size(); } *p-- = static_cast(*digits); - if (prefix_size != 0) *p = static_cast('-'); + if (prefix_size != 0) *p = static_cast(prefix[0]); auto data = buffer.data(); out = write_padded( out, specs, usize, usize, diff --git a/test/locale-test.cc b/test/locale-test.cc index aa8b6009..db55923d 100644 --- a/test/locale-test.cc +++ b/test/locale-test.cc @@ -73,8 +73,13 @@ TEST(LocaleTest, Format) { } TEST(LocaleTest, FormatDetaultAlign) { - std::locale special_grouping_loc(std::locale(), new special_grouping()); - EXPECT_EQ(" 12,345", fmt::format(special_grouping_loc, "{:8L}", 12345)); + auto loc = std::locale({}, new special_grouping()); + EXPECT_EQ(" 12,345", fmt::format(loc, "{:8L}", 12345)); +} + +TEST(LocaleTest, FormatPlus) { + auto loc = std::locale({}, new special_grouping()); + EXPECT_EQ("+100", fmt::format(loc, "{:+L}", 100)); } TEST(LocaleTest, WFormat) {