ArgFormatter -> arg_formatter
This commit is contained in:
@@ -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);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user