diff --git a/format.cc b/format.cc index 9624bfb9..0451851b 100644 --- a/format.cc +++ b/format.cc @@ -532,8 +532,8 @@ void fmt::BasicWriter::write_double(T value, const FormatSpec &spec) { if (SignBit(static_cast(value))) { sign = '-'; value = -value; - } else if (spec.sign_flag()) { - sign = spec.plus_flag() ? '+' : ' '; + } else if (spec.flag(SIGN_FLAG)) { + sign = spec.flag(PLUS_FLAG) ? '+' : ' '; } if (value != value) { @@ -581,7 +581,7 @@ void fmt::BasicWriter::write_double(T value, const FormatSpec &spec) { Char *format_ptr = format; *format_ptr++ = '%'; unsigned width_for_sprintf = width; - if (spec.hash_flag()) + if (spec.flag(HASH_FLAG)) *format_ptr++ = '#'; if (spec.align() == ALIGN_CENTER) { width_for_sprintf = 0; @@ -852,7 +852,7 @@ void fmt::internal::PrintfFormatter::Format( } const Arg &arg = handle_arg_index(arg_index); - if (spec.hash_flag() && GetIntValue(arg) == 0) + if (spec.flag(HASH_FLAG) && GetIntValue(arg) == 0) spec.flags_ &= ~HASH_FLAG; if (spec.fill_ == '0') { if (arg.type <= Arg::LAST_NUMERIC_TYPE) diff --git a/format.h b/format.h index 1195c604..c47db9c3 100644 --- a/format.h +++ b/format.h @@ -920,12 +920,7 @@ struct TypeSpec : EmptySpec { Alignment align() const { return ALIGN_DEFAULT; } unsigned width() const { return 0; } int precision() const { return -1; } - - bool sign_flag() const { return false; } - bool plus_flag() const { return false; } - bool hash_flag() const { return false; } - bool char_flag() const { return false; } - + bool flag(unsigned) const { return false; } char type() const { return TYPE; } char fill() const { return ' '; } }; @@ -960,11 +955,7 @@ template struct AlignTypeSpec : AlignSpec { AlignTypeSpec(unsigned width, wchar_t fill) : AlignSpec(width, fill) {} - bool sign_flag() const { return false; } - bool plus_flag() const { return false; } - bool hash_flag() const { return false; } - bool char_flag() const { return false; } - + bool flag(unsigned) const { return false; } char type() const { return TYPE; } }; @@ -978,13 +969,8 @@ struct FormatSpec : AlignSpec { unsigned width = 0, char type = 0, wchar_t fill = ' ') : AlignSpec(width, fill), flags_(0), precision_(-1), type_(type) {} - bool sign_flag() const { return (flags_ & SIGN_FLAG) != 0; } - bool plus_flag() const { return (flags_ & PLUS_FLAG) != 0; } - bool hash_flag() const { return (flags_ & HASH_FLAG) != 0; } - bool char_flag() const { return (flags_ & CHAR_FLAG) != 0; } - + bool flag(unsigned f) const { return (flags_ & f) != 0; } int precision() const { return precision_; } - char type() const { return type_; } }; @@ -1622,8 +1608,8 @@ void BasicWriter::write_int(T value, const Spec &spec) { prefix[0] = '-'; ++prefix_size; abs_value = 0 - abs_value; - } else if (spec.sign_flag()) { - prefix[0] = spec.plus_flag() ? '+' : ' '; + } else if (spec.flag(SIGN_FLAG)) { + prefix[0] = spec.flag(PLUS_FLAG) ? '+' : ' '; ++prefix_size; } switch (spec.type()) { @@ -1636,7 +1622,7 @@ void BasicWriter::write_int(T value, const Spec &spec) { } case 'x': case 'X': { UnsignedType n = abs_value; - if (spec.hash_flag()) { + if (spec.flag(HASH_FLAG)) { prefix[prefix_size++] = '0'; prefix[prefix_size++] = spec.type(); } @@ -1656,7 +1642,7 @@ void BasicWriter::write_int(T value, const Spec &spec) { } case 'b': case 'B': { UnsignedType n = abs_value; - if (spec.hash_flag()) { + if (spec.flag(HASH_FLAG)) { prefix[prefix_size++] = '0'; prefix[prefix_size++] = spec.type(); } @@ -1673,7 +1659,7 @@ void BasicWriter::write_int(T value, const Spec &spec) { } case 'o': { UnsignedType n = abs_value; - if (spec.hash_flag()) + if (spec.flag(HASH_FLAG)) prefix[prefix_size++] = '0'; unsigned num_digits = 0; do { @@ -1689,7 +1675,7 @@ void BasicWriter::write_int(T value, const Spec &spec) { } default: internal::ReportUnknownType( - spec.type(), spec.char_flag() ? "char" : "integer"); + spec.type(), spec.flag(CHAR_FLAG) ? "char" : "integer"); break; } }