From a8d0ed08280dcd64f58a213b175d5dd88d52c7a7 Mon Sep 17 00:00:00 2001 From: Glen Stark Date: Thu, 2 Jun 2016 15:35:27 +0200 Subject: [PATCH] Took PrintfArgFormatter out of internal --- fmt/format.cc | 4 ++-- fmt/format.h | 13 ++++++------ fmt/printf.h | 37 ++++++++++++++++++----------------- test/custom-formatter-test.cc | 2 +- 4 files changed, 29 insertions(+), 27 deletions(-) diff --git a/fmt/format.cc b/fmt/format.cc index 8d00357d55c0..7632e084c470 100644 --- a/fmt/format.cc +++ b/fmt/format.cc @@ -501,7 +501,7 @@ template void fmt::internal::FixedBuffer::grow(std::size_t); template void fmt::internal::ArgMap::init(const fmt::ArgList &args); -template void fmt::internal::PrintfFormatter::format( +template void fmt::PrintfFormatter::format( BasicWriter &writer, CStringRef format); template int fmt::internal::CharTraits::format_float( @@ -518,7 +518,7 @@ template void fmt::internal::FixedBuffer::grow(std::size_t); template void fmt::internal::ArgMap::init(const fmt::ArgList &args); -template void fmt::internal::PrintfFormatter::format( +template void fmt::PrintfFormatter::format( BasicWriter &writer, WCStringRef format); template int fmt::internal::CharTraits::format_float( diff --git a/fmt/format.h b/fmt/format.h index e6a8f423393e..0260a5eee8f7 100644 --- a/fmt/format.h +++ b/fmt/format.h @@ -1319,8 +1319,6 @@ class RuntimeError : public std::runtime_error { RuntimeError() : std::runtime_error("") {} }; -template -class PrintfArgFormatter; template class ArgMap; @@ -1939,15 +1937,19 @@ class FormatterBase { } }; +template class PrintfArgFormatter; + +} // namespace internal + // A printf formatter. template > -class PrintfFormatter : private FormatterBase { + class PrintfFormatter : private internal::FormatterBase { private: void parse_flags(FormatSpec &spec, const Char *&s); // Returns the argument with specified index or, if arg_index is equal // to the maximum unsigned value, the next argument. - Arg get_arg(const Char *s, + internal::Arg get_arg(const Char *s, unsigned arg_index = (std::numeric_limits::max)()); // Parses argument index, flags and width and returns the argument index. @@ -1958,7 +1960,6 @@ class PrintfFormatter : private FormatterBase { FMT_API void format(BasicWriter &writer, BasicCStringRef format_str); }; -} // namespace internal /** \rst @@ -3190,7 +3191,7 @@ FMT_API void print(CStringRef format_str, ArgList args); template void printf(BasicWriter &w, BasicCStringRef format, ArgList args) { - internal::PrintfFormatter(args).format(w, format); + PrintfFormatter(args).format(w, format); } /** diff --git a/fmt/printf.h b/fmt/printf.h index 533edfcfe424..f212889ea4bc 100644 --- a/fmt/printf.h +++ b/fmt/printf.h @@ -252,8 +252,11 @@ class PrintfArgFormatter : } }; - template -void fmt::internal::PrintfFormatter::parse_flags( + +}// namespace internal + +template +void fmt::PrintfFormatter::parse_flags( FormatSpec &spec, const Char *&s) { for (;;) { switch (*s++) { @@ -280,11 +283,11 @@ void fmt::internal::PrintfFormatter::parse_flags( } template -Arg fmt::internal::PrintfFormatter::get_arg( +internal::Arg fmt::PrintfFormatter::get_arg( const Char *s, unsigned arg_index) { (void)s; const char *error = 0; - Arg arg = arg_index == UINT_MAX ? + internal::Arg arg = arg_index == UINT_MAX ? next_arg(error) : FormatterBase::get_arg(arg_index - 1, error); if (error) FMT_THROW(FormatError(!*s ? "invalid format string" : error)); @@ -292,14 +295,14 @@ Arg fmt::internal::PrintfFormatter::get_arg( } template -unsigned fmt::internal::PrintfFormatter::parse_header( +unsigned fmt::PrintfFormatter::parse_header( const Char *&s, FormatSpec &spec) { unsigned arg_index = UINT_MAX; Char c = *s; if (c >= '0' && c <= '9') { // Parse an argument index (if followed by '$') or a width possibly // preceded with '0' flag(s). - unsigned value = parse_nonnegative_int(s); + unsigned value = internal::parse_nonnegative_int(s); if (*s == '$') { // value is an argument index ++s; arg_index = value; @@ -317,16 +320,16 @@ unsigned fmt::internal::PrintfFormatter::parse_header( parse_flags(spec, s); // Parse width. if (*s >= '0' && *s <= '9') { - spec.width_ = parse_nonnegative_int(s); + spec.width_ = internal::parse_nonnegative_int(s); } else if (*s == '*') { ++s; - spec.width_ = WidthHandler(spec).visit(get_arg(s)); + spec.width_ = internal::WidthHandler(spec).visit(get_arg(s)); } return arg_index; } template - void fmt::internal::PrintfFormatter::format( + void fmt::PrintfFormatter::format( BasicWriter &writer, BasicCStringRef format_str) { const Char *start = format_str.c_str(); const Char *s = start; @@ -350,18 +353,18 @@ template if (*s == '.') { ++s; if ('0' <= *s && *s <= '9') { - spec.precision_ = static_cast(parse_nonnegative_int(s)); + spec.precision_ = static_cast(internal::parse_nonnegative_int(s)); } else if (*s == '*') { ++s; - spec.precision_ = PrecisionHandler().visit(get_arg(s)); + spec.precision_ = internal::PrecisionHandler().visit(get_arg(s)); } } - Arg arg = get_arg(s, arg_index); - if (spec.flag(HASH_FLAG) && IsZeroInt().visit(arg)) - spec.flags_ &= ~to_unsigned(HASH_FLAG); + internal::Arg arg = get_arg(s, arg_index); + if (spec.flag(HASH_FLAG) && internal::IsZeroInt().visit(arg)) + spec.flags_ &= ~internal::to_unsigned(HASH_FLAG); if (spec.fill_ == '0') { - if (arg.type <= Arg::LAST_NUMERIC_TYPE) + if (arg.type <= internal::Arg::LAST_NUMERIC_TYPE) spec.align_ = ALIGN_NUMERIC; else spec.fill_ = ' '; // Ignore '0' flag for non-numeric types. @@ -403,7 +406,7 @@ template if (!*s) FMT_THROW(FormatError("invalid format string")); spec.type_ = static_cast(*s++); - if (arg.type <= Arg::LAST_INTEGER_TYPE) { + if (arg.type <= internal::Arg::LAST_INTEGER_TYPE) { // Normalize type. switch (spec.type_) { case 'i': case 'u': @@ -424,8 +427,6 @@ template write(writer, start, s); } -}// namespace internal - } // namespace fmt #endif diff --git a/test/custom-formatter-test.cc b/test/custom-formatter-test.cc index 5af0c1e744a3..53daef1095fd 100644 --- a/test/custom-formatter-test.cc +++ b/test/custom-formatter-test.cc @@ -46,7 +46,7 @@ FMT_VARIADIC(std::string, custom_format, const char *) std::string printfer(const char* fstr, fmt::ArgList args){ fmt::MemoryWriter writer; - fmt::internal::PrintfFormatter pfer(args); + fmt::PrintfFormatter pfer(args); pfer.format(writer,fstr); return writer.str(); }