diff options
| author | Mike Pall <mike> | 2010-11-19 18:22:08 +0100 |
|---|---|---|
| committer | Mike Pall <mike> | 2010-11-19 18:22:08 +0100 |
| commit | 7cc981c14067d4b0e774a6bfb0acfc2f5c911f0d (patch) | |
| tree | f1dfe722e4bf2b6f9eab8add1411cc269c8db5ca /src | |
| parent | 29b8959df143994219e1192e099e5e70cf9181aa (diff) | |
| download | luajit-7cc981c14067d4b0e774a6bfb0acfc2f5c911f0d.tar.gz luajit-7cc981c14067d4b0e774a6bfb0acfc2f5c911f0d.tar.bz2 luajit-7cc981c14067d4b0e774a6bfb0acfc2f5c911f0d.zip | |
string.format("%q", str) is now fully reversible (from Lua 5.2).
Diffstat (limited to 'src')
| -rw-r--r-- | src/lib_string.c | 20 |
1 files changed, 9 insertions, 11 deletions
diff --git a/src/lib_string.c b/src/lib_string.c index 73a09583..c64baed5 100644 --- a/src/lib_string.c +++ b/src/lib_string.c | |||
| @@ -653,20 +653,18 @@ static void addquoted(lua_State *L, luaL_Buffer *b, int arg) | |||
| 653 | const char *s = strdata(str); | 653 | const char *s = strdata(str); |
| 654 | luaL_addchar(b, '"'); | 654 | luaL_addchar(b, '"'); |
| 655 | while (len--) { | 655 | while (len--) { |
| 656 | switch (*s) { | 656 | if (*s == '"' || *s == '\\' || *s == '\n') { |
| 657 | case '"': case '\\': case '\n': | ||
| 658 | luaL_addchar(b, '\\'); | 657 | luaL_addchar(b, '\\'); |
| 659 | luaL_addchar(b, *s); | 658 | luaL_addchar(b, *s); |
| 660 | break; | 659 | } else if (lj_char_iscntrl(uchar(*s))) { |
| 661 | case '\r': | 660 | uint32_t c1, c2, c3; |
| 662 | luaL_addlstring(b, "\\r", 2); | 661 | luaL_addchar(b, '\\'); |
| 663 | break; | 662 | c1 = uchar(*s); c3 = c1 % 10; c1 /= 10; c2 = c1 % 10; c1 /= 10; |
| 664 | case '\0': | 663 | if (c1 + lj_char_isdigit(uchar(s[1]))) luaL_addchar(b, '0' + c1); |
| 665 | luaL_addlstring(b, "\\000", 4); | 664 | if (c2 + (c1 + lj_char_isdigit(uchar(s[1])))) luaL_addchar(b, '0' + c2); |
| 666 | break; | 665 | luaL_addchar(b, '0' + c3); |
| 667 | default: | 666 | } else { |
| 668 | luaL_addchar(b, *s); | 667 | luaL_addchar(b, *s); |
| 669 | break; | ||
| 670 | } | 668 | } |
| 671 | s++; | 669 | s++; |
| 672 | } | 670 | } |
