aboutsummaryrefslogtreecommitdiff
path: root/llex.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2014-02-06 13:59:24 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2014-02-06 13:59:24 -0200
commit4ea60463f5a5cc5c30bf3f20be0dd5141f48aa3c (patch)
treed5330beaf2e11fc249f6c0aaef0b18ab3d9ec22c /llex.c
parentd438e1379d24f06f027f8fc0e8fc1ff6673b322f (diff)
downloadlua-4ea60463f5a5cc5c30bf3f20be0dd5141f48aa3c.tar.gz
lua-4ea60463f5a5cc5c30bf3f20be0dd5141f48aa3c.tar.bz2
lua-4ea60463f5a5cc5c30bf3f20be0dd5141f48aa3c.zip
UTF-8 encoding exported as format '%U' in 'lua_pushfstring'
Diffstat (limited to 'llex.c')
-rw-r--r--llex.c25
1 files changed, 7 insertions, 18 deletions
diff --git a/llex.c b/llex.c
index 818c0812..514a8150 100644
--- a/llex.c
+++ b/llex.c
@@ -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
362static void utf8esc (LexState *ls, unsigned int r) { 362static 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 '\'':