diff --git a/fmt/format.h b/fmt/format.h index 6ef31e9c..e11a05cf 100644 --- a/fmt/format.h +++ b/fmt/format.h @@ -356,30 +356,22 @@ namespace fmt { using std::move; #endif -template -class basic_buffer; - -typedef basic_buffer buffer; -typedef basic_buffer wbuffer; - template class basic_writer; template class basic_arg; -template -class arg_formatter; - -template -class printf_arg_formatter; - template class basic_context; typedef basic_context context; typedef basic_context wcontext; +// A formatter for objects of type T. +template +struct formatter; + /** \rst An implementation of ``std::basic_string_view`` for pre-C++17. It provides a @@ -482,10 +474,6 @@ class format_error : public std::runtime_error { ~format_error() throw(); }; -// A formatter for objects of type T. -template -struct formatter; - namespace internal { // Casts nonnegative integer to unsigned. @@ -589,6 +577,9 @@ class basic_buffer { virtual std::locale locale() const { return std::locale(); } }; +typedef basic_buffer buffer; +typedef basic_buffer wbuffer; + template template void basic_buffer::append(const U *begin, const U *end) { @@ -2304,9 +2295,6 @@ class basic_writer { template friend class internal::arg_formatter_base; - template - friend class printf_arg_formatter; - public: /** Constructs a ``basic_writer`` object. diff --git a/fmt/printf.h b/fmt/printf.h index 4a86c381..69f7a687 100644 --- a/fmt/printf.h +++ b/fmt/printf.h @@ -241,25 +241,13 @@ class printf_arg_formatter : public internal::arg_formatter_base { /** Formats a character. */ void operator()(Char value) { - const format_specs &fmt_spec = this->spec(); + format_specs &fmt_spec = this->spec(); basic_writer &w = this->writer(); if (fmt_spec.type_ && fmt_spec.type_ != 'c') - w.write_int(value, fmt_spec); - typedef typename basic_writer::pointer_type pointer_type; - pointer_type out = pointer_type(); - if (fmt_spec.width_ > 1) { - Char fill = ' '; - out = w.grow_buffer(fmt_spec.width_); - if (fmt_spec.align_ != ALIGN_LEFT) { - std::fill_n(out, fmt_spec.width_ - 1, fill); - out += fmt_spec.width_ - 1; - } else { - std::fill_n(out + 1, fmt_spec.width_ - 1, fill); - } - } else { - out = w.grow_buffer(1); - } - *out = static_cast(value); + return (*this)(static_cast(value)); + fmt_spec.flags_ = 0; + fmt_spec.align_ = ALIGN_RIGHT; + Base::operator()(value); } /** Formats a null-terminated C string. */ diff --git a/test/printf-test.cc b/test/printf-test.cc index c2d9e3d1..7ab5390e 100644 --- a/test/printf-test.cc +++ b/test/printf-test.cc @@ -137,7 +137,7 @@ TEST(PrintfTest, ZeroFlag) { EXPECT_PRINTF("+00042", "%00+6d", 42); // '0' flag is ignored for non-numeric types. - EXPECT_PRINTF(" x", "%05c", 'x'); + EXPECT_PRINTF("0000x", "%05c", 'x'); } TEST(PrintfTest, PlusFlag) {