Fixed #6281: MathLib: Long integer suffix i64 is not supported.

This commit is contained in:
orbitcowboy 2014-11-20 10:23:09 +01:00
parent f5d804f71a
commit 4a2a4474c9
2 changed files with 96 additions and 6 deletions

View File

@ -368,9 +368,7 @@ bool MathLib::isHex(const std::string& s)
bool MathLib::isValidSuffix(std::string::const_iterator it, std::string::const_iterator end)
{
enum Status {
START, SUFFIX_U, SUFFIX_UL, SUFFIX_ULL, SUFFIX_L, SUFFIX_LU, SUFFIX_LL, SUFFIX_LLU
} state = START;
enum {START, SUFFIX_U, SUFFIX_UL, SUFFIX_ULL, SUFFIX_L, SUFFIX_LU, SUFFIX_LL, SUFFIX_LLU, SUFFIX_I, SUFFIX_I6, SUFFIX_I64} state = START;
for (; it != end; ++it) {
switch (state) {
case START:
@ -378,6 +376,8 @@ bool MathLib::isValidSuffix(std::string::const_iterator it, std::string::const_i
state = SUFFIX_U;
else if (*it == 'l' || *it == 'L')
state = SUFFIX_L;
else if (*it == 'i')
state = SUFFIX_I;
else
return false;
break;
@ -409,13 +409,31 @@ bool MathLib::isValidSuffix(std::string::const_iterator it, std::string::const_i
else
return false;
break;
case SUFFIX_I:
if (*it == '6')
state = SUFFIX_I6;
else
return false;
break;
case SUFFIX_I6:
if (*it == '4')
state = SUFFIX_I64;
else
return false;
break;
default:
return false;
break;
}
}
return (state == SUFFIX_U) || (state == SUFFIX_L)
|| (state == SUFFIX_UL) || (state == SUFFIX_LU) || (state == SUFFIX_LL)
|| (state == SUFFIX_ULL) || (state == SUFFIX_LLU);
return ((state == SUFFIX_U) ||
(state == SUFFIX_L) ||
(state == SUFFIX_UL) ||
(state == SUFFIX_LU) ||
(state == SUFFIX_LL) ||
(state == SUFFIX_ULL) ||
(state == SUFFIX_LLU) ||
(state == SUFFIX_I64));
}
/*! \brief Does the string represent a binary number?

View File

@ -36,6 +36,7 @@ private:
TEST_CASE(isdec);
TEST_CASE(isoct);
TEST_CASE(ishex);
TEST_CASE(isValidSuffix);
TEST_CASE(isnegative);
TEST_CASE(ispositive);
TEST_CASE(isfloat);
@ -533,6 +534,77 @@ private:
ASSERT_EQUALS(false, MathLib::isHex(""));
}
void isValidSuffix(void)
{
// negative testing
std::string value = "ux";
ASSERT_EQUALS(false, MathLib::isValidSuffix(value.begin(), value.end()));
value = "ulx";
ASSERT_EQUALS(false, MathLib::isValidSuffix(value.begin(), value.end()));
value = "lx";
ASSERT_EQUALS(false, MathLib::isValidSuffix(value.begin(), value.end()));
value = "lux";
ASSERT_EQUALS(false, MathLib::isValidSuffix(value.begin(), value.end()));
value = "lll";
ASSERT_EQUALS(false, MathLib::isValidSuffix(value.begin(), value.end()));
value = "garbage";
ASSERT_EQUALS(false, MathLib::isValidSuffix(value.begin(), value.end()));
value = "";
ASSERT_EQUALS(false, MathLib::isValidSuffix(value.begin(), value.end()));
value = "llu ";
ASSERT_EQUALS(false, MathLib::isValidSuffix(value.begin(), value.end()));
value = "i";
ASSERT_EQUALS(false, MathLib::isValidSuffix(value.begin(), value.end()));
value = "iX";
ASSERT_EQUALS(false, MathLib::isValidSuffix(value.begin(), value.end()));
value = "i6X";
ASSERT_EQUALS(false, MathLib::isValidSuffix(value.begin(), value.end()));
value = "i64X";
ASSERT_EQUALS(false, MathLib::isValidSuffix(value.begin(), value.end()));
value = "i64 ";
ASSERT_EQUALS(false, MathLib::isValidSuffix(value.begin(), value.end()));
value = "i66";
ASSERT_EQUALS(false, MathLib::isValidSuffix(value.begin(), value.end()));
// positive testing
value = "u";
ASSERT_EQUALS(true, MathLib::isValidSuffix(value.begin(), value.end()));
value = "ul";
ASSERT_EQUALS(true, MathLib::isValidSuffix(value.begin(), value.end()));
value = "ull";
ASSERT_EQUALS(true, MathLib::isValidSuffix(value.begin(), value.end()));
value = "l";
ASSERT_EQUALS(true, MathLib::isValidSuffix(value.begin(), value.end()));
value = "lu";
ASSERT_EQUALS(true, MathLib::isValidSuffix(value.begin(), value.end()));
value = "ll";
ASSERT_EQUALS(true, MathLib::isValidSuffix(value.begin(), value.end()));
value = "llu";
ASSERT_EQUALS(true, MathLib::isValidSuffix(value.begin(), value.end()));
value = "i64";
ASSERT_EQUALS(true, MathLib::isValidSuffix(value.begin(), value.end()));
}
void ispositive() const
{
ASSERT_EQUALS(false, MathLib::isPositive("-1"));