Replaced if-statement-chain with switch case

This commit is contained in:
Andreas Tsouchlos 2021-11-25 09:48:55 +01:00
parent 4c054bea8a
commit 5a0185e074

View File

@ -119,63 +119,46 @@ constexpr parse_result_t<unsigned> parse_number(unsigned i) {
template <ConstString s> template <ConstString s>
constexpr parse_result_t<FormatType> parse_type(unsigned i) { constexpr parse_result_t<FormatType> parse_type(unsigned i) {
if (s[i] == 's') { // string ++i;
++i; switch (s[i]) {
return {true, i, FormatType::s}; case 's':
} else if (s[i] == 'c') { // char return {true, i, FormatType::s};
++i; case 'c':
return {true, i, FormatType::c}; return {true, i, FormatType::c};
} else if (s[i] == 'b') { // int case 'b':
++i; return {true, i, FormatType::b};
return {true, i, FormatType::b}; case 'B':
} else if (s[i] == 'B') { return {true, i, FormatType::B};
++i; case 'd':
return {true, i, FormatType::B}; return {true, i, FormatType::d};
// } else if (s[i] == 'c') { case 'o':
// ++i; return {true, i, FormatType::o};
// return {true, i, FormatType::c}; case 'x':
} else if (s[i] == 'd') { return {true, i, FormatType::x};
++i; case 'X':
return {true, i, FormatType::d}; return {true, i, FormatType::X};
} else if (s[i] == 'o') { case 'a':
++i; return {true, i, FormatType::a};
return {true, i, FormatType::o}; case 'A':
} else if (s[i] == 'x') { return {true, i, FormatType::A};
++i; case 'e':
return {true, i, FormatType::x}; return {true, i, FormatType::e};
} else if (s[i] == 'X') { case 'E':
++i; return {true, i, FormatType::E};
return {true, i, FormatType::X}; case 'f':
} else if (s[i] == 'a') { // float return {true, i, FormatType::f};
++i; case 'F':
return {true, i, FormatType::a}; return {true, i, FormatType::F};
} else if (s[i] == 'A') { case 'g':
++i; return {true, i, FormatType::g};
return {true, i, FormatType::A}; case 'G':
} else if (s[i] == 'e') { return {true, i, FormatType::G};
++i; case 'p':
return {true, i, FormatType::e}; return {true, i, FormatType::p};
} else if (s[i] == 'E') { default:
++i; --i;
return {true, i, FormatType::E}; return {false, i, FormatType::s};
} else if (s[i] == 'f') {
++i;
return {true, i, FormatType::f};
} else if (s[i] == 'F') {
++i;
return {true, i, FormatType::F};
} else if (s[i] == 'g') {
++i;
return {true, i, FormatType::g};
} else if (s[i] == 'G') {
++i;
return {true, i, FormatType::G};
} else if (s[i] == 'p') { // pointer
++i;
return {true, i, FormatType::p};
} }
return {false, i, FormatType::s};
} }
template <ConstString s> template <ConstString s>