Fixed #6274 (MathLib::isFloat doesn't recognize long double literal suffix L or l)

This commit is contained in:
Robert Reif 2014-11-17 06:53:32 +01:00 committed by Daniel Marjamäki
parent 45ff012b2c
commit 7c4a137e14
2 changed files with 32 additions and 2 deletions

View File

@ -167,7 +167,7 @@ bool MathLib::isFloat(const std::string &s)
if (s.empty())
return false;
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, L
} state = START;
for (std::string::const_iterator it = s.begin(); it != s.end(); ++it) {
switch (state) {
@ -210,6 +210,10 @@ bool MathLib::isFloat(const std::string &s)
case TRAILING_DECIMAL:
if (*it=='e' || *it=='E')
state=E;
else if (*it=='f' || *it=='F')
state=F;
else if (*it=='l' || *it=='L')
state=L;
else if (std::isdigit(*it))
state=BASE_DIGITS2;
else
@ -220,6 +224,8 @@ bool MathLib::isFloat(const std::string &s)
state=E;
else if (*it=='f' || *it=='F')
state=F;
else if (*it=='l' || *it=='L')
state=L;
else if (!std::isdigit(*it))
return false;
break;
@ -240,14 +246,18 @@ bool MathLib::isFloat(const std::string &s)
case MANTISSA_DIGITS:
if (*it=='f' || *it=='F')
state=F;
else if (*it=='l' || *it=='L')
state=L;
else if (!std::isdigit(*it))
return false;
break;
case F:
return false;
case L:
return false;
}
}
return (state==BASE_DIGITS2 || state==MANTISSA_DIGITS || state==TRAILING_DECIMAL || state==F);
return (state==BASE_DIGITS2 || state==MANTISSA_DIGITS || state==TRAILING_DECIMAL || state==F || state==L);
}
bool MathLib::isNegative(const std::string &s)

View File

@ -552,6 +552,10 @@ private:
ASSERT_EQUALS(false, MathLib::isFloat(" 0"));
ASSERT_EQUALS(true , MathLib::isFloat("0."));
ASSERT_EQUALS(true , MathLib::isFloat("0.f"));
ASSERT_EQUALS(true , MathLib::isFloat("0.F"));
ASSERT_EQUALS(true , MathLib::isFloat("0.l"));
ASSERT_EQUALS(true , MathLib::isFloat("0.L"));
ASSERT_EQUALS(false , MathLib::isFloat("0. "));
ASSERT_EQUALS(false , MathLib::isFloat(" 0. "));
ASSERT_EQUALS(false , MathLib::isFloat(" 0."));
@ -560,6 +564,10 @@ private:
ASSERT_EQUALS(false , MathLib::isFloat("..0.."));
ASSERT_EQUALS(false , MathLib::isFloat("..0"));
ASSERT_EQUALS(true , MathLib::isFloat("0.0"));
ASSERT_EQUALS(true , MathLib::isFloat("0.0f"));
ASSERT_EQUALS(true , MathLib::isFloat("0.0F"));
ASSERT_EQUALS(true , MathLib::isFloat("0.0l"));
ASSERT_EQUALS(true , MathLib::isFloat("0.0L"));
ASSERT_EQUALS(true , MathLib::isFloat("-0."));
ASSERT_EQUALS(true , MathLib::isFloat("+0."));
ASSERT_EQUALS(true , MathLib::isFloat("-0.0"));
@ -583,8 +591,14 @@ private:
ASSERT_EQUALS(true , MathLib::isFloat("+1E+1"));
ASSERT_EQUALS(true , MathLib::isFloat("+1E+100"));
ASSERT_EQUALS(true , MathLib::isFloat("+1E+100f"));
ASSERT_EQUALS(true , MathLib::isFloat("+1E+100F"));
ASSERT_EQUALS(true , MathLib::isFloat("+1E+100l"));
ASSERT_EQUALS(true , MathLib::isFloat("+1E+100L"));
ASSERT_EQUALS(true , MathLib::isFloat("+1E+007")); // to be sure about #5485
ASSERT_EQUALS(true , MathLib::isFloat("+1E+001f"));
ASSERT_EQUALS(true , MathLib::isFloat("+1E+001F"));
ASSERT_EQUALS(true , MathLib::isFloat("+1E+001l"));
ASSERT_EQUALS(true , MathLib::isFloat("+1E+001L"));
ASSERT_EQUALS(false , MathLib::isFloat("+1E+001f2"));
ASSERT_EQUALS(true , MathLib::isFloat("+1E+10000"));
ASSERT_EQUALS(true , MathLib::isFloat("-1E+1"));
@ -597,8 +611,14 @@ private:
ASSERT_EQUALS(true , MathLib::isFloat("0.4"));
ASSERT_EQUALS(true , MathLib::isFloat("2352.3f"));
ASSERT_EQUALS(true , MathLib::isFloat("2352.3F"));
ASSERT_EQUALS(true , MathLib::isFloat("2352.3l"));
ASSERT_EQUALS(true , MathLib::isFloat("2352.3L"));
ASSERT_EQUALS(true , MathLib::isFloat("0.00004"));
ASSERT_EQUALS(true , MathLib::isFloat("2352.00001f"));
ASSERT_EQUALS(true , MathLib::isFloat("2352.00001F"));
ASSERT_EQUALS(true , MathLib::isFloat("2352.00001l"));
ASSERT_EQUALS(true , MathLib::isFloat("2352.00001L"));
ASSERT_EQUALS(true , MathLib::isFloat(".4"));
ASSERT_EQUALS(true , MathLib::isFloat(".3e2"));
ASSERT_EQUALS(true , MathLib::isFloat("1.0E+1"));