Partially reverted 1317063b21
. enum class is not part of the common subset of supported C++11 functions of the compilers supported by cppcheck. (Fixes #5745)
This commit is contained in:
parent
71264fb672
commit
ab4f58a146
200
lib/mathlib.cpp
200
lib/mathlib.cpp
|
@ -152,88 +152,88 @@ bool MathLib::isFloat(const std::string &s)
|
||||||
{
|
{
|
||||||
if (s.empty())
|
if (s.empty())
|
||||||
return false;
|
return false;
|
||||||
enum class State {
|
enum State {
|
||||||
START, BASE_PLUSMINUS, BASE_DIGITS1, LEADING_DECIMAL, TRAILING_DECIMAL, BASE_DIGITS2, E, MANTISSA_PLUSMINUS, MANTISSA_DIGITS, F
|
START, BASE_PLUSMINUS, BASE_DIGITS1, LEADING_DECIMAL, TRAILING_DECIMAL, BASE_DIGITS2, E, MANTISSA_PLUSMINUS, MANTISSA_DIGITS, F
|
||||||
} state = State::START;
|
} state = START;
|
||||||
for (std::string::const_iterator it = s.begin(); it != s.end(); ++it) {
|
for (std::string::const_iterator it = s.begin(); it != s.end(); ++it) {
|
||||||
switch (state) {
|
switch (state) {
|
||||||
case State::START:
|
case START:
|
||||||
if (*it=='+' || *it=='-')
|
if (*it=='+' || *it=='-')
|
||||||
state=State::BASE_PLUSMINUS;
|
state=BASE_PLUSMINUS;
|
||||||
else if (*it=='.')
|
else if (*it=='.')
|
||||||
state=State::LEADING_DECIMAL;
|
state=LEADING_DECIMAL;
|
||||||
else if (std::isdigit(*it))
|
else if (std::isdigit(*it))
|
||||||
state=State::BASE_DIGITS1;
|
state=BASE_DIGITS1;
|
||||||
else
|
else
|
||||||
return false;
|
return false;
|
||||||
break;
|
break;
|
||||||
case State::BASE_PLUSMINUS:
|
case BASE_PLUSMINUS:
|
||||||
if (*it=='.')
|
if (*it=='.')
|
||||||
state=State::LEADING_DECIMAL;
|
state=LEADING_DECIMAL;
|
||||||
else if (std::isdigit(*it))
|
else if (std::isdigit(*it))
|
||||||
state=State::BASE_DIGITS1;
|
state=BASE_DIGITS1;
|
||||||
else if (*it=='e' || *it=='E')
|
else if (*it=='e' || *it=='E')
|
||||||
state=State::E;
|
state=E;
|
||||||
else
|
else
|
||||||
return false;
|
return false;
|
||||||
break;
|
break;
|
||||||
case State::LEADING_DECIMAL:
|
case LEADING_DECIMAL:
|
||||||
if (std::isdigit(*it))
|
if (std::isdigit(*it))
|
||||||
state=State::BASE_DIGITS2;
|
state=BASE_DIGITS2;
|
||||||
else if (*it=='e' || *it=='E')
|
else if (*it=='e' || *it=='E')
|
||||||
state=State::E;
|
state=E;
|
||||||
else
|
else
|
||||||
return false;
|
return false;
|
||||||
break;
|
break;
|
||||||
case State::BASE_DIGITS1:
|
case BASE_DIGITS1:
|
||||||
if (*it=='e' || *it=='E')
|
if (*it=='e' || *it=='E')
|
||||||
state=State::E;
|
state=E;
|
||||||
else if (*it=='.')
|
else if (*it=='.')
|
||||||
state=State::TRAILING_DECIMAL;
|
state=TRAILING_DECIMAL;
|
||||||
else if (!std::isdigit(*it))
|
else if (!std::isdigit(*it))
|
||||||
return false;
|
return false;
|
||||||
break;
|
break;
|
||||||
case State::TRAILING_DECIMAL:
|
case TRAILING_DECIMAL:
|
||||||
if (*it=='e' || *it=='E')
|
if (*it=='e' || *it=='E')
|
||||||
state=State::E;
|
state=E;
|
||||||
else if (std::isdigit(*it))
|
else if (std::isdigit(*it))
|
||||||
state=State::BASE_DIGITS2;
|
state=BASE_DIGITS2;
|
||||||
else
|
else
|
||||||
return false;
|
return false;
|
||||||
break;
|
break;
|
||||||
case State::BASE_DIGITS2:
|
case BASE_DIGITS2:
|
||||||
if (*it=='e' || *it=='E')
|
if (*it=='e' || *it=='E')
|
||||||
state=State::E;
|
state=E;
|
||||||
else if (*it=='f' || *it=='F')
|
else if (*it=='f' || *it=='F')
|
||||||
state=State::F;
|
state=F;
|
||||||
else if (!std::isdigit(*it))
|
else if (!std::isdigit(*it))
|
||||||
return false;
|
return false;
|
||||||
break;
|
break;
|
||||||
case State::E:
|
case E:
|
||||||
if (*it=='+' || *it=='-')
|
if (*it=='+' || *it=='-')
|
||||||
state=State::MANTISSA_PLUSMINUS;
|
state=MANTISSA_PLUSMINUS;
|
||||||
else if (std::isdigit(*it))
|
else if (std::isdigit(*it))
|
||||||
state=State::MANTISSA_DIGITS;
|
state=MANTISSA_DIGITS;
|
||||||
else
|
else
|
||||||
return false;
|
return false;
|
||||||
break;
|
break;
|
||||||
case State::MANTISSA_PLUSMINUS:
|
case MANTISSA_PLUSMINUS:
|
||||||
if (!std::isdigit(*it))
|
if (!std::isdigit(*it))
|
||||||
return false;
|
return false;
|
||||||
else
|
else
|
||||||
state=State::MANTISSA_DIGITS;
|
state=MANTISSA_DIGITS;
|
||||||
break;
|
break;
|
||||||
case State::MANTISSA_DIGITS:
|
case MANTISSA_DIGITS:
|
||||||
if (*it=='f' || *it=='F')
|
if (*it=='f' || *it=='F')
|
||||||
state=State::F;
|
state=F;
|
||||||
else if (!std::isdigit(*it))
|
else if (!std::isdigit(*it))
|
||||||
return false;
|
return false;
|
||||||
break;
|
break;
|
||||||
case State::F:
|
case F:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return (state==State::BASE_DIGITS2 || state==State::MANTISSA_DIGITS || state==State::TRAILING_DECIMAL || state==State::F);
|
return (state==BASE_DIGITS2 || state==MANTISSA_DIGITS || state==TRAILING_DECIMAL || state==F);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MathLib::isNegative(const std::string &s)
|
bool MathLib::isNegative(const std::string &s)
|
||||||
|
@ -262,126 +262,126 @@ bool MathLib::isPositive(const std::string &s)
|
||||||
**/
|
**/
|
||||||
bool MathLib::isOct(const std::string& s)
|
bool MathLib::isOct(const std::string& s)
|
||||||
{
|
{
|
||||||
enum class Status {
|
enum Status {
|
||||||
START, PLUSMINUS, OCTAL_PREFIX, DIGITS
|
START, PLUSMINUS, OCTAL_PREFIX, DIGITS
|
||||||
} state = Status::START;
|
} state = START;
|
||||||
for (std::string::const_iterator it = s.begin(); it != s.end(); ++it) {
|
for (std::string::const_iterator it = s.begin(); it != s.end(); ++it) {
|
||||||
switch (state) {
|
switch (state) {
|
||||||
case Status::START:
|
case START:
|
||||||
if (*it == '+' || *it == '-')
|
if (*it == '+' || *it == '-')
|
||||||
state = Status::PLUSMINUS;
|
state = PLUSMINUS;
|
||||||
else if (*it == '0')
|
else if (*it == '0')
|
||||||
state = Status::OCTAL_PREFIX;
|
state = OCTAL_PREFIX;
|
||||||
else
|
else
|
||||||
return false;
|
return false;
|
||||||
break;
|
break;
|
||||||
case Status::PLUSMINUS:
|
case PLUSMINUS:
|
||||||
if (*it == '0')
|
if (*it == '0')
|
||||||
state =Status:: OCTAL_PREFIX;
|
state = OCTAL_PREFIX;
|
||||||
else
|
else
|
||||||
return false;
|
return false;
|
||||||
break;
|
break;
|
||||||
case Status::OCTAL_PREFIX:
|
case OCTAL_PREFIX:
|
||||||
if (isOctalDigit(*it))
|
if (isOctalDigit(*it))
|
||||||
state = Status::DIGITS;
|
state = DIGITS;
|
||||||
else
|
else
|
||||||
return false;
|
return false;
|
||||||
break;
|
break;
|
||||||
case Status::DIGITS:
|
case DIGITS:
|
||||||
if (isOctalDigit(*it))
|
if (isOctalDigit(*it))
|
||||||
state = Status::DIGITS;
|
state = DIGITS;
|
||||||
else
|
else
|
||||||
return isValidSuffix(it,s.end());
|
return isValidSuffix(it,s.end());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return state == Status::DIGITS;
|
return state == DIGITS;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MathLib::isHex(const std::string& s)
|
bool MathLib::isHex(const std::string& s)
|
||||||
{
|
{
|
||||||
enum class Status {
|
enum Status {
|
||||||
START, PLUSMINUS, HEX_PREFIX, DIGIT, DIGITS
|
START, PLUSMINUS, HEX_PREFIX, DIGIT, DIGITS
|
||||||
} state = Status::START;
|
} state = START;
|
||||||
for (std::string::const_iterator it = s.begin(); it != s.end(); ++it) {
|
for (std::string::const_iterator it = s.begin(); it != s.end(); ++it) {
|
||||||
switch (state) {
|
switch (state) {
|
||||||
case Status::START:
|
case START:
|
||||||
if (*it == '+' || *it == '-')
|
if (*it == '+' || *it == '-')
|
||||||
state = Status::PLUSMINUS;
|
state = PLUSMINUS;
|
||||||
else if (*it == '0')
|
else if (*it == '0')
|
||||||
state = Status::HEX_PREFIX;
|
state = HEX_PREFIX;
|
||||||
else
|
else
|
||||||
return false;
|
return false;
|
||||||
break;
|
break;
|
||||||
case Status::PLUSMINUS:
|
case PLUSMINUS:
|
||||||
if (*it == '0')
|
if (*it == '0')
|
||||||
state = Status::HEX_PREFIX;
|
state = HEX_PREFIX;
|
||||||
else
|
else
|
||||||
return false;
|
return false;
|
||||||
break;
|
break;
|
||||||
case Status::HEX_PREFIX:
|
case HEX_PREFIX:
|
||||||
if (*it == 'x' || *it == 'X')
|
if (*it == 'x' || *it == 'X')
|
||||||
state = Status::DIGIT;
|
state = DIGIT;
|
||||||
else
|
else
|
||||||
return false;
|
return false;
|
||||||
break;
|
break;
|
||||||
case Status::DIGIT:
|
case DIGIT:
|
||||||
if (isxdigit(*it))
|
if (isxdigit(*it))
|
||||||
state = Status::DIGITS;
|
state = DIGITS;
|
||||||
else
|
else
|
||||||
return false;
|
return false;
|
||||||
break;
|
break;
|
||||||
case Status::DIGITS:
|
case DIGITS:
|
||||||
if (isxdigit(*it))
|
if (isxdigit(*it))
|
||||||
state = Status::DIGITS;
|
state = DIGITS;
|
||||||
else
|
else
|
||||||
return isValidSuffix(it,s.end());
|
return isValidSuffix(it,s.end());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return state == Status::DIGITS;
|
return state == DIGITS;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MathLib::isValidSuffix(std::string::const_iterator it, std::string::const_iterator end)
|
bool MathLib::isValidSuffix(std::string::const_iterator it, std::string::const_iterator end)
|
||||||
{
|
{
|
||||||
enum class Status {
|
enum Status {
|
||||||
START, SUFFIX_U, SUFFIX_UL, SUFFIX_ULL, SUFFIX_L, SUFFIX_LU, SUFFIX_LL, SUFFIX_LLU
|
START, SUFFIX_U, SUFFIX_UL, SUFFIX_ULL, SUFFIX_L, SUFFIX_LU, SUFFIX_LL, SUFFIX_LLU
|
||||||
} state = Status::START;
|
} state = START;
|
||||||
for (; it != end; ++it) {
|
for (; it != end; ++it) {
|
||||||
switch (state) {
|
switch (state) {
|
||||||
case Status::START:
|
case START:
|
||||||
if (*it == 'u' || *it == 'U')
|
if (*it == 'u' || *it == 'U')
|
||||||
state = Status::SUFFIX_U;
|
state = SUFFIX_U;
|
||||||
else if (*it == 'l' || *it == 'L')
|
else if (*it == 'l' || *it == 'L')
|
||||||
state = Status::SUFFIX_L;
|
state = SUFFIX_L;
|
||||||
else
|
else
|
||||||
return false;
|
return false;
|
||||||
break;
|
break;
|
||||||
case Status::SUFFIX_U:
|
case SUFFIX_U:
|
||||||
if (*it == 'l' || *it == 'L')
|
if (*it == 'l' || *it == 'L')
|
||||||
state = Status::SUFFIX_UL; // UL
|
state = SUFFIX_UL; // UL
|
||||||
else
|
else
|
||||||
return false;
|
return false;
|
||||||
break;
|
break;
|
||||||
case Status::SUFFIX_UL:
|
case SUFFIX_UL:
|
||||||
if (*it == 'l' || *it == 'L')
|
if (*it == 'l' || *it == 'L')
|
||||||
state = Status::SUFFIX_ULL; // ULL
|
state = SUFFIX_ULL; // ULL
|
||||||
else
|
else
|
||||||
return false;
|
return false;
|
||||||
break;
|
break;
|
||||||
case Status::SUFFIX_L:
|
case SUFFIX_L:
|
||||||
if (*it == 'u' || *it == 'U')
|
if (*it == 'u' || *it == 'U')
|
||||||
state = Status::SUFFIX_LU; // LU
|
state = SUFFIX_LU; // LU
|
||||||
else if (*it == 'l' || *it == 'L')
|
else if (*it == 'l' || *it == 'L')
|
||||||
state = Status::SUFFIX_LL; // LL
|
state = SUFFIX_LL; // LL
|
||||||
else
|
else
|
||||||
return false;
|
return false;
|
||||||
break;
|
break;
|
||||||
case Status::SUFFIX_LU:
|
case SUFFIX_LU:
|
||||||
return false;
|
return false;
|
||||||
case Status::SUFFIX_LL:
|
case SUFFIX_LL:
|
||||||
if (*it == 'u' || *it == 'U')
|
if (*it == 'u' || *it == 'U')
|
||||||
state = Status::SUFFIX_LLU; // LLU
|
state = SUFFIX_LLU; // LLU
|
||||||
else
|
else
|
||||||
return false;
|
return false;
|
||||||
break;
|
break;
|
||||||
|
@ -389,9 +389,9 @@ bool MathLib::isValidSuffix(std::string::const_iterator it, std::string::const_i
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return (state == Status::SUFFIX_U) || (state == Status::SUFFIX_L)
|
return (state == SUFFIX_U) || (state == SUFFIX_L)
|
||||||
|| (state == Status::SUFFIX_UL) || (state == Status::SUFFIX_LU) || (state == Status::SUFFIX_LL)
|
|| (state == SUFFIX_UL) || (state == SUFFIX_LU) || (state == SUFFIX_LL)
|
||||||
|| (state == Status::SUFFIX_ULL) || (state == Status::SUFFIX_LLU);
|
|| (state == SUFFIX_ULL) || (state == SUFFIX_LLU);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*! \brief Does the string represent a binary number?
|
/*! \brief Does the string represent a binary number?
|
||||||
|
@ -405,80 +405,80 @@ bool MathLib::isValidSuffix(std::string::const_iterator it, std::string::const_i
|
||||||
**/
|
**/
|
||||||
bool MathLib::isBin(const std::string& s)
|
bool MathLib::isBin(const std::string& s)
|
||||||
{
|
{
|
||||||
enum class Status {
|
enum Status {
|
||||||
START, PLUSMINUS, GNU_BIN_PREFIX, DIGIT, DIGITS
|
START, PLUSMINUS, GNU_BIN_PREFIX, DIGIT, DIGITS
|
||||||
} state = Status::START;
|
} state = START;
|
||||||
for (std::string::const_iterator it = s.begin(); it != s.end(); ++it) {
|
for (std::string::const_iterator it = s.begin(); it != s.end(); ++it) {
|
||||||
switch (state) {
|
switch (state) {
|
||||||
case Status::START:
|
case START:
|
||||||
if (*it == '+' || *it == '-')
|
if (*it == '+' || *it == '-')
|
||||||
state = Status::PLUSMINUS;
|
state = PLUSMINUS;
|
||||||
else if (*it == '0')
|
else if (*it == '0')
|
||||||
state = Status::GNU_BIN_PREFIX;
|
state = GNU_BIN_PREFIX;
|
||||||
else
|
else
|
||||||
return false;
|
return false;
|
||||||
break;
|
break;
|
||||||
case Status::PLUSMINUS:
|
case PLUSMINUS:
|
||||||
if (*it == '0')
|
if (*it == '0')
|
||||||
state = Status::GNU_BIN_PREFIX;
|
state = GNU_BIN_PREFIX;
|
||||||
else
|
else
|
||||||
return false;
|
return false;
|
||||||
break;
|
break;
|
||||||
case Status::GNU_BIN_PREFIX:
|
case GNU_BIN_PREFIX:
|
||||||
if (*it == 'b' || *it == 'B')
|
if (*it == 'b' || *it == 'B')
|
||||||
state = Status::DIGIT;
|
state = DIGIT;
|
||||||
else
|
else
|
||||||
return false;
|
return false;
|
||||||
break;
|
break;
|
||||||
case Status::DIGIT:
|
case DIGIT:
|
||||||
if (*it == '0' || *it == '1')
|
if (*it == '0' || *it == '1')
|
||||||
state = Status::DIGITS;
|
state = DIGITS;
|
||||||
else
|
else
|
||||||
return false;
|
return false;
|
||||||
break;
|
break;
|
||||||
case Status::DIGITS:
|
case DIGITS:
|
||||||
if (*it == '0' || *it == '1')
|
if (*it == '0' || *it == '1')
|
||||||
state = Status::DIGITS;
|
state = DIGITS;
|
||||||
else
|
else
|
||||||
return isValidSuffix(it,s.end());
|
return isValidSuffix(it,s.end());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return state == Status::DIGITS;
|
return state == DIGITS;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MathLib::isDec(const std::string & s)
|
bool MathLib::isDec(const std::string & s)
|
||||||
{
|
{
|
||||||
enum class Status {
|
enum Status {
|
||||||
START, PLUSMINUS, DIGIT, SUFFIX
|
START, PLUSMINUS, DIGIT, SUFFIX
|
||||||
} state = Status::START;
|
} state = START;
|
||||||
for (std::string::const_iterator it = s.begin(); it != s.end(); ++it) {
|
for (std::string::const_iterator it = s.begin(); it != s.end(); ++it) {
|
||||||
switch (state) {
|
switch (state) {
|
||||||
case Status::START:
|
case START:
|
||||||
if (*it == '+' || *it == '-')
|
if (*it == '+' || *it == '-')
|
||||||
state = Status::PLUSMINUS;
|
state = PLUSMINUS;
|
||||||
else if (isdigit(*it))
|
else if (isdigit(*it))
|
||||||
state = Status::DIGIT;
|
state = DIGIT;
|
||||||
else
|
else
|
||||||
return false;
|
return false;
|
||||||
break;
|
break;
|
||||||
case Status::PLUSMINUS:
|
case PLUSMINUS:
|
||||||
if (isdigit(*it))
|
if (isdigit(*it))
|
||||||
state = Status::DIGIT;
|
state = DIGIT;
|
||||||
else
|
else
|
||||||
return false;
|
return false;
|
||||||
break;
|
break;
|
||||||
case Status::DIGIT:
|
case DIGIT:
|
||||||
if (isdigit(*it))
|
if (isdigit(*it))
|
||||||
state = Status::DIGIT;
|
state = DIGIT;
|
||||||
else
|
else
|
||||||
return isValidSuffix(it,s.end());
|
return isValidSuffix(it,s.end());
|
||||||
break;
|
break;
|
||||||
case Status::SUFFIX:
|
case SUFFIX:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return state == Status::DIGIT;
|
return state == DIGIT;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MathLib::isInt(const std::string & s)
|
bool MathLib::isInt(const std::string & s)
|
||||||
|
|
Loading…
Reference in New Issue