Improve handling of various standard character constants

This commit is contained in:
Daniel Marjamäki 2015-11-20 10:23:38 +01:00
parent 86957214ae
commit 52b5446d86
1 changed files with 36 additions and 9 deletions

View File

@ -367,15 +367,42 @@ MathLib::bigint MathLib::toLongNumber(const std::string & str)
char c;
if (str.size() == 3U)
c = str[1];
else if (str == "\'\\0\'")
else if (str[1] == '\\' && str.size() == 4U) {
switch (str[2]) {
case '0':
c = '\0';
else if (str == "\'\\n\'")
break;
case 'a':
c = '\a';
break;
case 'b':
c = '\b';
break;
case 'f':
c = '\f';
break;
case 'n':
c = '\n';
else if (str == "\'\\r\'")
break;
case 'r':
c = '\r';
else if (str == "\'\\t\'")
break;
case 't':
c = '\t';
else
break;
case 'v':
c = '\v';
break;
case '\\':
case '\?':
case '\'':
case '\"':
c = str[2];
break;
default:
throw InternalError(0, "MathLib::toLongNumber: Unhandled char constant " + str);
}
} else
throw InternalError(0, "MathLib::toLongNumber: Unhandled char constant " + str);
return c & 0xff;
}