mathlib:isInt() now handles calles of 'u' and 'l' correctly; testcases added

This commit is contained in:
Martin Ettl 2010-05-12 23:49:09 +02:00
parent 963108d957
commit 1382832bd0
2 changed files with 19 additions and 1 deletions

View File

@ -184,9 +184,18 @@ bool MathLib::isInt(const std::string & s)
} }
else if (Mode == eDefault) 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 // unsigned or long
while (std::tolower(s[n]) == 'u' || std::tolower(s[n]) == 'l') ++n; while (std::tolower(s[n]) == 'u' || std::tolower(s[n]) == 'l') ++n;
if(bStartsWithDigit==false)
return false;
} }
// eat up whitespace // eat up whitespace
while (std::isspace(s[n])) while (std::isspace(s[n]))

View File

@ -213,6 +213,15 @@ private:
ASSERT_EQUALS(false, MathLib::isInt("+1.0E-1 ")); ASSERT_EQUALS(false, MathLib::isInt("+1.0E-1 "));
ASSERT_EQUALS(false, MathLib::isInt("-1.E+1 ")); ASSERT_EQUALS(false, MathLib::isInt("-1.E+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() void isnegative()