Commit e78904b9 authored by Victor Zverovich's avatar Victor Zverovich

Move formatting functionality from BasicFormatter to BasicWriter & FormatPaser...

Move formatting functionality from BasicFormatter to BasicWriter & FormatPaser to simplify the implementation of standalone formatting methods.
parent 1104e732
...@@ -359,7 +359,7 @@ void fmt::BasicWriter<Char>::FormatDouble( ...@@ -359,7 +359,7 @@ void fmt::BasicWriter<Char>::FormatDouble(
// FormatError reporting unmatched '{'. The idea is that unmatched '{' // FormatError reporting unmatched '{'. The idea is that unmatched '{'
// should override other errors. // should override other errors.
template <typename Char> template <typename Char>
void fmt::BasicFormatter<Char>::ReportError( void fmt::BasicWriter<Char>::FormatParser::ReportError(
const Char *s, StringRef message) const { const Char *s, StringRef message) const {
for (int num_open_braces = num_open_braces_; *s; ++s) { for (int num_open_braces = num_open_braces_; *s; ++s) {
if (*s == '{') { if (*s == '{') {
...@@ -375,7 +375,7 @@ void fmt::BasicFormatter<Char>::ReportError( ...@@ -375,7 +375,7 @@ void fmt::BasicFormatter<Char>::ReportError(
// Parses an unsigned integer advancing s to the end of the parsed input. // Parses an unsigned integer advancing s to the end of the parsed input.
// This function assumes that the first character of s is a digit. // This function assumes that the first character of s is a digit.
template <typename Char> template <typename Char>
unsigned fmt::BasicFormatter<Char>::ParseUInt(const Char *&s) const { unsigned fmt::BasicWriter<Char>::FormatParser::ParseUInt(const Char *&s) const {
assert('0' <= *s && *s <= '9'); assert('0' <= *s && *s <= '9');
unsigned value = 0; unsigned value = 0;
do { do {
...@@ -388,8 +388,8 @@ unsigned fmt::BasicFormatter<Char>::ParseUInt(const Char *&s) const { ...@@ -388,8 +388,8 @@ unsigned fmt::BasicFormatter<Char>::ParseUInt(const Char *&s) const {
} }
template <typename Char> template <typename Char>
inline const typename fmt::BasicFormatter<Char>::ArgInfo inline const typename fmt::BasicWriter<Char>::ArgInfo
&fmt::BasicFormatter<Char>::ParseArgIndex(const Char *&s) { &fmt::BasicWriter<Char>::FormatParser::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 != ':')
...@@ -407,32 +407,35 @@ inline const typename fmt::BasicFormatter<Char>::ArgInfo ...@@ -407,32 +407,35 @@ inline const typename fmt::BasicFormatter<Char>::ArgInfo
next_arg_index_ = -1; next_arg_index_ = -1;
arg_index = ParseUInt(s); arg_index = ParseUInt(s);
} }
if (arg_index >= args_.size()) if (arg_index >= num_args_)
ReportError(s, "argument index is out of range in format"); ReportError(s, "argument index is out of range in format");
return args_[arg_index]; return args_[arg_index];
} }
template <typename Char> template <typename Char>
void fmt::BasicFormatter<Char>::CheckSign(const Char *&s, const ArgInfo &arg) { void fmt::BasicWriter<Char>::FormatParser::CheckSign(
const Char *&s, const ArgInfo &arg) {
char sign = static_cast<char>(*s); char sign = static_cast<char>(*s);
if (arg.type > LAST_NUMERIC_TYPE) { if (arg.type > LAST_NUMERIC_TYPE) {
ReportError(s, ReportError(s,
Format("format specifier '{}' requires numeric argument") << sign); fmt::Format("format specifier '{}' requires numeric argument") << sign);
} }
if (arg.type == UINT || arg.type == ULONG || arg.type == ULONG_LONG) { if (arg.type == UINT || arg.type == ULONG || arg.type == ULONG_LONG) {
ReportError(s, ReportError(s,
Format("format specifier '{}' requires signed argument") << sign); fmt::Format("format specifier '{}' requires signed argument") << sign);
} }
++s; ++s;
} }
template <typename Char> template <typename Char>
void fmt::BasicFormatter<Char>::DoFormat() { void fmt::BasicWriter<Char>::FormatParser::Format(
const Char *start = format_; BasicWriter<Char> &writer, BasicStringRef<Char> format,
format_ = 0; std::size_t num_args, const ArgInfo *args) {
const Char *start = format.c_str();
num_args_ = num_args;
args_ = args;
next_arg_index_ = 0; next_arg_index_ = 0;
const Char *s = start; const Char *s = start;
BasicWriter<Char> &writer = *writer_;
while (*s) { while (*s) {
Char c = *s++; Char c = *s++;
if (c != '{' && c != '}') continue; if (c != '{' && c != '}') continue;
...@@ -697,18 +700,21 @@ template fmt::BasicWriter<char>::CharPtr ...@@ -697,18 +700,21 @@ template fmt::BasicWriter<char>::CharPtr
fmt::BasicWriter<char>::PrepareFilledBuffer( fmt::BasicWriter<char>::PrepareFilledBuffer(
unsigned size, const AlignSpec &spec, char sign); unsigned size, const AlignSpec &spec, char sign);
template void fmt::BasicFormatter<char>::ReportError( template void fmt::BasicWriter<char>::FormatParser::ReportError(
const char *s, StringRef message) const; const char *s, StringRef message) const;
template unsigned fmt::BasicFormatter<char>::ParseUInt(const char *&s) const; template unsigned fmt::BasicWriter<char>::FormatParser::ParseUInt(
const char *&s) const;
template const fmt::BasicFormatter<char>::ArgInfo template const fmt::BasicWriter<char>::ArgInfo
&fmt::BasicFormatter<char>::ParseArgIndex(const char *&s); &fmt::BasicWriter<char>::FormatParser::ParseArgIndex(const char *&s);
template void fmt::BasicFormatter<char>::CheckSign( template void fmt::BasicWriter<char>::FormatParser::CheckSign(
const char *&s, const ArgInfo &arg); const char *&s, const ArgInfo &arg);
template void fmt::BasicFormatter<char>::DoFormat(); template void fmt::BasicWriter<char>::FormatParser::Format(
BasicWriter<char> &writer, BasicStringRef<char> format,
std::size_t num_args, const ArgInfo *args);
// Explicit instantiations for wchar_t. // Explicit instantiations for wchar_t.
...@@ -726,19 +732,21 @@ template fmt::BasicWriter<wchar_t>::CharPtr ...@@ -726,19 +732,21 @@ template fmt::BasicWriter<wchar_t>::CharPtr
fmt::BasicWriter<wchar_t>::PrepareFilledBuffer( fmt::BasicWriter<wchar_t>::PrepareFilledBuffer(
unsigned size, const AlignSpec &spec, char sign); unsigned size, const AlignSpec &spec, char sign);
template void fmt::BasicFormatter<wchar_t>::ReportError( template void fmt::BasicWriter<wchar_t>::FormatParser::ReportError(
const wchar_t *s, StringRef message) const; const wchar_t *s, StringRef message) const;
template unsigned fmt::BasicFormatter<wchar_t>::ParseUInt( template unsigned fmt::BasicWriter<wchar_t>::FormatParser::ParseUInt(
const wchar_t *&s) const; const wchar_t *&s) const;
template const fmt::BasicFormatter<wchar_t>::ArgInfo template const fmt::BasicWriter<wchar_t>::ArgInfo
&fmt::BasicFormatter<wchar_t>::ParseArgIndex(const wchar_t *&s); &fmt::BasicWriter<wchar_t>::FormatParser::ParseArgIndex(const wchar_t *&s);
template void fmt::BasicFormatter<wchar_t>::CheckSign( template void fmt::BasicWriter<wchar_t>::FormatParser::CheckSign(
const wchar_t *&s, const ArgInfo &arg); const wchar_t *&s, const ArgInfo &arg);
template void fmt::BasicFormatter<wchar_t>::DoFormat(); template void fmt::BasicWriter<wchar_t>::FormatParser::Format(
BasicWriter<wchar_t> &writer, BasicStringRef<wchar_t> format,
std::size_t num_args, const ArgInfo *args);
#if _MSC_VER #if _MSC_VER
# pragma warning(pop) # pragma warning(pop)
......
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment