Merge pull request #796 from simartin/ticket_7452_follow_up

Address comments in PR#794 and alternative fix for ticket #7500.
This commit is contained in:
amai2012 2016-05-21 09:20:23 +02:00
commit b60b283c5b
1 changed files with 6 additions and 6 deletions

View File

@ -356,8 +356,6 @@ MathLib::bigint MathLib::characterLiteralToLongNumber(const std::string& str)
// is implementation-defined. // is implementation-defined.
// clang and gcc seem to use the following encoding: 'AB' as (('A' << 8) | 'B') // clang and gcc seem to use the following encoding: 'AB' as (('A' << 8) | 'B')
const std::string& normStr = normalizeCharacterLiteral(str); const std::string& normStr = normalizeCharacterLiteral(str);
if (normStr.empty())
throw InternalError(0, "Internal Error. MathLib::characterLiteralToLongNumber: Unhandled char constant '" + str + "'.");
return encodeMultiChar(normStr); return encodeMultiChar(normStr);
} }
@ -372,14 +370,14 @@ std::string MathLib::normalizeCharacterLiteral(const std::string& iLiteral)
} }
++idx; ++idx;
if (idx == iLiteralLen) { if (idx == iLiteralLen) {
throw InternalError(0, "Internal Error. MathLib::toLongNumber: Unhandled char constant '" + iLiteral + "'."); throw InternalError(0, "Internal Error. MathLib::normalizeCharacterLiteral: Unhandled char constant '" + iLiteral + "'.");
} }
switch (iLiteral[idx]) { switch (iLiteral[idx]) {
case 'x': case 'x':
// Hexa-decimal number: skip \x and interpret the next two characters // Hexa-decimal number: skip \x and interpret the next two characters
{ {
if (++idx == iLiteralLen) if (++idx == iLiteralLen)
throw InternalError(0, "Internal Error. MathLib::toLongNumber: Unhandled char constant '" + iLiteral + "'."); throw InternalError(0, "Internal Error. MathLib::normalizeCharacterLiteral: Unhandled char constant '" + iLiteral + "'.");
std::string tempBuf; std::string tempBuf;
tempBuf.push_back(iLiteral[idx]); tempBuf.push_back(iLiteral[idx]);
if (++idx != iLiteralLen) if (++idx != iLiteralLen)
@ -390,6 +388,8 @@ std::string MathLib::normalizeCharacterLiteral(const std::string& iLiteral)
case 'u': case 'u':
case 'U': case 'U':
// Unicode string; just skip the \u or \U // Unicode string; just skip the \u or \U
if (idx + 1 == iLiteralLen)
throw InternalError(0, "Internal Error. MathLib::characterLiteralToLongNumber: Unhandled char constant '" + iLiteral + "'.");
continue; continue;
} }
// Single digit octal number // Single digit octal number
@ -436,13 +436,13 @@ std::string MathLib::normalizeCharacterLiteral(const std::string& iLiteral)
normalizedLiteral.push_back(iLiteral[idx]); normalizedLiteral.push_back(iLiteral[idx]);
break; break;
default: default:
throw InternalError(0, "Internal Error. MathLib::toLongNumber: Unhandled char constant '" + iLiteral + "'."); throw InternalError(0, "Internal Error. MathLib::normalizeCharacterLiteral: Unhandled char constant '" + iLiteral + "'.");
} }
continue; continue;
} }
// 2-3 digit octal number // 2-3 digit octal number
if (!MathLib::isOctalDigit(iLiteral[idx])) if (!MathLib::isOctalDigit(iLiteral[idx]))
throw InternalError(0, "Internal Error. MathLib::toLongNumber: Unhandled char constant '" + iLiteral + "'."); throw InternalError(0, "Internal Error. MathLib::normalizeCharacterLiteral: Unhandled char constant '" + iLiteral + "'.");
std::string tempBuf; std::string tempBuf;
tempBuf.push_back(iLiteral[idx]); tempBuf.push_back(iLiteral[idx]);
++idx; ++idx;