Replaced if-statement-chain with switch case
This commit is contained in:
parent
4c054bea8a
commit
5a0185e074
59
inc/parse.h
59
inc/parse.h
@ -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]) {
|
||||||
|
case 's':
|
||||||
return {true, i, FormatType::s};
|
return {true, i, FormatType::s};
|
||||||
} else if (s[i] == 'c') { // char
|
case 'c':
|
||||||
++i;
|
|
||||||
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};
|
||||||
} else if (s[i] == 'B') {
|
case 'B':
|
||||||
++i;
|
|
||||||
return {true, i, FormatType::B};
|
return {true, i, FormatType::B};
|
||||||
// } else if (s[i] == 'c') {
|
case 'd':
|
||||||
// ++i;
|
|
||||||
// return {true, i, FormatType::c};
|
|
||||||
} else if (s[i] == 'd') {
|
|
||||||
++i;
|
|
||||||
return {true, i, FormatType::d};
|
return {true, i, FormatType::d};
|
||||||
} else if (s[i] == 'o') {
|
case 'o':
|
||||||
++i;
|
|
||||||
return {true, i, FormatType::o};
|
return {true, i, FormatType::o};
|
||||||
} else if (s[i] == 'x') {
|
case 'x':
|
||||||
++i;
|
|
||||||
return {true, i, FormatType::x};
|
return {true, i, FormatType::x};
|
||||||
} else if (s[i] == 'X') {
|
case 'X':
|
||||||
++i;
|
|
||||||
return {true, i, FormatType::X};
|
return {true, i, FormatType::X};
|
||||||
} else if (s[i] == 'a') { // float
|
case 'a':
|
||||||
++i;
|
|
||||||
return {true, i, FormatType::a};
|
return {true, i, FormatType::a};
|
||||||
} else if (s[i] == 'A') {
|
case 'A':
|
||||||
++i;
|
|
||||||
return {true, i, FormatType::A};
|
return {true, i, FormatType::A};
|
||||||
} else if (s[i] == 'e') {
|
case 'e':
|
||||||
++i;
|
|
||||||
return {true, i, FormatType::e};
|
return {true, i, FormatType::e};
|
||||||
} else if (s[i] == 'E') {
|
case 'E':
|
||||||
++i;
|
|
||||||
return {true, i, FormatType::E};
|
return {true, i, FormatType::E};
|
||||||
} else if (s[i] == 'f') {
|
case 'f':
|
||||||
++i;
|
|
||||||
return {true, i, FormatType::f};
|
return {true, i, FormatType::f};
|
||||||
} else if (s[i] == 'F') {
|
case 'F':
|
||||||
++i;
|
|
||||||
return {true, i, FormatType::F};
|
return {true, i, FormatType::F};
|
||||||
} else if (s[i] == 'g') {
|
case 'g':
|
||||||
++i;
|
|
||||||
return {true, i, FormatType::g};
|
return {true, i, FormatType::g};
|
||||||
} else if (s[i] == 'G') {
|
case 'G':
|
||||||
++i;
|
|
||||||
return {true, i, FormatType::G};
|
return {true, i, FormatType::G};
|
||||||
} else if (s[i] == 'p') { // pointer
|
case 'p':
|
||||||
++i;
|
|
||||||
return {true, i, FormatType::p};
|
return {true, i, FormatType::p};
|
||||||
}
|
default:
|
||||||
|
--i;
|
||||||
return {false, i, FormatType::s};
|
return {false, i, FormatType::s};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template <ConstString s>
|
template <ConstString s>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user