diff --git a/fmt/format.cc b/fmt/format.cc index 81d09cfe..9f9d6ae1 100644 --- a/fmt/format.cc +++ b/fmt/format.cc @@ -521,8 +521,7 @@ template void internal::FixedBuffer::grow(std::size_t); template void internal::ArgMap::init(const ArgList &args); -template void PrintfFormatter::format( - BasicWriter &writer, CStringRef format); +template void PrintfFormatter::format(CStringRef format); template int internal::CharTraits::format_float( char *buffer, std::size_t size, const char *format, @@ -538,8 +537,7 @@ template void internal::FixedBuffer::grow(std::size_t); template void internal::ArgMap::init(const ArgList &args); -template void PrintfFormatter::format( - BasicWriter &writer, WCStringRef format); +template void PrintfFormatter::format(WCStringRef format); template int internal::CharTraits::format_float( wchar_t *buffer, std::size_t size, const wchar_t *format, diff --git a/fmt/printf.h b/fmt/printf.h index e50f1e4d..3c3e32fe 100644 --- a/fmt/printf.h +++ b/fmt/printf.h @@ -255,6 +255,8 @@ template > class PrintfFormatter : private internal::FormatterBase { private: + BasicWriter &writer_; + void parse_flags(FormatSpec &spec, const Char *&s); // Returns the argument with specified index or, if arg_index is equal @@ -269,15 +271,15 @@ class PrintfFormatter : private internal::FormatterBase { public: /** \rst - Constructs a ``PrintfFormatter`` object. References to the arguments - are stored in the formatter object so make sure they have appropriate - lifetimes. + Constructs a ``PrintfFormatter`` object. References to the arguments and + the writer are stored in the formatter object so make sure they have + appropriate lifetimes. \endrst */ - explicit PrintfFormatter(const ArgList &args) : FormatterBase(args) {} + explicit PrintfFormatter(const ArgList &args, BasicWriter &w) + : FormatterBase(args), writer_(w) {} - FMT_API void format(BasicWriter &writer, - BasicCStringRef format_str); + FMT_API void format(BasicCStringRef format_str); }; template @@ -353,19 +355,18 @@ unsigned PrintfFormatter::parse_header( } template -void PrintfFormatter::format( - BasicWriter &writer, BasicCStringRef format_str) { +void PrintfFormatter::format(BasicCStringRef format_str) { const Char *start = format_str.c_str(); const Char *s = start; while (*s) { Char c = *s++; if (c != '%') continue; if (*s == c) { - write(writer, start, s); + write(writer_, start, s); start = ++s; continue; } - write(writer, start, s - 1); + write(writer_, start, s - 1); FormatSpec spec; spec.align_ = ALIGN_RIGHT; @@ -448,14 +449,14 @@ void PrintfFormatter::format( start = s; // Format argument. - AF(writer, spec).visit(arg); + AF(writer_, spec).visit(arg); } - write(writer, start, s); + write(writer_, start, s); } template void printf(BasicWriter &w, BasicCStringRef format, ArgList args) { - PrintfFormatter(args).format(w, format); + PrintfFormatter(args, w).format(format); } /** diff --git a/test/custom-formatter-test.cc b/test/custom-formatter-test.cc index 443721eb..ef25895d 100644 --- a/test/custom-formatter-test.cc +++ b/test/custom-formatter-test.cc @@ -51,10 +51,10 @@ std::string custom_format(const char *format_str, fmt::ArgList args) { } FMT_VARIADIC(std::string, custom_format, const char *) -std::string custom_sprintf(const char* fstr, fmt::ArgList args){ +std::string custom_sprintf(const char* format_str, fmt::ArgList args){ fmt::MemoryWriter writer; - fmt::PrintfFormatter pfer( args); - pfer.format(writer, fstr); + fmt::PrintfFormatter formatter(args, writer); + formatter.format(format_str); return writer.str(); } FMT_VARIADIC(std::string, custom_sprintf, const char*);