MathLib: fix for octal char literal '\200'
This commit is contained in:
parent
5175bf88d6
commit
90ed7634b8
|
@ -346,6 +346,10 @@ static unsigned int encodeMultiChar(const std::string& str)
|
|||
return retval;
|
||||
}
|
||||
|
||||
static bool isoctal(int c) {
|
||||
return c>='0' && c<='7';
|
||||
}
|
||||
|
||||
MathLib::bigint MathLib::characterLiteralToLongNumber(const std::string& str)
|
||||
{
|
||||
if (str.empty())
|
||||
|
@ -356,6 +360,11 @@ MathLib::bigint MathLib::characterLiteralToLongNumber(const std::string& str)
|
|||
return std::strtoul(str.substr(2).c_str(), NULL, 16);
|
||||
}
|
||||
|
||||
// '\123'
|
||||
if (str.size() == 4 && str[0] == '\\' && isoctal(str[1]) && isoctal(str[2]) && isoctal(str[3])) {
|
||||
return (char)std::strtoul(str.substr(1).c_str(), NULL, 8);
|
||||
}
|
||||
|
||||
// C99 6.4.4.4
|
||||
// The value of an integer character constant containing more than one character (e.g., 'ab'),
|
||||
// or containing a character or escape sequence that does not map to a single-byte execution character,
|
||||
|
|
|
@ -275,6 +275,9 @@ private:
|
|||
|
||||
// from char
|
||||
ASSERT_EQUALS((int)('A'), MathLib::toLongNumber("'A'"));
|
||||
ASSERT_EQUALS((int)('\x10'), MathLib::toLongNumber("'\\x10'"));
|
||||
ASSERT_EQUALS((int)('\100'), MathLib::toLongNumber("'\\100'"));
|
||||
ASSERT_EQUALS((int)('\200'), MathLib::toLongNumber("'\\200'"));
|
||||
#ifdef __GNUC__
|
||||
// BEGIN Implementation-specific results
|
||||
ASSERT_EQUALS((int)('AB'), MathLib::toLongNumber("'AB'"));
|
||||
|
|
Loading…
Reference in New Issue