mirror of
https://github.com/fmtlib/fmt.git
synced 2024-11-19 11:14:41 +00:00
FrmatSpec -> format_spec
This commit is contained in:
parent
b5fb8dd18b
commit
296e9cada2
34
fmt/format.h
34
fmt/format.h
@ -1738,8 +1738,8 @@ struct AlignTypeSpec : AlignSpec {
|
||||
char type() const { return TYPE; }
|
||||
};
|
||||
|
||||
// A full format specifier.
|
||||
class FormatSpec : public AlignSpec {
|
||||
// Format specifiers.
|
||||
class format_specs : public AlignSpec {
|
||||
private:
|
||||
template <typename Char>
|
||||
void set(fill_spec<Char> fill) {
|
||||
@ -1765,11 +1765,11 @@ class FormatSpec : public AlignSpec {
|
||||
int precision_;
|
||||
char type_;
|
||||
|
||||
FormatSpec(unsigned width = 0, char type = 0, wchar_t fill = ' ')
|
||||
format_specs(unsigned width = 0, char type = 0, wchar_t fill = ' ')
|
||||
: AlignSpec(width, fill), flags_(0), precision_(-1), type_(type) {}
|
||||
|
||||
template <typename... FormatSpecs>
|
||||
explicit FormatSpec(FormatSpecs... specs)
|
||||
explicit format_specs(FormatSpecs... specs)
|
||||
: AlignSpec(0, ' '), flags_(0), precision_(-1), type_(0){
|
||||
set(specs...);
|
||||
}
|
||||
@ -1855,7 +1855,7 @@ template <typename Char>
|
||||
class ArgFormatterBase {
|
||||
private:
|
||||
basic_writer<Char> &writer_;
|
||||
FormatSpec &spec_;
|
||||
format_specs &spec_;
|
||||
|
||||
FMT_DISALLOW_COPY_AND_ASSIGN(ArgFormatterBase);
|
||||
|
||||
@ -1883,7 +1883,7 @@ class ArgFormatterBase {
|
||||
|
||||
protected:
|
||||
basic_writer<Char> &writer() { return writer_; }
|
||||
FormatSpec &spec() { return spec_; }
|
||||
format_specs &spec() { return spec_; }
|
||||
|
||||
void write(bool value) {
|
||||
writer_.write_str(StringRef(value ? "true" : "false"), spec_);
|
||||
@ -1897,7 +1897,7 @@ class ArgFormatterBase {
|
||||
public:
|
||||
typedef Char char_type;
|
||||
|
||||
ArgFormatterBase(basic_writer<Char> &w, FormatSpec &s)
|
||||
ArgFormatterBase(basic_writer<Char> &w, format_specs &s)
|
||||
: writer_(w), spec_(s) {}
|
||||
|
||||
void operator()(monostate) {
|
||||
@ -2045,7 +2045,7 @@ class ArgFormatter : public internal::ArgFormatterBase<Char> {
|
||||
\endrst
|
||||
*/
|
||||
ArgFormatter(basic_writer<Char> &writer, basic_format_context<Char> &ctx,
|
||||
FormatSpec &spec)
|
||||
format_specs &spec)
|
||||
: internal::ArgFormatterBase<Char>(writer, spec), ctx_(ctx) {}
|
||||
|
||||
using internal::ArgFormatterBase<Char>::operator();
|
||||
@ -2255,14 +2255,14 @@ class basic_writer {
|
||||
|
||||
// Formats a floating-point number (double or long double).
|
||||
template <typename T>
|
||||
void write_double(T value, const FormatSpec &spec);
|
||||
void write_double(T value, const format_specs &spec);
|
||||
|
||||
// Writes a formatted string.
|
||||
template <typename StrChar>
|
||||
CharPtr write_str(const StrChar *s, std::size_t size, const AlignSpec &spec);
|
||||
|
||||
template <typename StrChar>
|
||||
void write_str(BasicStringRef<StrChar> str, const FormatSpec &spec);
|
||||
void write_str(BasicStringRef<StrChar> str, const format_specs &spec);
|
||||
|
||||
// This following methods are private to disallow writing wide characters
|
||||
// and strings to a char buffer. If you want to print a wide string as a
|
||||
@ -2382,11 +2382,11 @@ class basic_writer {
|
||||
template <typename T, typename... FormatSpecs>
|
||||
typename std::enable_if<std::is_integral<T>::value, void>::type
|
||||
write(T value, FormatSpecs... specs) {
|
||||
write_int(value, FormatSpec(specs...));
|
||||
write_int(value, format_specs(specs...));
|
||||
}
|
||||
|
||||
void write(double value) {
|
||||
write_double(value, FormatSpec());
|
||||
write_double(value, format_specs());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -2396,7 +2396,7 @@ class basic_writer {
|
||||
\endrst
|
||||
*/
|
||||
void write(long double value) {
|
||||
write_double(value, FormatSpec());
|
||||
write_double(value, format_specs());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -2427,7 +2427,7 @@ class basic_writer {
|
||||
|
||||
template <typename... FormatSpecs>
|
||||
void write(BasicStringRef<Char> str, FormatSpecs... specs) {
|
||||
write_str(str, FormatSpec(specs...));
|
||||
write_str(str, format_specs(specs...));
|
||||
}
|
||||
|
||||
void clear() FMT_NOEXCEPT { buffer_.clear(); }
|
||||
@ -2461,7 +2461,7 @@ typename basic_writer<Char>::CharPtr basic_writer<Char>::write_str(
|
||||
template <typename Char>
|
||||
template <typename StrChar>
|
||||
void basic_writer<Char>::write_str(
|
||||
BasicStringRef<StrChar> s, const FormatSpec &spec) {
|
||||
BasicStringRef<StrChar> s, const format_specs &spec) {
|
||||
// Check if StrChar is convertible to Char.
|
||||
internal::CharTraits<Char>::convert(StrChar());
|
||||
if (spec.type_ && spec.type_ != 's')
|
||||
@ -2649,7 +2649,7 @@ void basic_writer<Char>::write_int(T value, Spec spec) {
|
||||
|
||||
template <typename Char>
|
||||
template <typename T>
|
||||
void basic_writer<Char>::write_double(T value, const FormatSpec &spec) {
|
||||
void basic_writer<Char>::write_double(T value, const format_specs &spec) {
|
||||
// Check type.
|
||||
char type = spec.type();
|
||||
bool upper = false;
|
||||
@ -3366,7 +3366,7 @@ template <typename ArgFormatter, typename Char, typename Context>
|
||||
void do_format_arg(basic_writer<Char> &writer, basic_format_arg<Context> arg,
|
||||
Context &ctx) {
|
||||
const Char *&s = ctx.ptr();
|
||||
FormatSpec spec;
|
||||
format_specs spec;
|
||||
if (*s == ':') {
|
||||
if (visit(internal::CustomFormatter<Char, Context>(writer, ctx), arg))
|
||||
return;
|
||||
|
20
fmt/printf.h
20
fmt/printf.h
@ -170,12 +170,12 @@ class CharConverter {
|
||||
// left alignment if it is negative.
|
||||
class PrintfWidthHandler {
|
||||
private:
|
||||
FormatSpec &spec_;
|
||||
format_specs &spec_;
|
||||
|
||||
FMT_DISALLOW_COPY_AND_ASSIGN(PrintfWidthHandler);
|
||||
|
||||
public:
|
||||
explicit PrintfWidthHandler(FormatSpec &spec) : spec_(spec) {}
|
||||
explicit PrintfWidthHandler(format_specs &spec) : spec_(spec) {}
|
||||
|
||||
template <typename T>
|
||||
typename std::enable_if<std::is_integral<T>::value, unsigned>::type
|
||||
@ -224,14 +224,14 @@ class PrintfArgFormatter : public internal::ArgFormatterBase<Char> {
|
||||
specifier information for standard argument types.
|
||||
\endrst
|
||||
*/
|
||||
PrintfArgFormatter(basic_writer<Char> &writer, FormatSpec &spec)
|
||||
PrintfArgFormatter(basic_writer<Char> &writer, format_specs &spec)
|
||||
: internal::ArgFormatterBase<Char>(writer, spec) {}
|
||||
|
||||
using Base::operator();
|
||||
|
||||
/** Formats an argument of type ``bool``. */
|
||||
void operator()(bool value) {
|
||||
FormatSpec &fmt_spec = this->spec();
|
||||
format_specs &fmt_spec = this->spec();
|
||||
if (fmt_spec.type_ != 's')
|
||||
return (*this)(value ? 1 : 0);
|
||||
fmt_spec.type_ = 0;
|
||||
@ -240,7 +240,7 @@ class PrintfArgFormatter : public internal::ArgFormatterBase<Char> {
|
||||
|
||||
/** Formats a character. */
|
||||
void operator()(Char value) {
|
||||
const FormatSpec &fmt_spec = this->spec();
|
||||
const format_specs &fmt_spec = this->spec();
|
||||
basic_writer<Char> &w = this->writer();
|
||||
if (fmt_spec.type_ && fmt_spec.type_ != 'c')
|
||||
w.write_int(value, fmt_spec);
|
||||
@ -302,7 +302,7 @@ class printf_context :
|
||||
typedef internal::format_context_base<Char, printf_context> Base;
|
||||
typedef typename Base::format_arg format_arg;
|
||||
|
||||
void parse_flags(FormatSpec &spec, const Char *&s);
|
||||
void parse_flags(format_specs &spec, const Char *&s);
|
||||
|
||||
// Returns the argument with specified index or, if arg_index is equal
|
||||
// to the maximum unsigned value, the next argument.
|
||||
@ -311,7 +311,7 @@ class printf_context :
|
||||
unsigned arg_index = (std::numeric_limits<unsigned>::max)());
|
||||
|
||||
// Parses argument index, flags and width and returns the argument index.
|
||||
unsigned parse_header(const Char *&s, FormatSpec &spec);
|
||||
unsigned parse_header(const Char *&s, format_specs &spec);
|
||||
|
||||
public:
|
||||
/**
|
||||
@ -330,7 +330,7 @@ class printf_context :
|
||||
};
|
||||
|
||||
template <typename Char, typename AF>
|
||||
void printf_context<Char, AF>::parse_flags(FormatSpec &spec, const Char *&s) {
|
||||
void printf_context<Char, AF>::parse_flags(format_specs &spec, const Char *&s) {
|
||||
for (;;) {
|
||||
switch (*s++) {
|
||||
case '-':
|
||||
@ -369,7 +369,7 @@ typename printf_context<Char, AF>::format_arg printf_context<Char, AF>::get_arg(
|
||||
|
||||
template <typename Char, typename AF>
|
||||
unsigned printf_context<Char, AF>::parse_header(
|
||||
const Char *&s, FormatSpec &spec) {
|
||||
const Char *&s, format_specs &spec) {
|
||||
unsigned arg_index = std::numeric_limits<unsigned>::max();
|
||||
Char c = *s;
|
||||
if (c >= '0' && c <= '9') {
|
||||
@ -415,7 +415,7 @@ void printf_context<Char, AF>::format(basic_writer<Char> &writer) {
|
||||
}
|
||||
internal::write(writer, start, s - 1);
|
||||
|
||||
FormatSpec spec;
|
||||
format_specs spec;
|
||||
spec.align_ = ALIGN_RIGHT;
|
||||
|
||||
// Parse argument index, flags and width.
|
||||
|
@ -17,7 +17,7 @@ using fmt::PrintfArgFormatter;
|
||||
class CustomArgFormatter : public fmt::ArgFormatter<char> {
|
||||
public:
|
||||
CustomArgFormatter(fmt::writer &w, fmt::basic_format_context<char> &ctx,
|
||||
fmt::FormatSpec &s)
|
||||
fmt::format_specs &s)
|
||||
: fmt::ArgFormatter<char>(w, ctx, s) {}
|
||||
|
||||
using fmt::ArgFormatter<char>::operator();
|
||||
@ -33,7 +33,7 @@ class CustomArgFormatter : public fmt::ArgFormatter<char> {
|
||||
// rounded to 0.
|
||||
class CustomPrintfArgFormatter : public PrintfArgFormatter<char> {
|
||||
public:
|
||||
CustomPrintfArgFormatter(fmt::basic_writer<char> &w, fmt::FormatSpec &spec)
|
||||
CustomPrintfArgFormatter(fmt::basic_writer<char> &w, fmt::format_specs &spec)
|
||||
: PrintfArgFormatter<char>(w, spec) {}
|
||||
|
||||
using PrintfArgFormatter<char>::operator();
|
||||
|
@ -1644,7 +1644,7 @@ class MockArgFormatter : public fmt::internal::ArgFormatterBase<char> {
|
||||
typedef fmt::internal::ArgFormatterBase<char> Base;
|
||||
|
||||
MockArgFormatter(fmt::writer &w, fmt::format_context &ctx,
|
||||
fmt::FormatSpec &s)
|
||||
fmt::format_specs &s)
|
||||
: fmt::internal::ArgFormatterBase<char>(w, s) {
|
||||
EXPECT_CALL(*this, call(42));
|
||||
}
|
||||
|
@ -60,14 +60,14 @@ TEST(OStreamTest, Enum) {
|
||||
|
||||
struct TestArgFormatter : fmt::ArgFormatter<char> {
|
||||
TestArgFormatter(fmt::writer &w, fmt::format_context &ctx,
|
||||
fmt::FormatSpec &s)
|
||||
fmt::format_specs &s)
|
||||
: fmt::ArgFormatter<char>(w, ctx, s) {}
|
||||
};
|
||||
|
||||
TEST(OStreamTest, CustomArg) {
|
||||
fmt::MemoryWriter writer;
|
||||
fmt::format_context ctx("}", fmt::format_args());
|
||||
fmt::FormatSpec spec;
|
||||
fmt::format_specs spec;
|
||||
TestArgFormatter af(writer, ctx, spec);
|
||||
visit(af, fmt::internal::make_arg<fmt::format_context>(TestEnum()));
|
||||
EXPECT_EQ("TestEnum", writer.str());
|
||||
|
Loading…
Reference in New Issue
Block a user