mirror of
https://github.com/fmtlib/fmt.git
synced 2024-12-24 03:17:53 +00:00
Move PrintfParser from BasicWriter to the internal namespace.
This commit is contained in:
parent
e63a0ff125
commit
d29e505568
52
format.cc
52
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 <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
|
||||
// content area.
|
||||
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 StringChar>
|
||||
void fmt::BasicWriter<Char>::FormatString(
|
||||
@ -579,7 +577,7 @@ void fmt::BasicWriter<Char>::FormatParser::CheckSign(
|
||||
}
|
||||
|
||||
template <typename Char>
|
||||
void fmt::BasicWriter<Char>::PrintfParser::ParseFlags(
|
||||
void fmt::internal::PrintfParser<Char>::ParseFlags(
|
||||
FormatSpec &spec, const Char *&s) {
|
||||
for (;;) {
|
||||
switch (*s++) {
|
||||
@ -606,7 +604,7 @@ void fmt::BasicWriter<Char>::PrintfParser::ParseFlags(
|
||||
}
|
||||
|
||||
template <typename Char>
|
||||
unsigned fmt::BasicWriter<Char>::PrintfParser::ParseHeader(
|
||||
unsigned fmt::internal::PrintfParser<Char>::ParseHeader(
|
||||
const Char *&s, FormatSpec &spec, const char *&error) {
|
||||
unsigned arg_index = UINT_MAX;
|
||||
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
|
||||
template <typename Char>
|
||||
const typename fmt::BasicWriter<Char>::Arg
|
||||
&fmt::BasicWriter<Char>::PrintfParser::HandleArgIndex(
|
||||
const fmt::internal::ArgInfo
|
||||
&fmt::internal::PrintfParser<Char>::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<Char>::Arg
|
||||
}
|
||||
|
||||
template <typename Char>
|
||||
void fmt::BasicWriter<Char>::PrintfParser::Format(
|
||||
void fmt::internal::PrintfParser<Char>::Format(
|
||||
BasicWriter<Char> &writer, BasicStringRef<Char> format,
|
||||
const ArgList &args) {
|
||||
const Char *start = format.c_str();
|
||||
@ -1132,7 +1130,7 @@ template fmt::BasicWriter<char>::CharPtr
|
||||
template void fmt::BasicWriter<char>::FormatParser::Format(
|
||||
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);
|
||||
|
||||
// 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,
|
||||
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,
|
||||
const ArgList &args);
|
||||
|
||||
|
49
format.h
49
format.h
@ -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.
|
||||
# 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<Char>::UnsupportedStrType);
|
||||
|
||||
static ULongLong GetIntValue(const Arg &arg);
|
||||
|
||||
// Format string parser.
|
||||
class FormatParser {
|
||||
private:
|
||||
@ -1199,24 +1219,7 @@ class BasicWriter {
|
||||
BasicStringRef<Char> 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<Char> &writer,
|
||||
BasicStringRef<Char> format, const ArgList &args);
|
||||
};
|
||||
friend class internal::PrintfParser<Char>;
|
||||
|
||||
public:
|
||||
/**
|
||||
@ -1302,7 +1305,7 @@ class BasicWriter {
|
||||
|
||||
friend void printf(BasicWriter<Char> &w,
|
||||
BasicStringRef<Char> format, const ArgList &args) {
|
||||
PrintfParser().Format(w, format, args);
|
||||
internal::PrintfParser<Char>().Format(w, format, args);
|
||||
}
|
||||
|
||||
BasicWriter &operator<<(int value) {
|
||||
|
Loading…
Reference in New Issue
Block a user