diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2007-02-07 15:53:08 -0200 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2007-02-07 15:53:08 -0200 |
| commit | d62a21b9d379a576bae7426c80039ca1a4d2bb07 (patch) | |
| tree | 9c18a6666e02097898e51efdba68640c9327434c | |
| parent | cf86576a838dbe7a11f64116bdc9b1942d233ff8 (diff) | |
| download | lua-d62a21b9d379a576bae7426c80039ca1a4d2bb07.tar.gz lua-d62a21b9d379a576bae7426c80039ca1a4d2bb07.tar.bz2 lua-d62a21b9d379a576bae7426c80039ca1a4d2bb07.zip | |
when formatting with '%q', all control characters are coded
as \nnn.
| -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, '"'); |
