Get rid of FMT_VARIADIC

This commit is contained in:
Victor Zverovich
2016-08-26 17:23:13 -07:00
parent ece7ae5f49
commit 0028ce57b6
9 changed files with 127 additions and 104 deletions
+14 -4
View File
@@ -45,22 +45,32 @@ class CustomPrintfArgFormatter :
}
};
std::string custom_format(const char *format_str, fmt::format_args args) {
std::string vcustom_format(const char *format_str, fmt::format_args args) {
fmt::MemoryWriter writer;
// Pass custom argument formatter as a template arg to BasicFormatter.
fmt::BasicFormatter<char, CustomArgFormatter> formatter(args, writer);
formatter.format(format_str);
return writer.str();
}
FMT_VARIADIC(std::string, custom_format, const char *)
std::string custom_sprintf(const char* format_str, fmt::format_args args){
template <typename... Args>
std::string custom_format(const char *format_str, const Args & ... args) {
auto va = fmt::internal::make_format_args<fmt::BasicFormatter<char>>(args...);
return vcustom_format(format_str, va);
}
std::string vcustom_sprintf(const char* format_str, fmt::format_args args) {
fmt::MemoryWriter writer;
fmt::PrintfFormatter<char, CustomPrintfArgFormatter> formatter(args, writer);
formatter.format(format_str);
return writer.str();
}
FMT_VARIADIC(std::string, custom_sprintf, const char*);
template <typename... Args>
std::string custom_sprintf(const char *format_str, const Args & ... args) {
auto va = fmt::internal::make_format_args<fmt::BasicFormatter<char>>(args...);
return vcustom_sprintf(format_str, va);
}
TEST(CustomFormatterTest, Format) {
EXPECT_EQ("0.00", custom_format("{:.2f}", -.00001));