Browse Source

Util: Add default alignment to string types

master
Riyyi 2 years ago
parent
commit
04250a8605
  1. 1
      src/util/format/builder.cpp
  2. 2
      src/util/format/format.cpp
  3. 5
      src/util/format/formatter.cpp

1
src/util/format/builder.cpp

@ -63,6 +63,7 @@ void Builder::putString(std::string_view string, size_t width, Align align, char
}
switch (align) {
case Align::None:
case Align::Left:
m_builder.write(string.data(), length);
m_builder << std::string(width - length, fill);

2
src/util/format/format.cpp

@ -31,7 +31,7 @@ void variadicFormatImpl(Builder& builder, Parser& parser, TypeErasedParameters&
// Get parameter at index, or next
size_t index = indexMaybe.has_value() ? indexMaybe.value() : parameters.tell();
VERIFY(index < parameters.size(), "argument not found at index '%zu':'%zu'", index, parameters.size());
VERIFY(index < parameters.size(), "argument not found at index '%zu'", index);
auto& parameter = parameters.parameter(index);
// Format the parameter

5
src/util/format/formatter.cpp

@ -85,11 +85,6 @@ void Formatter<bool>::format(Builder& builder, bool value) const
template<>
void Formatter<std::string_view>::format(Builder& builder, std::string_view value) const
{
if (specifier.align == Builder::Align::None) {
builder.putString(value, specifier.width);
return;
}
builder.putString(value, specifier.width, specifier.align, specifier.fill);
}

Loading…
Cancel
Save