mirror of
https://github.com/fmtlib/fmt.git
synced 2025-02-04 15:40:07 +00:00
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>
|
||||
inline const Arg
|
||||
&fmt::internal::FormatParser<Char>::ParseArgIndex(const Char *&s) {
|
||||
&fmt::BasicFormatter<Char>::ParseArgIndex(const Char *&s) {
|
||||
unsigned arg_index = 0;
|
||||
if (*s < '0' || *s > '9') {
|
||||
if (*s != '}' && *s != ':')
|
||||
@ -586,7 +586,7 @@ inline const Arg
|
||||
}
|
||||
|
||||
template <typename Char>
|
||||
void fmt::internal::FormatParser<Char>::CheckSign(
|
||||
void fmt::BasicFormatter<Char>::CheckSign(
|
||||
const Char *&s, const Arg &arg) {
|
||||
char sign = static_cast<char>(*s);
|
||||
if (arg.type > Arg::LAST_NUMERIC_TYPE) {
|
||||
@ -868,7 +868,7 @@ void fmt::internal::PrintfParser<Char>::Format(
|
||||
}
|
||||
|
||||
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 *s = format_str;
|
||||
const char *error = 0;
|
||||
@ -1073,7 +1073,7 @@ const Char *fmt::internal::FormatParser<Char>::format(
|
||||
}
|
||||
|
||||
template <typename Char>
|
||||
void fmt::internal::FormatParser<Char>::Format(
|
||||
void fmt::BasicFormatter<Char>::Format(
|
||||
BasicStringRef<Char> format_str, const ArgList &args) {
|
||||
const Char *s = start_ = format_str.c_str();
|
||||
args_ = args;
|
||||
@ -1142,7 +1142,7 @@ template fmt::BasicWriter<char>::CharPtr
|
||||
fmt::BasicWriter<char>::FillPadding(CharPtr buffer,
|
||||
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);
|
||||
|
||||
template void fmt::internal::PrintfParser<char>::Format(
|
||||
@ -1154,7 +1154,7 @@ template fmt::BasicWriter<wchar_t>::CharPtr
|
||||
fmt::BasicWriter<wchar_t>::FillPadding(CharPtr buffer,
|
||||
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);
|
||||
|
||||
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;
|
||||
|
||||
namespace internal {
|
||||
template <typename Char>
|
||||
class FormatParser;
|
||||
}
|
||||
class BasicFormatter;
|
||||
|
||||
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
|
||||
@ -654,7 +652,7 @@ class MakeArg : public Arg {
|
||||
template <typename T>
|
||||
static void format_custom_arg(
|
||||
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));
|
||||
}
|
||||
|
||||
@ -751,17 +749,15 @@ class ArgList {
|
||||
}
|
||||
};
|
||||
|
||||
namespace internal {
|
||||
// Format string parser.
|
||||
// TODO: rename to Formatter
|
||||
// A formatter.
|
||||
template <typename Char>
|
||||
class FormatParser {
|
||||
class BasicFormatter {
|
||||
private:
|
||||
BasicWriter<Char> &writer_;
|
||||
ArgList args_;
|
||||
int next_arg_index_;
|
||||
const Char *start_;
|
||||
fmt::internal::FormatErrorReporter<Char> report_error_;
|
||||
internal::FormatErrorReporter<Char> report_error_;
|
||||
|
||||
// Parses argument index and returns an argument with this index.
|
||||
const internal::Arg &ParseArgIndex(const Char *&s);
|
||||
@ -769,7 +765,7 @@ private:
|
||||
void CheckSign(const Char *&s, const internal::Arg &arg);
|
||||
|
||||
public:
|
||||
explicit FormatParser(BasicWriter<Char> &w) : writer_(w) {}
|
||||
explicit BasicFormatter(BasicWriter<Char> &w) : writer_(w) {}
|
||||
|
||||
BasicWriter<Char> &writer() { return writer_; }
|
||||
|
||||
@ -778,6 +774,7 @@ public:
|
||||
const Char *format(const Char *format_str, const internal::Arg &arg);
|
||||
};
|
||||
|
||||
namespace internal {
|
||||
// Printf format string parser.
|
||||
template <typename Char>
|
||||
class PrintfParser {
|
||||
@ -1256,7 +1253,7 @@ class BasicWriter {
|
||||
// Do not implement!
|
||||
void operator<<(typename internal::CharTraits<Char>::UnsupportedStrType);
|
||||
|
||||
friend class internal::FormatParser<Char>;
|
||||
friend class BasicFormatter<Char>;
|
||||
friend class internal::PrintfParser<Char>;
|
||||
|
||||
public:
|
||||
@ -1337,7 +1334,7 @@ class BasicWriter {
|
||||
\endrst
|
||||
*/
|
||||
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>)
|
||||
|
||||
@ -1588,8 +1585,7 @@ void BasicWriter<Char>::FormatInt(T value, const Spec &spec) {
|
||||
|
||||
// Formats a value.
|
||||
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) {
|
||||
std::basic_ostringstream<Char> os;
|
||||
os << value;
|
||||
f.format(format_str, internal::MakeArg<Char>(os.str()));
|
||||
|
@ -1318,7 +1318,7 @@ TEST(FormatterTest, FormatUsingIOStreams) {
|
||||
class Answer {};
|
||||
|
||||
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";
|
||||
}
|
||||
|
||||
|
@ -185,7 +185,7 @@ TEST(UtilTest, MakeArg) {
|
||||
EXPECT_EQ(fmt::internal::Arg::CUSTOM, arg.type);
|
||||
arg.custom.value = &t;
|
||||
fmt::Writer w;
|
||||
fmt::internal::FormatParser<char> formatter(w);
|
||||
fmt::BasicFormatter<char> formatter(w);
|
||||
arg.custom.format(&formatter, &t, "}");
|
||||
EXPECT_EQ("test", w.str());
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user