MathLib::characterLiteralToLongNumber now reports more specific error messages for unsupported unicode literals (see #7162)
This commit is contained in:
parent
714579401f
commit
517922feb6
|
@ -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:
|
||||
|
|
|
@ -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"));
|
||||
|
|
Loading…
Reference in New Issue