Move PrintfParser from BasicWriter to the internal namespace.

This commit is contained in:
Victor Zverovich 2014-06-30 07:12:09 -07:00
parent e63a0ff125
commit d29e505568
2 changed files with 51 additions and 50 deletions

View File

@ -116,6 +116,24 @@ void ReportError(FormatFunc func,
std::fputc('\n', stderr); std::fputc('\n', stderr);
} catch (...) {} } 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 } // namespace
int fmt::internal::SignBitNoInline(double value) { return SignBit(value); } int fmt::internal::SignBitNoInline(double value) { return SignBit(value); }
@ -332,10 +350,6 @@ int fmt::internal::ParseNonnegativeInt(
return value; return value;
} }
template <typename Char>
const typename fmt::internal::ArgInfo
fmt::BasicWriter<Char>::DUMMY_ARG = {fmt::internal::ArgInfo::INT, 0};
// Fills the padding around the content and returns the pointer to the // Fills the padding around the content and returns the pointer to the
// content area. // content area.
template <typename Char> template <typename Char>
@ -502,22 +516,6 @@ void fmt::BasicWriter<Char>::FormatDouble(T value, const FormatSpec &spec) {
} }
} }
template <typename Char>
fmt::ULongLong fmt::BasicWriter<Char>::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 <typename Char> template <typename Char>
template <typename StringChar> template <typename StringChar>
void fmt::BasicWriter<Char>::FormatString( void fmt::BasicWriter<Char>::FormatString(
@ -579,7 +577,7 @@ void fmt::BasicWriter<Char>::FormatParser::CheckSign(
} }
template <typename Char> template <typename Char>
void fmt::BasicWriter<Char>::PrintfParser::ParseFlags( void fmt::internal::PrintfParser<Char>::ParseFlags(
FormatSpec &spec, const Char *&s) { FormatSpec &spec, const Char *&s) {
for (;;) { for (;;) {
switch (*s++) { switch (*s++) {
@ -606,7 +604,7 @@ void fmt::BasicWriter<Char>::PrintfParser::ParseFlags(
} }
template <typename Char> template <typename Char>
unsigned fmt::BasicWriter<Char>::PrintfParser::ParseHeader( unsigned fmt::internal::PrintfParser<Char>::ParseHeader(
const Char *&s, FormatSpec &spec, const char *&error) { const Char *&s, FormatSpec &spec, const char *&error) {
unsigned arg_index = UINT_MAX; unsigned arg_index = UINT_MAX;
Char c = *s; Char c = *s;
@ -672,8 +670,8 @@ unsigned fmt::BasicWriter<Char>::PrintfParser::ParseHeader(
// TODO: move to a base class that doesn't depend on template argument // TODO: move to a base class that doesn't depend on template argument
template <typename Char> template <typename Char>
const typename fmt::BasicWriter<Char>::Arg const fmt::internal::ArgInfo
&fmt::BasicWriter<Char>::PrintfParser::HandleArgIndex( &fmt::internal::PrintfParser<Char>::HandleArgIndex(
unsigned arg_index, const char *&error) { unsigned arg_index, const char *&error) {
if (arg_index != UINT_MAX) { if (arg_index != UINT_MAX) {
if (next_arg_index_ <= 0) { if (next_arg_index_ <= 0) {
@ -695,7 +693,7 @@ const typename fmt::BasicWriter<Char>::Arg
} }
template <typename Char> template <typename Char>
void fmt::BasicWriter<Char>::PrintfParser::Format( void fmt::internal::PrintfParser<Char>::Format(
BasicWriter<Char> &writer, BasicStringRef<Char> format, BasicWriter<Char> &writer, BasicStringRef<Char> format,
const ArgList &args) { const ArgList &args) {
const Char *start = format.c_str(); const Char *start = format.c_str();
@ -1132,7 +1130,7 @@ template fmt::BasicWriter<char>::CharPtr
template void fmt::BasicWriter<char>::FormatParser::Format( template void fmt::BasicWriter<char>::FormatParser::Format(
BasicWriter<char> &writer, BasicStringRef<char> format, const ArgList &args); BasicWriter<char> &writer, BasicStringRef<char> format, const ArgList &args);
template void fmt::BasicWriter<char>::PrintfParser::Format( template void fmt::internal::PrintfParser<char>::Format(
BasicWriter<char> &writer, BasicStringRef<char> format, const ArgList &args); BasicWriter<char> &writer, BasicStringRef<char> format, const ArgList &args);
// Explicit instantiations for wchar_t. // Explicit instantiations for wchar_t.
@ -1145,7 +1143,7 @@ template void fmt::BasicWriter<wchar_t>::FormatParser::Format(
BasicWriter<wchar_t> &writer, BasicStringRef<wchar_t> format, BasicWriter<wchar_t> &writer, BasicStringRef<wchar_t> format,
const ArgList &args); const ArgList &args);
template void fmt::BasicWriter<wchar_t>::PrintfParser::Format( template void fmt::internal::PrintfParser<wchar_t>::Format(
BasicWriter<wchar_t> &writer, BasicStringRef<wchar_t> format, BasicWriter<wchar_t> &writer, BasicStringRef<wchar_t> format,
const ArgList &args); const ArgList &args);

View File

@ -1008,6 +1008,30 @@ public:
} }
}; };
namespace internal {
// Printf format string parser.
template <typename Char>
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<Char> &writer,
BasicStringRef<Char> format, const ArgList &args);
};
} // namespace internal
// Generates a comma-separated list with results of applying f to numbers 0..n-1. // 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_GEN(n, f) FMT_GEN##n(f)
# define FMT_GEN1(f) f(0) # define FMT_GEN1(f) f(0)
@ -1125,8 +1149,6 @@ class BasicWriter {
typedef internal::ArgInfo Arg; typedef internal::ArgInfo Arg;
static const Arg DUMMY_ARG;
#if _SECURE_SCL #if _SECURE_SCL
static Char *GetBase(CharPtr p) { return p.base(); } static Char *GetBase(CharPtr p) { return p.base(); }
#else #else
@ -1180,8 +1202,6 @@ class BasicWriter {
// Do not implement! // Do not implement!
void operator<<(typename internal::CharTraits<Char>::UnsupportedStrType); void operator<<(typename internal::CharTraits<Char>::UnsupportedStrType);
static ULongLong GetIntValue(const Arg &arg);
// Format string parser. // Format string parser.
class FormatParser { class FormatParser {
private: private:
@ -1199,24 +1219,7 @@ class BasicWriter {
BasicStringRef<Char> format, const ArgList &args); BasicStringRef<Char> format, const ArgList &args);
}; };
// Printf format string parser. friend class internal::PrintfParser<Char>;
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<Char> &writer,
BasicStringRef<Char> format, const ArgList &args);
};
public: public:
/** /**
@ -1302,7 +1305,7 @@ class BasicWriter {
friend void printf(BasicWriter<Char> &w, friend void printf(BasicWriter<Char> &w,
BasicStringRef<Char> format, const ArgList &args) { BasicStringRef<Char> format, const ArgList &args) {
PrintfParser().Format(w, format, args); internal::PrintfParser<Char>().Format(w, format, args);
} }
BasicWriter &operator<<(int value) { BasicWriter &operator<<(int value) {