diff --git a/include/fmt/format-inl.h b/include/fmt/format-inl.h index c90d9773..16fc5f5d 100644 --- a/include/fmt/format-inl.h +++ b/include/fmt/format-inl.h @@ -106,7 +106,9 @@ template Locale locale_ref::get() const { template FMT_FUNC auto thousands_sep_impl(locale_ref loc) -> thousands_sep_result { auto& facet = std::use_facet>(loc.get()); - 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 FMT_FUNC Char decimal_point_impl(locale_ref loc) { return std::use_facet>(loc.get()) diff --git a/include/fmt/format.h b/include/fmt/format.h index 2468f2f1..64adc27b 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -1418,11 +1418,10 @@ auto write_int_localized(OutputIt& out, UInt value, unsigned prefix, static_assert(std::is_same, UInt>::value, ""); const auto sep_size = 1; auto ts = thousands_sep(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()) { @@ -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 s(&sep, sep_size); + basic_string_view 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();