Browse Source

Util: Rename Parser SpecifierType -> ParameterType

master
Riyyi 2 years ago
parent
commit
7825e87c19
  1. 10
      src/util/format/formatter.h
  2. 8
      src/util/format/parser.cpp
  3. 4
      src/util/format/parser.h

10
src/util/format/formatter.h

@ -67,16 +67,16 @@ struct Formatter {
constexpr void parse(Parser& parser)
{
if (std::is_integral_v<T>) {
parser.parseSpecifier(specifier, Parser::SpecifierType::Integral);
parser.parseSpecifier(specifier, Parser::ParameterType::Integral);
}
else if (std::is_floating_point_v<T>) {
parser.parseSpecifier(specifier, Parser::SpecifierType::FloatingPoint);
parser.parseSpecifier(specifier, Parser::ParameterType::FloatingPoint);
}
else if (std::is_same_v<T, char>) {
parser.parseSpecifier(specifier, Parser::SpecifierType::Char);
parser.parseSpecifier(specifier, Parser::ParameterType::Char);
}
else if (std::is_same_v<T, std::string_view>) {
parser.parseSpecifier(specifier, Parser::SpecifierType::String);
parser.parseSpecifier(specifier, Parser::ParameterType::String);
}
}
@ -143,7 +143,7 @@ struct Formatter<T*> {
constexpr void parse(Parser& parser)
{
parser.parseSpecifier(specifier, Parser::SpecifierType::Pointer);
parser.parseSpecifier(specifier, Parser::ParameterType::Pointer);
}
void format(Builder& builder, T* value) const

8
src/util/format/parser.cpp

@ -158,7 +158,7 @@ std::optional<size_t> Parser::consumeIndex()
VERIFY_NOT_REACHED();
}
void Parser::parseSpecifier(Specifier& specifier, SpecifierType type)
void Parser::parseSpecifier(Specifier& specifier, ParameterType type)
{
if (consumeSpecific('}') || isEOF()) {
return;
@ -204,7 +204,7 @@ void Parser::parseSpecifier(Specifier& specifier, SpecifierType type)
// Sign is only valid for numeric types
if (peek0 == '+' || peek0 == '-' || peek0 == ' ') {
VERIFY(state < State::AfterSign, "unexpected '%c' at this position", peek0);
VERIFY(type == SpecifierType::Integral || type == SpecifierType::FloatingPoint,
VERIFY(type == ParameterType::Integral || type == ParameterType::FloatingPoint,
"sign option is only valid for numeric types");
state = State::AfterSign;
specifier.sign = static_cast<Builder::Sign>(peek0);
@ -213,7 +213,7 @@ void Parser::parseSpecifier(Specifier& specifier, SpecifierType type)
// Alternative form is only valid for numeric types
if (peek0 == '#') {
VERIFY(state < State::AfterAlternativeForm, "unexpected '#' at this position");
VERIFY(type == SpecifierType::Integral || type == SpecifierType::FloatingPoint,
VERIFY(type == ParameterType::Integral || type == ParameterType::FloatingPoint,
"'#' option is only valid for numeric types");
state = State::AfterAlternativeForm;
specifier.alternativeForm = true;
@ -223,7 +223,7 @@ void Parser::parseSpecifier(Specifier& specifier, SpecifierType type)
if (peek0 == '0') {
if (state < State::AfterWidth) {
VERIFY(state < State::AfterZeroPadding, "unexpected '0' at this position");
VERIFY(type == SpecifierType::Integral || type == SpecifierType::FloatingPoint,
VERIFY(type == ParameterType::Integral || type == ParameterType::FloatingPoint,
"zero padding option is only valid for numeric types");
state = State::AfterZeroPadding;
specifier.zeroPadding = true;

4
src/util/format/parser.h

@ -24,7 +24,7 @@ public:
Manual, // {0},{1}
};
enum class SpecifierType {
enum class ParameterType {
Integral,
FloatingPoint,
Char,
@ -41,7 +41,7 @@ public:
std::string_view consumeLiteral();
std::optional<size_t> consumeIndex();
void parseSpecifier(Specifier& specifier, SpecifierType type);
void parseSpecifier(Specifier& specifier, ParameterType type);
private:
ArgumentIndexingMode m_mode { ArgumentIndexingMode::Automatic };

Loading…
Cancel
Save