Browse Source

Util: Reorder specifier arguments to match parsing order

master
Riyyi 2 years ago
parent
commit
5eb5e2d51e
  1. 12
      src/util/format/builder.cpp
  2. 6
      src/util/format/builder.h
  3. 6
      src/util/format/formatter.cpp
  4. 4
      src/util/format/formatter.h

12
src/util/format/builder.cpp

@ -28,7 +28,7 @@ void Builder::putLiteral(std::string_view literal)
}
}
void Builder::putU64(size_t value, size_t width, Align align, char fill, Sign sign, bool isNegative) const
void Builder::putU64(size_t value, char fill, Align align, Sign sign, size_t width, bool isNegative) const
{
std::string string = (std::stringstream {} << value).str();
@ -79,11 +79,11 @@ void Builder::putU64(size_t value, size_t width, Align align, char fill, Sign si
};
}
void Builder::putI64(int64_t value, size_t width, Align align, char fill, Sign sign) const
void Builder::putI64(int64_t value, char fill, Align align, Sign sign, size_t width) const
{
auto const isNegative = value < 0;
value = isNegative ? -value : value;
putU64(static_cast<uint64_t>(value), width, align, fill, sign, isNegative);
bool isNegative = value < 0;
value = isNegative ? -value : value;
putU64(static_cast<uint64_t>(value), fill, align, sign, width, isNegative);
}
void Builder::putF64(double number, uint8_t precision) const
@ -99,7 +99,7 @@ void Builder::putF64(double number, uint8_t precision) const
m_builder << string;
}
void Builder::putString(std::string_view string, size_t width, Align align, char fill) const
void Builder::putString(std::string_view string, char fill, Align align, size_t width) const
{
size_t length = string.length();
if (width < length) {

6
src/util/format/builder.h

@ -36,11 +36,11 @@ public:
void putLiteral(std::string_view literal);
void putU64(size_t value, size_t width = 0, Align align = Align::Right, char fill = ' ', Sign sign = Sign::Negative, bool isNegative = false) const;
void putI64(int64_t value, size_t width = 0, Align align = Align::Right, char fill = ' ', Sign sign = Sign::Negative) const;
void putU64(size_t value, char fill = ' ', Align align = Align::Right, Sign sign = Sign::Negative, size_t width = 0, bool isNegative = false) const;
void putI64(int64_t value, char fill = ' ', Align align = Align::Right, Sign sign = Sign::Negative, size_t width = 0) const;
void putF64(double number, uint8_t precision = 6) const;
void putCharacter(char character) const { m_builder.write(&character, 1); }
void putString(std::string_view string, size_t width = 0, Align align = Align::Left, char fill = ' ') const;
void putString(std::string_view string, char fill = ' ', Align align = Align::Left, size_t width = 0) const;
void putPointer(const void* pointer) const { m_builder << pointer; }
const std::stringstream& builder() const { return m_builder; }

6
src/util/format/formatter.cpp

@ -35,7 +35,7 @@ void Formatter<bool>::format(Builder& builder, bool value) const
template<>
void Formatter<std::string_view>::format(Builder& builder, std::string_view value) const
{
builder.putString(value, specifier.width, specifier.align, specifier.fill);
builder.putString(value, specifier.fill, specifier.align, specifier.width);
}
void Formatter<const char*>::parse(Parser& parser)
@ -51,7 +51,9 @@ void Formatter<const char*>::format(Builder& builder, const char* value) const
return;
}
builder.putString(value != nullptr ? std::string_view { value, strlen(value) } : "nullptr");
Formatter<std::string_view>::format(
builder,
value != nullptr ? std::string_view { value, strlen(value) } : "nullptr");
}
// Pointer

4
src/util/format/formatter.h

@ -93,11 +93,11 @@ struct Formatter<T> {
{
if (std::is_signed_v<T>) {
builder.putI64(
value, specifier.width, specifier.align, specifier.fill, specifier.sign);
value, specifier.fill, specifier.align, specifier.sign, specifier.width);
}
if (std::is_unsigned_v<T>) {
builder.putU64(
value, specifier.width, specifier.align, specifier.fill, specifier.sign);
value, specifier.fill, specifier.align, specifier.sign, specifier.width);
}
}
};

Loading…
Cancel
Save