This commit is contained in:
Victor Zverovich
2018-03-04 09:16:51 -08:00
parent b7632e9641
commit 86a9bc8291
20 changed files with 126 additions and 473 deletions
+10 -16
View File
@@ -1,28 +1,22 @@
/*
Custom argument formatter tests
// Formatting library for C++ - custom argument formatter tests
//
// Copyright (c) 2012 - present, Victor Zverovich
// All rights reserved.
//
// For the license information refer to format.h.
Copyright (c) 2016, Victor Zverovich
All rights reserved.
For the license information refer to format.h.
*/
#include "fmt/printf.h"
#include "fmt/format.h"
#include "gtest-extra.h"
using fmt::printf_arg_formatter;
// A custom argument formatter that doesn't print `-` for floating-point values
// rounded to 0.
class CustomArgFormatter :
class custom_arg_formatter :
public fmt::arg_formatter<fmt::back_insert_range<fmt::internal::buffer>> {
public:
typedef fmt::back_insert_range<fmt::internal::buffer> range;
typedef decltype(fmt::internal::declval<range>().begin()) iterator;
typedef fmt::arg_formatter<range> base;
CustomArgFormatter(fmt::basic_context<iterator, char> &ctx,
fmt::format_specs &s)
custom_arg_formatter(fmt::context &ctx, fmt::format_specs &s)
: base(ctx, s) {}
using base::operator();
@@ -37,7 +31,7 @@ class CustomArgFormatter :
std::string custom_vformat(fmt::string_view format_str, fmt::format_args args) {
fmt::memory_buffer buffer;
// Pass custom argument formatter as a template arg to vwrite.
fmt::vformat_to<CustomArgFormatter>(buffer, format_str, args);
fmt::vformat_to<custom_arg_formatter>(buffer, format_str, args);
return std::string(buffer.data(), buffer.size());
}