mirror of
https://github.com/LuaJIT/LuaJIT.git
synced 2025-02-07 23:24:09 +00:00
Parse hexadecimal escapes in strings (from Lua 5.2).
This commit is contained in:
parent
57cd5026eb
commit
29b8959df1
@ -117,7 +117,7 @@ ERRDEF(XNUMBER, "malformed number")
|
|||||||
ERRDEF(XLSTR, "unfinished long string")
|
ERRDEF(XLSTR, "unfinished long string")
|
||||||
ERRDEF(XLCOM, "unfinished long comment")
|
ERRDEF(XLCOM, "unfinished long comment")
|
||||||
ERRDEF(XSTR, "unfinished string")
|
ERRDEF(XSTR, "unfinished string")
|
||||||
ERRDEF(XESC, "escape sequence too large")
|
ERRDEF(XESC, "invalid escape sequence")
|
||||||
ERRDEF(XLDELIM, "invalid long string delimiter")
|
ERRDEF(XLDELIM, "invalid long string delimiter")
|
||||||
ERRDEF(XBCLOAD, "cannot load Lua bytecode")
|
ERRDEF(XBCLOAD, "cannot load Lua bytecode")
|
||||||
ERRDEF(XTOKEN, LUA_QS " expected")
|
ERRDEF(XTOKEN, LUA_QS " expected")
|
||||||
|
38
src/lj_lex.c
38
src/lj_lex.c
@ -154,7 +154,7 @@ static void read_string(LexState *ls, int delim, TValue *tv)
|
|||||||
continue;
|
continue;
|
||||||
case '\\': {
|
case '\\': {
|
||||||
int c;
|
int c;
|
||||||
next(ls); /* do not save the `\' */
|
next(ls); /* Skip the '\\'. */
|
||||||
switch (ls->current) {
|
switch (ls->current) {
|
||||||
case 'a': c = '\a'; break;
|
case 'a': c = '\a'; break;
|
||||||
case 'b': c = '\b'; break;
|
case 'b': c = '\b'; break;
|
||||||
@ -163,20 +163,36 @@ static void read_string(LexState *ls, int delim, TValue *tv)
|
|||||||
case 'r': c = '\r'; break;
|
case 'r': c = '\r'; break;
|
||||||
case 't': c = '\t'; break;
|
case 't': c = '\t'; break;
|
||||||
case 'v': c = '\v'; break;
|
case 'v': c = '\v'; break;
|
||||||
|
case 'x': /* Hexadecimal escape '\xXX'. */
|
||||||
|
c = (next(ls) & 15u) << 4;
|
||||||
|
if (!lj_char_isdigit(ls->current)) {
|
||||||
|
if (!lj_char_isxdigit(ls->current)) goto err_xesc;
|
||||||
|
c += 9 << 4;
|
||||||
|
}
|
||||||
|
c += (next(ls) & 15u);
|
||||||
|
if (!lj_char_isdigit(ls->current)) {
|
||||||
|
if (!lj_char_isxdigit(ls->current)) goto err_xesc;
|
||||||
|
c += 9;
|
||||||
|
}
|
||||||
|
break;
|
||||||
case '\n': case '\r': save(ls, '\n'); inclinenumber(ls); continue;
|
case '\n': case '\r': save(ls, '\n'); inclinenumber(ls); continue;
|
||||||
case END_OF_STREAM: continue; /* will raise an error next loop */
|
case END_OF_STREAM: continue;
|
||||||
default:
|
default:
|
||||||
if (!lj_char_isdigit(ls->current)) {
|
if (!lj_char_isdigit(ls->current)) {
|
||||||
save_and_next(ls); /* handles \\, \", \', and \? */
|
save_and_next(ls); /* Handles '\\', '\"' and "\'". */
|
||||||
} else { /* \xxx */
|
} else { /* Decimal escape '\ddd'. */
|
||||||
int i = 0;
|
c = (ls->current - '0');
|
||||||
c = 0;
|
if (lj_char_isdigit(next(ls))) {
|
||||||
do {
|
c = c*10 + (ls->current - '0');
|
||||||
c = 10*c + (ls->current-'0');
|
if (lj_char_isdigit(next(ls))) {
|
||||||
next(ls);
|
c = c*10 + (ls->current - '0');
|
||||||
} while (++i<3 && lj_char_isdigit(ls->current));
|
if (c > 255) {
|
||||||
if (c > 255)
|
err_xesc:
|
||||||
lj_lex_error(ls, TK_string, LJ_ERR_XESC);
|
lj_lex_error(ls, TK_string, LJ_ERR_XESC);
|
||||||
|
}
|
||||||
|
next(ls);
|
||||||
|
}
|
||||||
|
}
|
||||||
save(ls, c);
|
save(ls, c);
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
|
Loading…
Reference in New Issue
Block a user