diff options
Diffstat (limited to 'llex.c')
-rw-r--r-- | llex.c | 25 |
1 files changed, 7 insertions, 18 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: llex.c,v 2.71 2014/01/31 15:14:22 roberto Exp roberto $ | 2 | ** $Id: llex.c,v 2.72 2014/02/04 18:57:34 roberto Exp roberto $ |
3 | ** Lexical Analyzer | 3 | ** Lexical Analyzer |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -359,22 +359,11 @@ static unsigned int readutf8esc (LexState *ls) { | |||
359 | } | 359 | } |
360 | 360 | ||
361 | 361 | ||
362 | static void utf8esc (LexState *ls, unsigned int r) { | 362 | static void utf8esc (LexState *ls) { |
363 | if (r < 0x80) /* ascii? */ | 363 | char buff[UTF8BUFFSZ]; |
364 | save(ls, r); | 364 | int n = luaO_utf8esc(buff, readutf8esc(ls)); |
365 | else { /* need continuation bytes */ | 365 | for (; n > 0; n--) /* add 'buff' to string */ |
366 | int buff[4]; /* to store continuation bytes */ | 366 | save(ls, buff[UTF8BUFFSZ - n]); |
367 | int n = 0; /* number of continuation bytes */ | ||
368 | unsigned int mfb = 0x3f; /* maximum that fits in first byte */ | ||
369 | do { | ||
370 | buff[n++] = 0x80 | (r & 0x3f); /* add continuation byte */ | ||
371 | r >>= 6; /* remove added bits */ | ||
372 | mfb >>= 1; /* now there is one less bit in first byte */ | ||
373 | } while (r > mfb); /* needs continuation byte? */ | ||
374 | save(ls, (~mfb << 1) | r); /* add first byte */ | ||
375 | while (n-- > 0) /* add 'buff' to string, reversed */ | ||
376 | save(ls, buff[n]); | ||
377 | } | ||
378 | } | 367 | } |
379 | 368 | ||
380 | 369 | ||
@@ -414,7 +403,7 @@ static void read_string (LexState *ls, int del, SemInfo *seminfo) { | |||
414 | case 't': c = '\t'; goto read_save; | 403 | case 't': c = '\t'; goto read_save; |
415 | case 'v': c = '\v'; goto read_save; | 404 | case 'v': c = '\v'; goto read_save; |
416 | case 'x': c = readhexaesc(ls); goto read_save; | 405 | case 'x': c = readhexaesc(ls); goto read_save; |
417 | case 'u': utf8esc(ls, readutf8esc(ls)); goto no_save; | 406 | case 'u': utf8esc(ls); goto no_save; |
418 | case '\n': case '\r': | 407 | case '\n': case '\r': |
419 | inclinenumber(ls); c = '\n'; goto only_save; | 408 | inclinenumber(ls); c = '\n'; goto only_save; |
420 | case '\\': case '\"': case '\'': | 409 | case '\\': case '\"': case '\'': |