num_format_facet -> format_facet

This commit is contained in:
Victor Zverovich
2022-09-02 18:55:08 -07:00
parent f187274d36
commit fec5515c55
4 changed files with 40 additions and 38 deletions
+1 -1
View File
@@ -332,7 +332,7 @@ struct monostate {
#ifdef FMT_DOC
# define FMT_ENABLE_IF(...)
#else
# define FMT_ENABLE_IF(...) enable_if_t<(__VA_ARGS__), int> = 0
# define FMT_ENABLE_IF(...) fmt::enable_if_t<(__VA_ARGS__), int> = 0
#endif
FMT_BEGIN_DETAIL_NAMESPACE
+5 -5
View File
@@ -29,7 +29,7 @@
#include "format.h"
FMT_BEGIN_NAMESPACE
template <typename Locale> typename Locale::id num_format_facet<Locale>::id;
template <typename Locale> typename Locale::id format_facet<Locale>::id;
namespace detail {
@@ -118,15 +118,15 @@ template <typename Char> FMT_FUNC Char decimal_point_impl(locale_ref) {
}
#endif
FMT_FUNC auto write_int(appender out, loc_value value,
FMT_FUNC auto write_int(appender out, basic_format_arg<format_context> value,
const format_specs& specs, locale_ref loc) -> bool {
#ifndef FMT_STATIC_THOUSANDS_SEPARATOR
auto locale = loc.get<std::locale>();
// We cannot use the num_put<char> facet because it may produce output in
// a wrong encoding.
if (!std::has_facet<num_format_facet<std::locale>>(locale)) return {};
std::use_facet<num_format_facet<std::locale>>(locale).put(out, value, specs,
locale);
if (!std::has_facet<format_facet<std::locale>>(locale)) return {};
std::use_facet<format_facet<std::locale>>(locale).put(out, value, specs,
locale);
return true;
#endif
return false;
+13 -22
View File
@@ -985,27 +985,20 @@ constexpr auto compile_string_to_view(detail::std_string_view<Char> s)
}
} // namespace detail_exported
// A value to localize.
struct loc_value {
union {
unsigned long long ulong_long_value;
};
};
// A locale facet that formats numeric values in UTF-8.
// It is parameterized on the locale to avoid heavy <locale> include.
template <typename Locale> class num_format_facet : public Locale::facet {
// A locale facet that formats values in UTF-8.
// It is parameterized on the locale to avoid the heavy <locale> include.
template <typename Locale> class format_facet : public Locale::facet {
public:
static FMT_API typename Locale::id id;
void put(appender out, loc_value val, const format_specs& specs,
Locale& loc) const {
void put(appender out, basic_format_arg<format_context> val,
const format_specs& specs, Locale& loc) const {
do_put(out, val, specs, loc);
}
protected:
virtual void do_put(appender out, loc_value val, const format_specs& specs,
Locale& loc) const = 0;
virtual void do_put(appender out, basic_format_arg<format_context> val,
const format_specs& specs, Locale& loc) const = 0;
};
FMT_BEGIN_DETAIL_NAMESPACE
@@ -2037,23 +2030,21 @@ auto write_int(OutputIt out, UInt value, unsigned prefix,
});
}
FMT_API auto write_int(appender out, loc_value value, const format_specs& specs,
locale_ref loc) -> bool;
FMT_API auto write_int(appender out, basic_format_arg<format_context> value,
const format_specs& specs, locale_ref loc) -> bool;
template <typename OutputIt, typename Char>
inline auto write_int(OutputIt, loc_value, const basic_format_specs<Char>&,
locale_ref) -> bool {
inline auto write_int(OutputIt, basic_format_arg<buffer_context<Char>>,
const basic_format_specs<Char>&, locale_ref) -> bool {
return false;
}
template <typename OutputIt, typename UInt, typename Char>
auto write_int(OutputIt& out, UInt value, unsigned prefix,
const basic_format_specs<Char>& specs, locale_ref loc) -> bool {
auto result = false;
auto buf = memory_buffer();
if (sizeof(value) <= sizeof(unsigned long long))
result = write_int(appender(buf), {static_cast<unsigned long long>(value)},
auto written = write_int(appender(buf), make_arg<buffer_context<Char>>(value),
specs, loc);
if (!result) {
if (!written) {
auto grouping = digit_grouping<Char>(loc);
out = write_int(out, value, prefix, specs, grouping);
return true;