Skip to content

Commit

Permalink
Fix sign handling with large code units
Browse files Browse the repository at this point in the history
  • Loading branch information
vitaut committed Aug 20, 2022
1 parent 779449f commit 1f95c34
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
8 changes: 6 additions & 2 deletions include/fmt/format.h
Original file line number Diff line number Diff line change
Expand Up @@ -1998,7 +1998,10 @@ auto write_int_localized(OutputIt out, UInt value, unsigned prefix,
grouping.count_separators(num_digits));
return write_padded<align::right>(
out, specs, size, size, [&](reserve_iterator<OutputIt> it) {
if (prefix != 0) *it++ = static_cast<Char>(prefix);
if (prefix != 0) {
char sign = static_cast<char>(prefix);
*it++ = static_cast<Char>(sign);
}
return grouping.apply(it, string_view(digits, to_unsigned(num_digits)));
});
}
Expand Down Expand Up @@ -2157,7 +2160,8 @@ class counting_iterator {
return it;
}

FMT_CONSTEXPR friend counting_iterator operator+(counting_iterator it, difference_type n) {
FMT_CONSTEXPR friend counting_iterator operator+(counting_iterator it,
difference_type n) {
it.count_ += static_cast<size_t>(n);
return it;
}
Expand Down
4 changes: 4 additions & 0 deletions test/xchar-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -513,4 +513,8 @@ TEST(locale_test, chrono_weekday) {
std::locale::global(loc_old);
}

TEST(locale_test, sign) {
EXPECT_EQ(fmt::format(std::locale(), L"{:L}", -50), L"-50");
}

#endif // FMT_STATIC_THOUSANDS_SEPARATOR

0 comments on commit 1f95c34

Please sign in to comment.