From d29e505568a644841a6d59d4cb2fd777684c28d8 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Mon, 30 Jun 2014 07:12:09 -0700 Subject: [PATCH] Move PrintfParser from BasicWriter to the internal namespace. --- format.cc | 52 +++++++++++++++++++++++++--------------------------- format.h | 49 ++++++++++++++++++++++++++----------------------- 2 files changed, 51 insertions(+), 50 deletions(-) diff --git a/format.cc b/format.cc index 9c1f80af..e92bb32b 100644 --- a/format.cc +++ b/format.cc @@ -116,6 +116,24 @@ void ReportError(FormatFunc func, std::fputc('\n', stderr); } catch (...) {} } + +const fmt::internal::ArgInfo DUMMY_ARG = {fmt::internal::ArgInfo::INT, 0}; + +fmt::ULongLong GetIntValue(const fmt::internal::ArgInfo &arg) { + typedef fmt::internal::ArgInfo Arg; + switch (arg.type) { + case Arg::INT: + return arg.int_value; + case Arg::UINT: + return arg.uint_value; + case Arg::LONG_LONG: + return arg.long_long_value; + case Arg::ULONG_LONG: + return arg.ulong_long_value; + default: + return -1; + } +} } // namespace int fmt::internal::SignBitNoInline(double value) { return SignBit(value); } @@ -332,10 +350,6 @@ int fmt::internal::ParseNonnegativeInt( return value; } -template -const typename fmt::internal::ArgInfo - fmt::BasicWriter::DUMMY_ARG = {fmt::internal::ArgInfo::INT, 0}; - // Fills the padding around the content and returns the pointer to the // content area. template @@ -502,22 +516,6 @@ void fmt::BasicWriter::FormatDouble(T value, const FormatSpec &spec) { } } -template -fmt::ULongLong fmt::BasicWriter::GetIntValue(const Arg &arg) { - switch (arg.type) { - case Arg::INT: - return arg.int_value; - case Arg::UINT: - return arg.uint_value; - case Arg::LONG_LONG: - return arg.long_long_value; - case Arg::ULONG_LONG: - return arg.ulong_long_value; - default: - return -1; - } -} - template template void fmt::BasicWriter::FormatString( @@ -579,7 +577,7 @@ void fmt::BasicWriter::FormatParser::CheckSign( } template -void fmt::BasicWriter::PrintfParser::ParseFlags( +void fmt::internal::PrintfParser::ParseFlags( FormatSpec &spec, const Char *&s) { for (;;) { switch (*s++) { @@ -606,7 +604,7 @@ void fmt::BasicWriter::PrintfParser::ParseFlags( } template -unsigned fmt::BasicWriter::PrintfParser::ParseHeader( +unsigned fmt::internal::PrintfParser::ParseHeader( const Char *&s, FormatSpec &spec, const char *&error) { unsigned arg_index = UINT_MAX; Char c = *s; @@ -672,8 +670,8 @@ unsigned fmt::BasicWriter::PrintfParser::ParseHeader( // TODO: move to a base class that doesn't depend on template argument template -const typename fmt::BasicWriter::Arg - &fmt::BasicWriter::PrintfParser::HandleArgIndex( +const fmt::internal::ArgInfo + &fmt::internal::PrintfParser::HandleArgIndex( unsigned arg_index, const char *&error) { if (arg_index != UINT_MAX) { if (next_arg_index_ <= 0) { @@ -695,7 +693,7 @@ const typename fmt::BasicWriter::Arg } template -void fmt::BasicWriter::PrintfParser::Format( +void fmt::internal::PrintfParser::Format( BasicWriter &writer, BasicStringRef format, const ArgList &args) { const Char *start = format.c_str(); @@ -1132,7 +1130,7 @@ template fmt::BasicWriter::CharPtr template void fmt::BasicWriter::FormatParser::Format( BasicWriter &writer, BasicStringRef format, const ArgList &args); -template void fmt::BasicWriter::PrintfParser::Format( +template void fmt::internal::PrintfParser::Format( BasicWriter &writer, BasicStringRef format, const ArgList &args); // Explicit instantiations for wchar_t. @@ -1145,7 +1143,7 @@ template void fmt::BasicWriter::FormatParser::Format( BasicWriter &writer, BasicStringRef format, const ArgList &args); -template void fmt::BasicWriter::PrintfParser::Format( +template void fmt::internal::PrintfParser::Format( BasicWriter &writer, BasicStringRef format, const ArgList &args); diff --git a/format.h b/format.h index 13be305a..33ce9667 100644 --- a/format.h +++ b/format.h @@ -1008,6 +1008,30 @@ public: } }; +namespace internal { +// Printf format string parser. +template +class PrintfParser { + private: + ArgList args_; + int next_arg_index_; + + typedef ArgInfo Arg; + + void ParseFlags(FormatSpec &spec, const Char *&s); + + // Parses argument index, flags and width and returns the parsed + // argument index. + unsigned ParseHeader(const Char *&s, FormatSpec &spec, const char *&error); + + const ArgInfo &HandleArgIndex(unsigned arg_index, const char *&error); + + public: + void Format(BasicWriter &writer, + BasicStringRef format, const ArgList &args); +}; +} // namespace internal + // Generates a comma-separated list with results of applying f to numbers 0..n-1. # define FMT_GEN(n, f) FMT_GEN##n(f) # define FMT_GEN1(f) f(0) @@ -1125,8 +1149,6 @@ class BasicWriter { typedef internal::ArgInfo Arg; - static const Arg DUMMY_ARG; - #if _SECURE_SCL static Char *GetBase(CharPtr p) { return p.base(); } #else @@ -1180,8 +1202,6 @@ class BasicWriter { // Do not implement! void operator<<(typename internal::CharTraits::UnsupportedStrType); - static ULongLong GetIntValue(const Arg &arg); - // Format string parser. class FormatParser { private: @@ -1199,24 +1219,7 @@ class BasicWriter { BasicStringRef format, const ArgList &args); }; - // Printf format string parser. - class PrintfParser { - private: - ArgList args_; - int next_arg_index_; - - void ParseFlags(FormatSpec &spec, const Char *&s); - - // Parses argument index, flags and width and returns the parsed - // argument index. - unsigned ParseHeader(const Char *&s, FormatSpec &spec, const char *&error); - - const Arg &HandleArgIndex(unsigned arg_index, const char *&error); - - public: - void Format(BasicWriter &writer, - BasicStringRef format, const ArgList &args); - }; + friend class internal::PrintfParser; public: /** @@ -1302,7 +1305,7 @@ class BasicWriter { friend void printf(BasicWriter &w, BasicStringRef format, const ArgList &args) { - PrintfParser().Format(w, format, args); + internal::PrintfParser().Format(w, format, args); } BasicWriter &operator<<(int value) {