mathlib:isInt() now handles calles of 'u' and 'l' correctly; testcases added
This commit is contained in:
parent
963108d957
commit
1382832bd0
|
@ -184,9 +184,18 @@ bool MathLib::isInt(const std::string & s)
|
|||
}
|
||||
else if (Mode == eDefault)
|
||||
{
|
||||
while (std::isdigit(s[n])) ++n;
|
||||
// starts with digit
|
||||
bool bStartsWithDigit=false;
|
||||
while (std::isdigit(s[n]))
|
||||
{
|
||||
bStartsWithDigit=true;
|
||||
++n;
|
||||
};
|
||||
// unsigned or long
|
||||
while (std::tolower(s[n]) == 'u' || std::tolower(s[n]) == 'l') ++n;
|
||||
|
||||
if(bStartsWithDigit==false)
|
||||
return false;
|
||||
}
|
||||
// eat up whitespace
|
||||
while (std::isspace(s[n]))
|
||||
|
|
|
@ -213,6 +213,15 @@ private:
|
|||
ASSERT_EQUALS(false, MathLib::isInt("+1.0E-1 "));
|
||||
ASSERT_EQUALS(false, MathLib::isInt("-1.E+1 "));
|
||||
ASSERT_EQUALS(false, MathLib::isInt("+1.E-1 "));
|
||||
// test some garbage
|
||||
ASSERT_EQUALS(false, MathLib::isInt("u"));
|
||||
ASSERT_EQUALS(false, MathLib::isInt("l"));
|
||||
ASSERT_EQUALS(false, MathLib::isInt("ul"));
|
||||
ASSERT_EQUALS(false, MathLib::isInt("ll"));
|
||||
ASSERT_EQUALS(false, MathLib::isInt("U"));
|
||||
ASSERT_EQUALS(false, MathLib::isInt("L"));
|
||||
ASSERT_EQUALS(false, MathLib::isInt("uL"));
|
||||
ASSERT_EQUALS(false, MathLib::isInt("LL"));
|
||||
}
|
||||
|
||||
void isnegative()
|
||||
|
|
Loading…
Reference in New Issue