LibC: Fix coding style in scanf helpers

This commit is contained in:
Andreas Kling 2021-04-08 12:52:15 +02:00
parent c4e19250a1
commit ce80f0d552
Notes: sideshowbarker 2024-07-18 20:39:00 +09:00

View File

@ -71,7 +71,7 @@ enum class ReadKind {
};
template<typename T, typename ApT, ReadKind kind = ReadKind::Normal>
struct read_element_concrete {
struct ReadElementConcrete {
bool operator()(GenericLexer&, va_list)
{
return false;
@ -79,7 +79,7 @@ struct read_element_concrete {
};
template<typename ApT, ReadKind kind>
struct read_element_concrete<int, ApT, kind> {
struct ReadElementConcrete<int, ApT, kind> {
bool operator()(GenericLexer& lexer, va_list* ap)
{
lexer.ignore_while(isspace);
@ -113,7 +113,7 @@ struct read_element_concrete<int, ApT, kind> {
};
template<typename ApT, ReadKind kind>
struct read_element_concrete<char, ApT, kind> {
struct ReadElementConcrete<char, ApT, kind> {
bool operator()(GenericLexer& lexer, va_list* ap)
{
static_assert(kind == ReadKind::Normal, "Can't read a non-normal character");
@ -130,7 +130,7 @@ struct read_element_concrete<char, ApT, kind> {
};
template<typename ApT, ReadKind kind>
struct read_element_concrete<unsigned, ApT, kind> {
struct ReadElementConcrete<unsigned, ApT, kind> {
bool operator()(GenericLexer& lexer, va_list* ap)
{
lexer.ignore_while(isspace);
@ -164,7 +164,7 @@ struct read_element_concrete<unsigned, ApT, kind> {
};
template<typename ApT, ReadKind kind>
struct read_element_concrete<long long, ApT, kind> {
struct ReadElementConcrete<long long, ApT, kind> {
bool operator()(GenericLexer& lexer, va_list* ap)
{
lexer.ignore_while(isspace);
@ -198,7 +198,7 @@ struct read_element_concrete<long long, ApT, kind> {
};
template<typename ApT, ReadKind kind>
struct read_element_concrete<unsigned long long, ApT, kind> {
struct ReadElementConcrete<unsigned long long, ApT, kind> {
bool operator()(GenericLexer& lexer, va_list* ap)
{
lexer.ignore_while(isspace);
@ -232,7 +232,7 @@ struct read_element_concrete<unsigned long long, ApT, kind> {
};
template<typename ApT, ReadKind kind>
struct read_element_concrete<float, ApT, kind> {
struct ReadElementConcrete<float, ApT, kind> {
bool operator()(GenericLexer& lexer, va_list* ap)
{
lexer.ignore_while(isspace);
@ -263,7 +263,7 @@ struct read_element_concrete<float, ApT, kind> {
};
template<typename T, ReadKind kind>
struct read_element {
struct ReadElement {
bool operator()(LengthModifier length_modifier, GenericLexer& input_lexer, va_list* ap)
{
switch (length_modifier) {
@ -271,42 +271,42 @@ struct read_element {
case None:
VERIFY_NOT_REACHED();
case Default:
return read_element_concrete<T, T, kind> {}(input_lexer, ap);
return ReadElementConcrete<T, T, kind> {}(input_lexer, ap);
case Char:
return read_element_concrete<T, char, kind> {}(input_lexer, ap);
return ReadElementConcrete<T, char, kind> {}(input_lexer, ap);
case Short:
return read_element_concrete<T, short, kind> {}(input_lexer, ap);
return ReadElementConcrete<T, short, kind> {}(input_lexer, ap);
case Long:
if constexpr (IsSame<T, int>::value)
return read_element_concrete<T, long, kind> {}(input_lexer, ap);
return ReadElementConcrete<T, long, kind> {}(input_lexer, ap);
if constexpr (IsSame<T, unsigned>::value)
return read_element_concrete<T, unsigned, kind> {}(input_lexer, ap);
return ReadElementConcrete<T, unsigned, kind> {}(input_lexer, ap);
if constexpr (IsSame<T, float>::value)
return read_element_concrete<int, double, kind> {}(input_lexer, ap);
return ReadElementConcrete<int, double, kind> {}(input_lexer, ap);
return false;
case LongLong:
if constexpr (IsSame<T, int>::value)
return read_element_concrete<long long, long long, kind> {}(input_lexer, ap);
return ReadElementConcrete<long long, long long, kind> {}(input_lexer, ap);
if constexpr (IsSame<T, unsigned>::value)
return read_element_concrete<unsigned long long, unsigned long long, kind> {}(input_lexer, ap);
return ReadElementConcrete<unsigned long long, unsigned long long, kind> {}(input_lexer, ap);
if constexpr (IsSame<T, float>::value)
return read_element_concrete<long long, double, kind> {}(input_lexer, ap);
return ReadElementConcrete<long long, double, kind> {}(input_lexer, ap);
return false;
case IntMax:
return read_element_concrete<T, intmax_t, kind> {}(input_lexer, ap);
return ReadElementConcrete<T, intmax_t, kind> {}(input_lexer, ap);
case Size:
return read_element_concrete<T, size_t, kind> {}(input_lexer, ap);
return ReadElementConcrete<T, size_t, kind> {}(input_lexer, ap);
case PtrDiff:
return read_element_concrete<T, ptrdiff_t, kind> {}(input_lexer, ap);
return ReadElementConcrete<T, ptrdiff_t, kind> {}(input_lexer, ap);
case LongDouble:
return read_element_concrete<T, long double, kind> {}(input_lexer, ap);
return ReadElementConcrete<T, long double, kind> {}(input_lexer, ap);
}
}
};
template<>
struct read_element<char*, ReadKind::Normal> {
read_element(StringView scan_set = {}, bool invert = false)
struct ReadElement<char*, ReadKind::Normal> {
ReadElement(StringView scan_set = {}, bool invert = false)
: scan_set(scan_set.is_null() ? " \t\n\f\r" : scan_set)
, invert(scan_set.is_null() ? true : invert)
, was_null(scan_set.is_null())
@ -345,7 +345,7 @@ private:
};
template<>
struct read_element<void*, ReadKind::Normal> {
struct ReadElement<void*, ReadKind::Normal> {
bool operator()(LengthModifier length_modifier, GenericLexer& input_lexer, va_list* ap)
{
if (length_modifier != LengthModifier::Default)
@ -554,61 +554,61 @@ extern "C" int vsscanf(const char* input, const char* format, va_list ap)
dbgln("Invalid conversion specifier {} in scanf!", (int)conversion_specifier);
VERIFY_NOT_REACHED();
case Decimal:
if (!read_element<int, ReadKind::Normal> {}(length_modifier, input_lexer, (va_list*)&ap))
if (!ReadElement<int, ReadKind::Normal> {}(length_modifier, input_lexer, (va_list*)&ap))
format_lexer.consume_all();
else
++elements_matched;
break;
case Integer:
if (!read_element<int, ReadKind::Infer> {}(length_modifier, input_lexer, (va_list*)&ap))
if (!ReadElement<int, ReadKind::Infer> {}(length_modifier, input_lexer, (va_list*)&ap))
format_lexer.consume_all();
else
++elements_matched;
break;
case Octal:
if (!read_element<unsigned, ReadKind::Octal> {}(length_modifier, input_lexer, (va_list*)&ap))
if (!ReadElement<unsigned, ReadKind::Octal> {}(length_modifier, input_lexer, (va_list*)&ap))
format_lexer.consume_all();
else
++elements_matched;
break;
case Unsigned:
if (!read_element<unsigned, ReadKind::Normal> {}(length_modifier, input_lexer, (va_list*)&ap))
if (!ReadElement<unsigned, ReadKind::Normal> {}(length_modifier, input_lexer, (va_list*)&ap))
format_lexer.consume_all();
else
++elements_matched;
break;
case Hex:
if (!read_element<unsigned, ReadKind::Hex> {}(length_modifier, input_lexer, (va_list*)&ap))
if (!ReadElement<unsigned, ReadKind::Hex> {}(length_modifier, input_lexer, (va_list*)&ap))
format_lexer.consume_all();
else
++elements_matched;
break;
case Floating:
if (!read_element<float, ReadKind::Normal> {}(length_modifier, input_lexer, (va_list*)&ap))
if (!ReadElement<float, ReadKind::Normal> {}(length_modifier, input_lexer, (va_list*)&ap))
format_lexer.consume_all();
else
++elements_matched;
break;
case String:
if (!read_element<char*, ReadKind::Normal> {}(length_modifier, input_lexer, (va_list*)&ap))
if (!ReadElement<char*, ReadKind::Normal> {}(length_modifier, input_lexer, (va_list*)&ap))
format_lexer.consume_all();
else
++elements_matched;
break;
case UseScanList:
if (!read_element<char*, ReadKind::Normal> { scanlist, invert_scanlist }(length_modifier, input_lexer, (va_list*)&ap))
if (!ReadElement<char*, ReadKind::Normal> { scanlist, invert_scanlist }(length_modifier, input_lexer, (va_list*)&ap))
format_lexer.consume_all();
else
++elements_matched;
break;
case Character:
if (!read_element<char, ReadKind::Normal> {}(length_modifier, input_lexer, (va_list*)&ap))
if (!ReadElement<char, ReadKind::Normal> {}(length_modifier, input_lexer, (va_list*)&ap))
format_lexer.consume_all();
else
++elements_matched;
break;
case Pointer:
if (!read_element<void*, ReadKind::Normal> {}(length_modifier, input_lexer, (va_list*)&ap))
if (!ReadElement<void*, ReadKind::Normal> {}(length_modifier, input_lexer, (va_list*)&ap))
format_lexer.consume_all();
else
++elements_matched;