MathLib::characterLiteralToLongNumber now reports more specific error messages for unsupported unicode literals (see #7162)

This commit is contained in:
Alexander Mai 2015-11-22 07:38:38 +01:00
parent 714579401f
commit 517922feb6
2 changed files with 63 additions and 53 deletions

View File

@ -316,14 +316,21 @@ MathLib::biguint MathLib::toULongNumber(const std::string & str)
MathLib::bigint MathLib::characterLiteralToLongNumber(const std::string& str)
{
if (str.empty())
return 0; // for unit-testing...
if (str.size()==1)
return str[0] & 0xff;
if (str[0] != '\\')
throw InternalError(0, "Internal Error. MathLib::toLongNumber: Unhandled char constant " + str);
if (str[1]=='x') {
switch (str[1]) {
case 'x':
return toLongNumber("0x" + str.substr(2));
}
case 'u': // 16bit unicode character
throw InternalError(0, "Internal Error. MathLib::toLongNumber: Unhandled 16-bit unicode char constant " + str);
case 'U': // 16bit unicode character
throw InternalError(0, "Internal Error. MathLib::toLongNumber: Unhandled 32-bit unicode char constant " + str);
default: {
char c;
switch (str.size()-1) {
case 1:
@ -378,11 +385,12 @@ MathLib::bigint MathLib::characterLiteralToLongNumber(const std::string& str)
return toLongNumber("0" + str.substr(1));
break;
}
}
}
throw InternalError(0, "Internal Error. MathLib::toLongNumber: Unhandled char constant " + str);
}
MathLib::bigint MathLib::toLongNumber(const std::string & str)
{
// hexadecimal numbers:

View File

@ -282,6 +282,8 @@ private:
ASSERT_EQUALS((int)('\134'), MathLib::toLongNumber("'\\134'"));
ASSERT_THROW(MathLib::toLongNumber("'\\9'"), InternalError);
ASSERT_THROW(MathLib::toLongNumber("'\\934'"), InternalError);
ASSERT_THROW(MathLib::toLongNumber("'\\u9343'"), InternalError);
ASSERT_THROW(MathLib::toLongNumber("'\\U0001f34c'"), InternalError);
ASSERT_EQUALS(-8552249625308161526, MathLib::toLongNumber("0x89504e470d0a1a0a"));
ASSERT_EQUALS(-8481036456200365558, MathLib::toLongNumber("0x8a4d4e470d0a1a0a"));