This commit is contained in:
blueloveTH 2023-06-15 22:07:16 +08:00
parent 58adfe6d17
commit 9ea76aee85
2 changed files with 15 additions and 1 deletions

View File

@ -323,6 +323,18 @@ struct Lexer {
case 'n': buff.push_back('\n'); break; case 'n': buff.push_back('\n'); break;
case 'r': buff.push_back('\r'); break; case 'r': buff.push_back('\r'); break;
case 't': buff.push_back('\t'); break; case 't': buff.push_back('\t'); break;
case 'x': {
char hex[3] = {eatchar(), eatchar(), '\0'};
size_t parsed;
char code;
try{
code = (char)Number::stoi(hex, &parsed, 16);
}catch(std::invalid_argument&){
SyntaxError("invalid hex char");
}
if (parsed != 2) SyntaxError("invalid hex char");
buff.push_back(code);
} break;
default: SyntaxError("invalid escape char"); default: SyntaxError("invalid escape char");
} }
} else { } else {

View File

@ -106,4 +106,6 @@ a = '123'
assert a.rjust(5) == ' 123' assert a.rjust(5) == ' 123'
assert a.rjust(5, '0') == '00123' assert a.rjust(5, '0') == '00123'
assert a.ljust(5) == '123 ' assert a.ljust(5) == '123 '
assert a.ljust(5, '0') == '12300' assert a.ljust(5, '0') == '12300'
assert '\x30\x31\x32' == '012'