Revert "Took PrintfArgFormatter out of internal"
This reverts commit a8d0ed0828.
This commit is contained in:
parent
a8d0ed0828
commit
0b0e9255c7
@ -501,7 +501,7 @@ template void fmt::internal::FixedBuffer<char>::grow(std::size_t);
|
||||
|
||||
template void fmt::internal::ArgMap<char>::init(const fmt::ArgList &args);
|
||||
|
||||
template void fmt::PrintfFormatter<char>::format(
|
||||
template void fmt::internal::PrintfFormatter<char>::format(
|
||||
BasicWriter<char> &writer, CStringRef format);
|
||||
|
||||
template int fmt::internal::CharTraits<char>::format_float(
|
||||
@ -518,7 +518,7 @@ template void fmt::internal::FixedBuffer<wchar_t>::grow(std::size_t);
|
||||
|
||||
template void fmt::internal::ArgMap<wchar_t>::init(const fmt::ArgList &args);
|
||||
|
||||
template void fmt::PrintfFormatter<wchar_t>::format(
|
||||
template void fmt::internal::PrintfFormatter<wchar_t>::format(
|
||||
BasicWriter<wchar_t> &writer, WCStringRef format);
|
||||
|
||||
template int fmt::internal::CharTraits<wchar_t>::format_float(
|
||||
|
||||
13
fmt/format.h
13
fmt/format.h
@ -1319,6 +1319,8 @@ class RuntimeError : public std::runtime_error {
|
||||
RuntimeError() : std::runtime_error("") {}
|
||||
};
|
||||
|
||||
template <typename Char>
|
||||
class PrintfArgFormatter;
|
||||
|
||||
template <typename Char>
|
||||
class ArgMap;
|
||||
@ -1937,19 +1939,15 @@ class FormatterBase {
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Char> class PrintfArgFormatter;
|
||||
|
||||
} // namespace internal
|
||||
|
||||
// A printf formatter.
|
||||
template <typename Char, typename PAF = fmt::internal::PrintfArgFormatter<Char> >
|
||||
class PrintfFormatter : private internal::FormatterBase {
|
||||
class PrintfFormatter : private FormatterBase {
|
||||
private:
|
||||
void parse_flags(FormatSpec &spec, const Char *&s);
|
||||
|
||||
// Returns the argument with specified index or, if arg_index is equal
|
||||
// to the maximum unsigned value, the next argument.
|
||||
internal::Arg get_arg(const Char *s,
|
||||
Arg get_arg(const Char *s,
|
||||
unsigned arg_index = (std::numeric_limits<unsigned>::max)());
|
||||
|
||||
// Parses argument index, flags and width and returns the argument index.
|
||||
@ -1960,6 +1958,7 @@ template <typename Char> class PrintfArgFormatter;
|
||||
FMT_API void format(BasicWriter<Char> &writer,
|
||||
BasicCStringRef<Char> format_str);
|
||||
};
|
||||
} // namespace internal
|
||||
|
||||
/**
|
||||
\rst
|
||||
@ -3191,7 +3190,7 @@ FMT_API void print(CStringRef format_str, ArgList args);
|
||||
|
||||
template <typename Char>
|
||||
void printf(BasicWriter<Char> &w, BasicCStringRef<Char> format, ArgList args) {
|
||||
PrintfFormatter<Char>(args).format(w, format);
|
||||
internal::PrintfFormatter<Char>(args).format(w, format);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
37
fmt/printf.h
37
fmt/printf.h
@ -252,11 +252,8 @@ class PrintfArgFormatter :
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
}// namespace internal
|
||||
|
||||
template <typename Char, typename PAF>
|
||||
void fmt::PrintfFormatter<Char, PAF>::parse_flags(
|
||||
template <typename Char, typename PAF>
|
||||
void fmt::internal::PrintfFormatter<Char, PAF>::parse_flags(
|
||||
FormatSpec &spec, const Char *&s) {
|
||||
for (;;) {
|
||||
switch (*s++) {
|
||||
@ -283,11 +280,11 @@ void fmt::PrintfFormatter<Char, PAF>::parse_flags(
|
||||
}
|
||||
|
||||
template <typename Char, typename PAF>
|
||||
internal::Arg fmt::PrintfFormatter<Char, PAF>::get_arg(
|
||||
Arg fmt::internal::PrintfFormatter<Char, PAF>::get_arg(
|
||||
const Char *s, unsigned arg_index) {
|
||||
(void)s;
|
||||
const char *error = 0;
|
||||
internal::Arg arg = arg_index == UINT_MAX ?
|
||||
Arg arg = arg_index == UINT_MAX ?
|
||||
next_arg(error) : FormatterBase::get_arg(arg_index - 1, error);
|
||||
if (error)
|
||||
FMT_THROW(FormatError(!*s ? "invalid format string" : error));
|
||||
@ -295,14 +292,14 @@ internal::Arg fmt::PrintfFormatter<Char, PAF>::get_arg(
|
||||
}
|
||||
|
||||
template <typename Char, typename PAF>
|
||||
unsigned fmt::PrintfFormatter<Char, PAF>::parse_header(
|
||||
unsigned fmt::internal::PrintfFormatter<Char, PAF>::parse_header(
|
||||
const Char *&s, FormatSpec &spec) {
|
||||
unsigned arg_index = UINT_MAX;
|
||||
Char c = *s;
|
||||
if (c >= '0' && c <= '9') {
|
||||
// Parse an argument index (if followed by '$') or a width possibly
|
||||
// preceded with '0' flag(s).
|
||||
unsigned value = internal::parse_nonnegative_int(s);
|
||||
unsigned value = parse_nonnegative_int(s);
|
||||
if (*s == '$') { // value is an argument index
|
||||
++s;
|
||||
arg_index = value;
|
||||
@ -320,16 +317,16 @@ unsigned fmt::PrintfFormatter<Char, PAF>::parse_header(
|
||||
parse_flags(spec, s);
|
||||
// Parse width.
|
||||
if (*s >= '0' && *s <= '9') {
|
||||
spec.width_ = internal::parse_nonnegative_int(s);
|
||||
spec.width_ = parse_nonnegative_int(s);
|
||||
} else if (*s == '*') {
|
||||
++s;
|
||||
spec.width_ = internal::WidthHandler(spec).visit(get_arg(s));
|
||||
spec.width_ = WidthHandler(spec).visit(get_arg(s));
|
||||
}
|
||||
return arg_index;
|
||||
}
|
||||
|
||||
template <typename Char, typename PAF >
|
||||
void fmt::PrintfFormatter<Char,PAF>::format(
|
||||
void fmt::internal::PrintfFormatter<Char,PAF>::format(
|
||||
BasicWriter<Char> &writer, BasicCStringRef<Char> format_str) {
|
||||
const Char *start = format_str.c_str();
|
||||
const Char *s = start;
|
||||
@ -353,18 +350,18 @@ template <typename Char, typename PAF >
|
||||
if (*s == '.') {
|
||||
++s;
|
||||
if ('0' <= *s && *s <= '9') {
|
||||
spec.precision_ = static_cast<int>(internal::parse_nonnegative_int(s));
|
||||
spec.precision_ = static_cast<int>(parse_nonnegative_int(s));
|
||||
} else if (*s == '*') {
|
||||
++s;
|
||||
spec.precision_ = internal::PrecisionHandler().visit(get_arg(s));
|
||||
spec.precision_ = PrecisionHandler().visit(get_arg(s));
|
||||
}
|
||||
}
|
||||
|
||||
internal::Arg arg = get_arg(s, arg_index);
|
||||
if (spec.flag(HASH_FLAG) && internal::IsZeroInt().visit(arg))
|
||||
spec.flags_ &= ~internal::to_unsigned<int>(HASH_FLAG);
|
||||
Arg arg = get_arg(s, arg_index);
|
||||
if (spec.flag(HASH_FLAG) && IsZeroInt().visit(arg))
|
||||
spec.flags_ &= ~to_unsigned<int>(HASH_FLAG);
|
||||
if (spec.fill_ == '0') {
|
||||
if (arg.type <= internal::Arg::LAST_NUMERIC_TYPE)
|
||||
if (arg.type <= Arg::LAST_NUMERIC_TYPE)
|
||||
spec.align_ = ALIGN_NUMERIC;
|
||||
else
|
||||
spec.fill_ = ' '; // Ignore '0' flag for non-numeric types.
|
||||
@ -406,7 +403,7 @@ template <typename Char, typename PAF >
|
||||
if (!*s)
|
||||
FMT_THROW(FormatError("invalid format string"));
|
||||
spec.type_ = static_cast<char>(*s++);
|
||||
if (arg.type <= internal::Arg::LAST_INTEGER_TYPE) {
|
||||
if (arg.type <= Arg::LAST_INTEGER_TYPE) {
|
||||
// Normalize type.
|
||||
switch (spec.type_) {
|
||||
case 'i': case 'u':
|
||||
@ -427,6 +424,8 @@ template <typename Char, typename PAF >
|
||||
write(writer, start, s);
|
||||
}
|
||||
|
||||
}// namespace internal
|
||||
|
||||
} // namespace fmt
|
||||
|
||||
#endif
|
||||
|
||||
@ -46,7 +46,7 @@ FMT_VARIADIC(std::string, custom_format, const char *)
|
||||
|
||||
std::string printfer(const char* fstr, fmt::ArgList args){
|
||||
fmt::MemoryWriter writer;
|
||||
fmt::PrintfFormatter<char, CustomPAF> pfer(args);
|
||||
fmt::internal::PrintfFormatter<char, CustomPAF> pfer(args);
|
||||
pfer.format(writer,fstr);
|
||||
return writer.str();
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user