diff options
| -rw-r--r-- | lstrlib.c | 33 |
1 files changed, 14 insertions, 19 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lstrlib.c,v 1.134 2006/09/11 14:07:24 roberto Exp roberto $ | 2 | ** $Id: lstrlib.c,v 1.135 2006/09/18 16:33:14 roberto Exp roberto $ |
| 3 | ** Standard library for string operations and pattern-matching | 3 | ** Standard library for string operations and pattern-matching |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -697,25 +697,20 @@ static void addquoted (lua_State *L, luaL_Buffer *b, int arg) { | |||
| 697 | const char *s = luaL_checklstring(L, arg, &l); | 697 | const char *s = luaL_checklstring(L, arg, &l); |
| 698 | luaL_addchar(b, '"'); | 698 | luaL_addchar(b, '"'); |
| 699 | while (l--) { | 699 | while (l--) { |
| 700 | switch (*s) { | 700 | if (*s == '"' || *s == '\\' || *s == '\n') { |
| 701 | case '"': case '\\': case '\n': { | 701 | luaL_addchar(b, '\\'); |
| 702 | luaL_addchar(b, '\\'); | 702 | luaL_addchar(b, *s); |
| 703 | luaL_addchar(b, *s); | ||
| 704 | break; | ||
| 705 | } | ||
| 706 | case '\r': { | ||
| 707 | luaL_addlstring(b, "\\r", 2); | ||
| 708 | break; | ||
| 709 | } | ||
| 710 | case '\0': { | ||
| 711 | luaL_addlstring(b, "\\000", 4); | ||
| 712 | break; | ||
| 713 | } | ||
| 714 | default: { | ||
| 715 | luaL_addchar(b, *s); | ||
| 716 | break; | ||
| 717 | } | ||
| 718 | } | 703 | } |
| 704 | else if (*s == '\0' || iscntrl(uchar(*s))) { | ||
| 705 | char buff[10]; | ||
| 706 | if (*s != '\0' && !isdigit(uchar(*(s+1)))) | ||
| 707 | sprintf(buff, "\\%d", uchar(*s)); | ||
| 708 | else | ||
| 709 | sprintf(buff, "\\%03d", uchar(*s)); | ||
| 710 | luaL_addstring(b, buff); | ||
| 711 | } | ||
| 712 | else | ||
| 713 | luaL_addchar(b, *s); | ||
| 719 | s++; | 714 | s++; |
| 720 | } | 715 | } |
| 721 | luaL_addchar(b, '"'); | 716 | luaL_addchar(b, '"'); |
