mirror of
https://github.com/fmtlib/fmt.git
synced 2025-01-10 14:30:09 +00:00
Improve handling of thousands separator
This commit is contained in:
parent
024741b476
commit
2ac0bfe59e
@ -106,7 +106,9 @@ template <typename Locale> Locale locale_ref::get() const {
|
||||
template <typename Char>
|
||||
FMT_FUNC auto thousands_sep_impl(locale_ref loc) -> thousands_sep_result<Char> {
|
||||
auto& facet = std::use_facet<std::numpunct<Char>>(loc.get<std::locale>());
|
||||
return {facet.grouping(), facet.thousands_sep()};
|
||||
auto grouping = facet.grouping();
|
||||
auto thousands_sep = grouping.empty() ? Char() : facet.thousands_sep();
|
||||
return {std::move(grouping), thousands_sep};
|
||||
}
|
||||
template <typename Char> FMT_FUNC Char decimal_point_impl(locale_ref loc) {
|
||||
return std::use_facet<std::numpunct<Char>>(loc.get<std::locale>())
|
||||
|
@ -1418,11 +1418,10 @@ auto write_int_localized(OutputIt& out, UInt value, unsigned prefix,
|
||||
static_assert(std::is_same<uint64_or_128_t<UInt>, UInt>::value, "");
|
||||
const auto sep_size = 1;
|
||||
auto ts = thousands_sep<Char>(loc);
|
||||
const std::string& groups = ts.grouping;
|
||||
Char sep = ts.thousands_sep;
|
||||
if (!sep || groups.empty()) return false;
|
||||
if (!ts.thousands_sep) return false;
|
||||
int num_digits = count_digits(value);
|
||||
int size = num_digits, n = num_digits;
|
||||
const std::string& groups = ts.grouping;
|
||||
std::string::const_iterator group = groups.cbegin();
|
||||
while (group != groups.cend() && n > *group && *group > 0 &&
|
||||
*group != max_value<char>()) {
|
||||
@ -1437,7 +1436,7 @@ auto write_int_localized(OutputIt& out, UInt value, unsigned prefix,
|
||||
if (prefix != 0) ++size;
|
||||
const auto usize = to_unsigned(size);
|
||||
buffer.resize(usize);
|
||||
basic_string_view<Char> s(&sep, sep_size);
|
||||
basic_string_view<Char> s(&ts.thousands_sep, sep_size);
|
||||
// Index of a decimal digit with the least significant digit having index 0.
|
||||
int digit_index = 0;
|
||||
group = groups.cbegin();
|
||||
|
Loading…
Reference in New Issue
Block a user