ArgFormatter -> arg_formatter

This commit is contained in:
Victor Zverovich
2017-02-18 07:46:32 -08:00
parent 50e716737d
commit 4ec8860783
5 changed files with 23 additions and 23 deletions

View File

@@ -10,38 +10,38 @@
#include "fmt/printf.h"
#include "gtest-extra.h"
using fmt::PrintfArgFormatter;
using fmt::printf_arg_formatter;
// A custom argument formatter that doesn't print `-` for floating-point values
// rounded to 0.
class CustomArgFormatter : public fmt::ArgFormatter<char> {
class CustomArgFormatter : public fmt::arg_formatter<char> {
public:
CustomArgFormatter(fmt::buffer &buf, fmt::basic_context<char> &ctx,
fmt::format_specs &s)
: fmt::ArgFormatter<char>(buf, ctx, s) {}
: fmt::arg_formatter<char>(buf, ctx, s) {}
using fmt::ArgFormatter<char>::operator();
using fmt::arg_formatter<char>::operator();
void operator()(double value) {
if (round(value * pow(10, spec().precision())) == 0)
value = 0;
fmt::ArgFormatter<char>::operator()(value);
fmt::arg_formatter<char>::operator()(value);
}
};
// A custom argument formatter that doesn't print `-` for floating-point values
// rounded to 0.
class CustomPrintfArgFormatter : public PrintfArgFormatter<char> {
class CustomPrintfArgFormatter : public printf_arg_formatter<char> {
public:
CustomPrintfArgFormatter(fmt::buffer &buf, fmt::format_specs &spec)
: PrintfArgFormatter<char>(buf, spec) {}
: printf_arg_formatter<char>(buf, spec) {}
using PrintfArgFormatter<char>::operator();
using printf_arg_formatter<char>::operator();
void operator()(double value) {
if (round(value * pow(10, spec().precision())) == 0)
value = 0;
PrintfArgFormatter<char>::operator()(value);
printf_arg_formatter<char>::operator()(value);
}
};

View File

@@ -58,9 +58,9 @@ TEST(OStreamTest, Enum) {
EXPECT_EQ("0", fmt::format("{}", A));
}
struct TestArgFormatter : fmt::ArgFormatter<char> {
struct TestArgFormatter : fmt::arg_formatter<char> {
TestArgFormatter(fmt::buffer &buf, fmt::context &ctx, fmt::format_specs &s)
: fmt::ArgFormatter<char>(buf, ctx, s) {}
: fmt::arg_formatter<char>(buf, ctx, s) {}
};
TEST(OStreamTest, CustomArg) {