From 6f0e3d6063ab75ad81899135689569e440ddb813 Mon Sep 17 00:00:00 2001 From: Riyyi Date: Tue, 9 Aug 2022 11:11:19 +0200 Subject: [PATCH] Util: Add Container parser checks --- src/util/format/formatter.h | 2 ++ src/util/format/parser.cpp | 22 ++++++++++++++++++++-- src/util/format/parser.h | 1 + 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/util/format/formatter.h b/src/util/format/formatter.h index 10e011e..4e20c8e 100644 --- a/src/util/format/formatter.h +++ b/src/util/format/formatter.h @@ -46,6 +46,8 @@ enum class PresentationType : uint8_t { String = 's', // Pointer Pointer = 'p', + // Container + Container = 'C', }; struct Specifier { diff --git a/src/util/format/parser.cpp b/src/util/format/parser.cpp index 1c1447a..b1e5140 100644 --- a/src/util/format/parser.cpp +++ b/src/util/format/parser.cpp @@ -320,7 +320,7 @@ constexpr void Parser::checkSpecifierCharType(const Specifier& specifier) { checkSpecifierIntegralType(specifier); - // Valid: fill, align, width + // Valid: fill + align, width // Invalid: sign, alternativeForm, zeroPadding, precision if (specifier.type == PresentationType::None || specifier.type == PresentationType::Character) { @@ -342,7 +342,7 @@ constexpr void Parser::checkSpecifierCStringType(const Specifier& specifier) VERIFY(false, "invalid type specifier"); } - // Valid: fill, align, width + // Valid: fill + align, width // Invalid: sign, alternativeForm, zeroPadding, precision VERIFY(specifier.sign == Builder::Sign::None, "invalid specifier option"); VERIFY(specifier.alternativeForm == false, "invalid specifier option"); @@ -362,6 +362,23 @@ constexpr void Parser::checkSpecifierPointerType(const Specifier& specifier) VERIFY(specifier.type != PresentationType::String, "invalid type specifier"); } +constexpr void Parser::checkSpecifierContainerType(const Specifier& specifier) +{ + switch (specifier.type) { + case PresentationType::None: + case PresentationType::Container: + break; + default: + VERIFY(false, "invalid type specifier"); + } + + // Valid: fill + align, alternativeForm, width + // Invalid: sign, zeroPadding, precision + VERIFY(specifier.sign == Builder::Sign::None, "invalid specifier option"); + VERIFY(specifier.zeroPadding == false, "invalid specifier option"); + VERIFY(specifier.precision == -1, "invalid specifier option"); +} + constexpr void Parser::checkSpecifierType(const Specifier& specifier, ParameterType type) { switch (type) { @@ -384,6 +401,7 @@ constexpr void Parser::checkSpecifierType(const Specifier& specifier, ParameterT checkSpecifierPointerType(specifier); break; case ParameterType::Container: + checkSpecifierContainerType(specifier); break; default: VERIFY_NOT_REACHED(); diff --git a/src/util/format/parser.h b/src/util/format/parser.h index 475fc19..c2dc8c0 100644 --- a/src/util/format/parser.h +++ b/src/util/format/parser.h @@ -50,6 +50,7 @@ public: constexpr void checkSpecifierCStringType(const Specifier& specifier); constexpr void checkSpecifierStringType(const Specifier& specifier); constexpr void checkSpecifierPointerType(const Specifier& specifier); + constexpr void checkSpecifierContainerType(const Specifier& specifier); constexpr void checkSpecifierType(const Specifier& specifier, ParameterType type); private: