Fix handling of the + flag with locales (#2133)

This commit is contained in:
Victor Zverovich 2021-02-13 07:08:01 -08:00
parent c5979d564e
commit ee0fed639c
2 changed files with 8 additions and 3 deletions

View File

@ -1810,7 +1810,7 @@ template <typename OutputIt, typename Char, typename UInt> struct int_writer {
p -= s.size();
}
*p-- = static_cast<Char>(*digits);
if (prefix_size != 0) *p = static_cast<Char>('-');
if (prefix_size != 0) *p = static_cast<Char>(prefix[0]);
auto data = buffer.data();
out = write_padded<align::right>(
out, specs, usize, usize,

View File

@ -73,8 +73,13 @@ TEST(LocaleTest, Format) {
}
TEST(LocaleTest, FormatDetaultAlign) {
std::locale special_grouping_loc(std::locale(), new special_grouping<char>());
EXPECT_EQ(" 12,345", fmt::format(special_grouping_loc, "{:8L}", 12345));
auto loc = std::locale({}, new special_grouping<char>());
EXPECT_EQ(" 12,345", fmt::format(loc, "{:8L}", 12345));
}
TEST(LocaleTest, FormatPlus) {
auto loc = std::locale({}, new special_grouping<char>());
EXPECT_EQ("+100", fmt::format(loc, "{:+L}", 100));
}
TEST(LocaleTest, WFormat) {