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
+21 -10
View File
@@ -2312,25 +2312,36 @@ TEST(format_int_test, format_int) {
EXPECT_EQ(os.str(), fmt::format_int(max_value<int64_t>()).str());
}
#ifdef FMT_STATIC_THOUSANDS_SEPARATOR
#ifndef FMT_STATIC_THOUSANDS_SEPARATOR
# include <locale>
class num_format : public fmt::num_format_facet<std::locale> {
class format_facet : public fmt::format_facet<std::locale> {
protected:
void do_put(fmt::appender out, fmt::loc_value, const fmt::format_specs&,
std::locale&) const override;
struct int_formatter {
fmt::appender out;
template <typename T, FMT_ENABLE_IF(fmt::detail::is_integer<T>::value)>
void operator()(T value) {
fmt::format_to(out, "[{}]", value);
}
template <typename T, FMT_ENABLE_IF(!fmt::detail::is_integer<T>::value)>
void operator()(T) {}
};
void do_put(fmt::appender out, fmt::basic_format_arg<fmt::format_context> arg,
const fmt::format_specs&, std::locale&) const override;
};
void num_format::do_put(fmt::appender out, fmt::loc_value value,
const fmt::format_specs&, std::locale&) const {
fmt::format_to(out, "[{}]", value.ulong_long_value);
void format_facet::do_put(fmt::appender out,
fmt::basic_format_arg<fmt::format_context> arg,
const fmt::format_specs&, std::locale&) const {
visit_format_arg(int_formatter{out}, arg);
}
TEST(format_test, num_format) {
auto loc = std::locale(std::locale(), new num_format());
TEST(format_test, format_facet) {
auto loc = std::locale(std::locale(), new format_facet());
EXPECT_EQ(fmt::format(loc, "{:L}", 42), "[42]");
EXPECT_EQ(fmt::format(loc, "{:L}", -42), "[-42]");
}
#endif // FMT_STATIC_THOUSANDS_SEPARATOR