Modernize: use enum class

This commit is contained in:
Daniel Marjamäki 2019-07-17 10:43:18 +02:00
parent 2afd5f5dd0
commit ec4d68e231
1 changed files with 39 additions and 39 deletions

View File

@ -643,87 +643,87 @@ bool MathLib::isDecimalFloat(const std::string &str)
{ {
if (str.empty()) if (str.empty())
return false; return false;
enum State { enum class State {
START, BASE_DIGITS1, LEADING_DECIMAL, TRAILING_DECIMAL, BASE_DIGITS2, E, MANTISSA_PLUSMINUS, MANTISSA_DIGITS, SUFFIX_F, SUFFIX_L START, BASE_DIGITS1, LEADING_DECIMAL, TRAILING_DECIMAL, BASE_DIGITS2, E, MANTISSA_PLUSMINUS, MANTISSA_DIGITS, SUFFIX_F, SUFFIX_L
} state = START; } state = State::START;
std::string::const_iterator it = str.begin(); std::string::const_iterator it = str.begin();
if ('+' == *it || '-' == *it) if ('+' == *it || '-' == *it)
++it; ++it;
for (; it != str.end(); ++it) { for (; it != str.end(); ++it) {
switch (state) { switch (state) {
case START: case State::START:
if (*it=='.') if (*it=='.')
state=LEADING_DECIMAL; state = State::LEADING_DECIMAL;
else if (std::isdigit(static_cast<unsigned char>(*it))) else if (std::isdigit(static_cast<unsigned char>(*it)))
state=BASE_DIGITS1; state = State::BASE_DIGITS1;
else else
return false; return false;
break; break;
case LEADING_DECIMAL: case State::LEADING_DECIMAL:
if (std::isdigit(static_cast<unsigned char>(*it))) if (std::isdigit(static_cast<unsigned char>(*it)))
state=BASE_DIGITS2; state = State::BASE_DIGITS2;
else else
return false; return false;
break; break;
case BASE_DIGITS1: case State::BASE_DIGITS1:
if (*it=='e' || *it=='E') if (*it=='e' || *it=='E')
state=E; state = State::E;
else if (*it=='.') else if (*it=='.')
state=TRAILING_DECIMAL; state = State::TRAILING_DECIMAL;
else if (!std::isdigit(static_cast<unsigned char>(*it))) else if (!std::isdigit(static_cast<unsigned char>(*it)))
return false; return false;
break; break;
case TRAILING_DECIMAL: case State::TRAILING_DECIMAL:
if (*it=='e' || *it=='E') if (*it=='e' || *it=='E')
state=E; state = State::E;
else if (*it=='f' || *it=='F') else if (*it=='f' || *it=='F')
state=SUFFIX_F; state = State::SUFFIX_F;
else if (*it=='l' || *it=='L') else if (*it=='l' || *it=='L')
state=SUFFIX_L; state = State::SUFFIX_L;
else if (std::isdigit(static_cast<unsigned char>(*it))) else if (std::isdigit(static_cast<unsigned char>(*it)))
state=BASE_DIGITS2; state = State::BASE_DIGITS2;
else else
return false; return false;
break; break;
case BASE_DIGITS2: case State::BASE_DIGITS2:
if (*it=='e' || *it=='E') if (*it=='e' || *it=='E')
state=E; state = State::E;
else if (*it=='f' || *it=='F') else if (*it=='f' || *it=='F')
state=SUFFIX_F; state = State::SUFFIX_F;
else if (*it=='l' || *it=='L') else if (*it=='l' || *it=='L')
state=SUFFIX_L; state = State::SUFFIX_L;
else if (!std::isdigit(static_cast<unsigned char>(*it))) else if (!std::isdigit(static_cast<unsigned char>(*it)))
return false; return false;
break; break;
case E: case State::E:
if (*it=='+' || *it=='-') if (*it=='+' || *it=='-')
state=MANTISSA_PLUSMINUS; state = State::MANTISSA_PLUSMINUS;
else if (std::isdigit(static_cast<unsigned char>(*it))) else if (std::isdigit(static_cast<unsigned char>(*it)))
state=MANTISSA_DIGITS; state = State::MANTISSA_DIGITS;
else else
return false; return false;
break; break;
case MANTISSA_PLUSMINUS: case State::MANTISSA_PLUSMINUS:
if (!std::isdigit(static_cast<unsigned char>(*it))) if (!std::isdigit(static_cast<unsigned char>(*it)))
return false; return false;
else else
state=MANTISSA_DIGITS; state = State::MANTISSA_DIGITS;
break; break;
case MANTISSA_DIGITS: case State::MANTISSA_DIGITS:
if (*it=='f' || *it=='F') if (*it=='f' || *it=='F')
state=SUFFIX_F; state = State::SUFFIX_F;
else if (*it=='l' || *it=='L') else if (*it=='l' || *it=='L')
state=SUFFIX_L; state = State::SUFFIX_L;
else if (!std::isdigit(static_cast<unsigned char>(*it))) else if (!std::isdigit(static_cast<unsigned char>(*it)))
return false; return false;
break; break;
case SUFFIX_F: case State::SUFFIX_F:
return false; return false;
case SUFFIX_L: case State::SUFFIX_L:
return false; return false;
} }
} }
return (state==BASE_DIGITS2 || state==MANTISSA_DIGITS || state==TRAILING_DECIMAL || state==SUFFIX_F || state==SUFFIX_L); return (state==State::BASE_DIGITS2 || state==State::MANTISSA_DIGITS || state==State::TRAILING_DECIMAL || state==State::SUFFIX_F || state==State::SUFFIX_L);
} }
bool MathLib::isNegative(const std::string &str) bool MathLib::isNegative(const std::string &str)
@ -842,9 +842,9 @@ bool MathLib::isValidIntegerSuffix(const std::string& str, bool supportMicrosoft
**/ **/
bool MathLib::isOct(const std::string& str) bool MathLib::isOct(const std::string& str)
{ {
enum Status { enum class Status {
START, OCTAL_PREFIX, DIGITS START, OCTAL_PREFIX, DIGITS
} state = START; } state = Status::START;
if (str.empty()) if (str.empty())
return false; return false;
std::string::const_iterator it = str.begin(); std::string::const_iterator it = str.begin();
@ -852,27 +852,27 @@ bool MathLib::isOct(const std::string& str)
++it; ++it;
for (; it != str.end(); ++it) { for (; it != str.end(); ++it) {
switch (state) { switch (state) {
case START: case Status::START:
if (*it == '0') if (*it == '0')
state = OCTAL_PREFIX; state = Status::OCTAL_PREFIX;
else else
return false; return false;
break; break;
case OCTAL_PREFIX: case Status::OCTAL_PREFIX:
if (isOctalDigit(static_cast<unsigned char>(*it))) if (isOctalDigit(static_cast<unsigned char>(*it)))
state = DIGITS; state = Status::DIGITS;
else else
return false; return false;
break; break;
case DIGITS: case Status::DIGITS:
if (isOctalDigit(static_cast<unsigned char>(*it))) if (isOctalDigit(static_cast<unsigned char>(*it)))
state = DIGITS; state = Status::DIGITS;
else else
return _isValidIntegerSuffix(it,str.end()); return _isValidIntegerSuffix(it,str.end());
break; break;
} }
} }
return state == DIGITS; return state == Status::DIGITS;
} }
bool MathLib::isIntHex(const std::string& str) bool MathLib::isIntHex(const std::string& str)