Skip to content

Commit

Permalink
Fix handling of default alignmment with locale (#1801)
Browse files Browse the repository at this point in the history
  • Loading branch information
vitaut committed Aug 6, 2020
1 parent 37c8f4e commit 0907c08
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
7 changes: 5 additions & 2 deletions include/fmt/format.h
Original file line number Diff line number Diff line change
Expand Up @@ -1598,8 +1598,11 @@ template <typename OutputIt, typename Char, typename UInt> struct int_writer {
make_checked(p, s.size()));
}
if (prefix_size != 0) p[-1] = static_cast<Char>('-');
out = write(out, basic_string_view<Char>(buffer.data(), buffer.size()),
specs);
using iterator = remove_reference_t<decltype(reserve(out, 0))>;
auto data = buffer.data();
out = write_padded<align::right>(out, specs, size, size, [=](iterator it) {
return copy_str<Char>(data, data + size, it);
});
}

void on_chr() { *out++ = static_cast<Char>(abs_value); }
Expand Down
5 changes: 5 additions & 0 deletions test/locale-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ TEST(LocaleTest, Format) {
fmt::format(small_grouping_loc, "{:L}", max_value<uint32_t>()));
}

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));
}

TEST(LocaleTest, WFormat) {
std::locale loc(std::locale(), new numpunct<wchar_t>());
EXPECT_EQ(L"1234567", fmt::format(std::locale(), L"{:L}", 1234567));
Expand Down

0 comments on commit 0907c08

Please sign in to comment.