internal::FormatParser -> BasicFormatter.
This commit is contained in:
parent
e825156add
commit
b9a06bafd8
12
format.cc
12
format.cc
@ -559,7 +559,7 @@ void fmt::BasicWriter<Char>::write_str(
|
|||||||
|
|
||||||
template <typename Char>
|
template <typename Char>
|
||||||
inline const Arg
|
inline const Arg
|
||||||
&fmt::internal::FormatParser<Char>::ParseArgIndex(const Char *&s) {
|
&fmt::BasicFormatter<Char>::ParseArgIndex(const Char *&s) {
|
||||||
unsigned arg_index = 0;
|
unsigned arg_index = 0;
|
||||||
if (*s < '0' || *s > '9') {
|
if (*s < '0' || *s > '9') {
|
||||||
if (*s != '}' && *s != ':')
|
if (*s != '}' && *s != ':')
|
||||||
@ -586,7 +586,7 @@ inline const Arg
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <typename Char>
|
template <typename Char>
|
||||||
void fmt::internal::FormatParser<Char>::CheckSign(
|
void fmt::BasicFormatter<Char>::CheckSign(
|
||||||
const Char *&s, const Arg &arg) {
|
const Char *&s, const Arg &arg) {
|
||||||
char sign = static_cast<char>(*s);
|
char sign = static_cast<char>(*s);
|
||||||
if (arg.type > Arg::LAST_NUMERIC_TYPE) {
|
if (arg.type > Arg::LAST_NUMERIC_TYPE) {
|
||||||
@ -868,7 +868,7 @@ void fmt::internal::PrintfParser<Char>::Format(
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <typename Char>
|
template <typename Char>
|
||||||
const Char *fmt::internal::FormatParser<Char>::format(
|
const Char *fmt::BasicFormatter<Char>::format(
|
||||||
const Char *format_str, const internal::Arg &arg) {
|
const Char *format_str, const internal::Arg &arg) {
|
||||||
const Char *s = format_str;
|
const Char *s = format_str;
|
||||||
const char *error = 0;
|
const char *error = 0;
|
||||||
@ -1073,7 +1073,7 @@ const Char *fmt::internal::FormatParser<Char>::format(
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <typename Char>
|
template <typename Char>
|
||||||
void fmt::internal::FormatParser<Char>::Format(
|
void fmt::BasicFormatter<Char>::Format(
|
||||||
BasicStringRef<Char> format_str, const ArgList &args) {
|
BasicStringRef<Char> format_str, const ArgList &args) {
|
||||||
const Char *s = start_ = format_str.c_str();
|
const Char *s = start_ = format_str.c_str();
|
||||||
args_ = args;
|
args_ = args;
|
||||||
@ -1142,7 +1142,7 @@ template fmt::BasicWriter<char>::CharPtr
|
|||||||
fmt::BasicWriter<char>::FillPadding(CharPtr buffer,
|
fmt::BasicWriter<char>::FillPadding(CharPtr buffer,
|
||||||
unsigned total_size, std::size_t content_size, wchar_t fill);
|
unsigned total_size, std::size_t content_size, wchar_t fill);
|
||||||
|
|
||||||
template void fmt::internal::FormatParser<char>::Format(
|
template void fmt::BasicFormatter<char>::Format(
|
||||||
BasicStringRef<char> format, const ArgList &args);
|
BasicStringRef<char> format, const ArgList &args);
|
||||||
|
|
||||||
template void fmt::internal::PrintfParser<char>::Format(
|
template void fmt::internal::PrintfParser<char>::Format(
|
||||||
@ -1154,7 +1154,7 @@ template fmt::BasicWriter<wchar_t>::CharPtr
|
|||||||
fmt::BasicWriter<wchar_t>::FillPadding(CharPtr buffer,
|
fmt::BasicWriter<wchar_t>::FillPadding(CharPtr buffer,
|
||||||
unsigned total_size, std::size_t content_size, wchar_t fill);
|
unsigned total_size, std::size_t content_size, wchar_t fill);
|
||||||
|
|
||||||
template void fmt::internal::FormatParser<wchar_t>::Format(
|
template void fmt::BasicFormatter<wchar_t>::Format(
|
||||||
BasicStringRef<wchar_t> format, const ArgList &args);
|
BasicStringRef<wchar_t> format, const ArgList &args);
|
||||||
|
|
||||||
template void fmt::internal::PrintfParser<wchar_t>::Format(
|
template void fmt::internal::PrintfParser<wchar_t>::Format(
|
||||||
|
26
format.h
26
format.h
@ -130,13 +130,11 @@ typedef BasicWriter<wchar_t> WWriter;
|
|||||||
|
|
||||||
struct FormatSpec;
|
struct FormatSpec;
|
||||||
|
|
||||||
namespace internal {
|
|
||||||
template <typename Char>
|
template <typename Char>
|
||||||
class FormatParser;
|
class BasicFormatter;
|
||||||
}
|
|
||||||
|
|
||||||
template <typename Char, typename T>
|
template <typename Char, typename T>
|
||||||
void format(internal::FormatParser<Char> &f, const Char *format_str, const T &value);
|
void format(BasicFormatter<Char> &f, const Char *format_str, const T &value);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
\rst
|
\rst
|
||||||
@ -654,7 +652,7 @@ class MakeArg : public Arg {
|
|||||||
template <typename T>
|
template <typename T>
|
||||||
static void format_custom_arg(
|
static void format_custom_arg(
|
||||||
void *formatter, const void *arg, const void *format_str) {
|
void *formatter, const void *arg, const void *format_str) {
|
||||||
format(*static_cast<FormatParser<Char>*>(formatter),
|
format(*static_cast<BasicFormatter<Char>*>(formatter),
|
||||||
static_cast<const Char*>(format_str), *static_cast<const T*>(arg));
|
static_cast<const Char*>(format_str), *static_cast<const T*>(arg));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -751,17 +749,15 @@ class ArgList {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
namespace internal {
|
// A formatter.
|
||||||
// Format string parser.
|
|
||||||
// TODO: rename to Formatter
|
|
||||||
template <typename Char>
|
template <typename Char>
|
||||||
class FormatParser {
|
class BasicFormatter {
|
||||||
private:
|
private:
|
||||||
BasicWriter<Char> &writer_;
|
BasicWriter<Char> &writer_;
|
||||||
ArgList args_;
|
ArgList args_;
|
||||||
int next_arg_index_;
|
int next_arg_index_;
|
||||||
const Char *start_;
|
const Char *start_;
|
||||||
fmt::internal::FormatErrorReporter<Char> report_error_;
|
internal::FormatErrorReporter<Char> report_error_;
|
||||||
|
|
||||||
// Parses argument index and returns an argument with this index.
|
// Parses argument index and returns an argument with this index.
|
||||||
const internal::Arg &ParseArgIndex(const Char *&s);
|
const internal::Arg &ParseArgIndex(const Char *&s);
|
||||||
@ -769,7 +765,7 @@ private:
|
|||||||
void CheckSign(const Char *&s, const internal::Arg &arg);
|
void CheckSign(const Char *&s, const internal::Arg &arg);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit FormatParser(BasicWriter<Char> &w) : writer_(w) {}
|
explicit BasicFormatter(BasicWriter<Char> &w) : writer_(w) {}
|
||||||
|
|
||||||
BasicWriter<Char> &writer() { return writer_; }
|
BasicWriter<Char> &writer() { return writer_; }
|
||||||
|
|
||||||
@ -778,6 +774,7 @@ public:
|
|||||||
const Char *format(const Char *format_str, const internal::Arg &arg);
|
const Char *format(const Char *format_str, const internal::Arg &arg);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
namespace internal {
|
||||||
// Printf format string parser.
|
// Printf format string parser.
|
||||||
template <typename Char>
|
template <typename Char>
|
||||||
class PrintfParser {
|
class PrintfParser {
|
||||||
@ -1256,7 +1253,7 @@ class BasicWriter {
|
|||||||
// Do not implement!
|
// Do not implement!
|
||||||
void operator<<(typename internal::CharTraits<Char>::UnsupportedStrType);
|
void operator<<(typename internal::CharTraits<Char>::UnsupportedStrType);
|
||||||
|
|
||||||
friend class internal::FormatParser<Char>;
|
friend class BasicFormatter<Char>;
|
||||||
friend class internal::PrintfParser<Char>;
|
friend class internal::PrintfParser<Char>;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@ -1337,7 +1334,7 @@ class BasicWriter {
|
|||||||
\endrst
|
\endrst
|
||||||
*/
|
*/
|
||||||
void write(BasicStringRef<Char> format, const ArgList &args) {
|
void write(BasicStringRef<Char> format, const ArgList &args) {
|
||||||
internal::FormatParser<Char>(*this).Format(format, args);
|
BasicFormatter<Char>(*this).Format(format, args);
|
||||||
}
|
}
|
||||||
FMT_VARIADIC_VOID(write, fmt::BasicStringRef<Char>)
|
FMT_VARIADIC_VOID(write, fmt::BasicStringRef<Char>)
|
||||||
|
|
||||||
@ -1588,8 +1585,7 @@ void BasicWriter<Char>::FormatInt(T value, const Spec &spec) {
|
|||||||
|
|
||||||
// Formats a value.
|
// Formats a value.
|
||||||
template <typename Char, typename T>
|
template <typename Char, typename T>
|
||||||
void format(internal::FormatParser<Char> &f,
|
void format(BasicFormatter<Char> &f, const Char *format_str, const T &value) {
|
||||||
const Char *format_str, const T &value) {
|
|
||||||
std::basic_ostringstream<Char> os;
|
std::basic_ostringstream<Char> os;
|
||||||
os << value;
|
os << value;
|
||||||
f.format(format_str, internal::MakeArg<Char>(os.str()));
|
f.format(format_str, internal::MakeArg<Char>(os.str()));
|
||||||
|
@ -1318,7 +1318,7 @@ TEST(FormatterTest, FormatUsingIOStreams) {
|
|||||||
class Answer {};
|
class Answer {};
|
||||||
|
|
||||||
template <typename Char>
|
template <typename Char>
|
||||||
void format(fmt::internal::FormatParser<Char> &f, const Char *, Answer) {
|
void format(fmt::BasicFormatter<Char> &f, const Char *, Answer) {
|
||||||
f.writer() << "42";
|
f.writer() << "42";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -185,7 +185,7 @@ TEST(UtilTest, MakeArg) {
|
|||||||
EXPECT_EQ(fmt::internal::Arg::CUSTOM, arg.type);
|
EXPECT_EQ(fmt::internal::Arg::CUSTOM, arg.type);
|
||||||
arg.custom.value = &t;
|
arg.custom.value = &t;
|
||||||
fmt::Writer w;
|
fmt::Writer w;
|
||||||
fmt::internal::FormatParser<char> formatter(w);
|
fmt::BasicFormatter<char> formatter(w);
|
||||||
arg.custom.format(&formatter, &t, "}");
|
arg.custom.format(&formatter, &t, "}");
|
||||||
EXPECT_EQ("test", w.str());
|
EXPECT_EQ("test", w.str());
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user