mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-19 19:10:17 +00:00
...
This commit is contained in:
parent
58adfe6d17
commit
9ea76aee85
12
src/lexer.h
12
src/lexer.h
@ -323,6 +323,18 @@ struct Lexer {
|
||||
case 'n': buff.push_back('\n'); break;
|
||||
case 'r': buff.push_back('\r'); 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");
|
||||
}
|
||||
} else {
|
||||
|
@ -106,4 +106,6 @@ a = '123'
|
||||
assert a.rjust(5) == ' 123'
|
||||
assert a.rjust(5, '0') == '00123'
|
||||
assert a.ljust(5) == '123 '
|
||||
assert a.ljust(5, '0') == '12300'
|
||||
assert a.ljust(5, '0') == '12300'
|
||||
|
||||
assert '\x30\x31\x32' == '012'
|
Loading…
x
Reference in New Issue
Block a user