diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1998-07-12 13:13:45 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1998-07-12 13:13:45 -0300 |
| commit | ad446a0eb06f570f826fd313f5ed225b04e3719a (patch) | |
| tree | 2f91c66b28a2115ad025275c57b65401a77aea23 | |
| parent | 176cb39feb0421069e930f004412c25549724f1f (diff) | |
| download | lua-ad446a0eb06f570f826fd313f5ed225b04e3719a.tar.gz lua-ad446a0eb06f570f826fd313f5ed225b04e3719a.tar.bz2 lua-ad446a0eb06f570f826fd313f5ed225b04e3719a.zip | |
"%q" can handle strings with '\0'.
Diffstat (limited to '')
| -rw-r--r-- | lstrlib.c | 23 |
1 files changed, 15 insertions, 8 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lstrlib.c,v 1.17 1998/06/29 18:24:06 roberto Exp roberto $ | 2 | ** $Id: lstrlib.c,v 1.18 1998/07/01 14:21:57 roberto Exp roberto $ |
| 3 | ** Standard library for strings and pattern-matching | 3 | ** Standard library for strings and pattern-matching |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -446,13 +446,20 @@ static void str_gsub (void) | |||
| 446 | } | 446 | } |
| 447 | 447 | ||
| 448 | 448 | ||
| 449 | static void luaI_addquoted (char *s) | 449 | static void luaI_addquoted (int arg) { |
| 450 | { | 450 | long l; |
| 451 | char *s = luaL_check_lstr(arg, &l); | ||
| 451 | luaL_addchar('"'); | 452 | luaL_addchar('"'); |
| 452 | for (; *s; s++) { | 453 | while (l--) { |
| 453 | if (strchr("\"\\\n", *s)) | 454 | switch (*s) { |
| 454 | luaL_addchar('\\'); | 455 | case '"': case '\\': case '\n': |
| 455 | luaL_addchar(*s); | 456 | luaL_addchar('\\'); |
| 457 | luaL_addchar(*s); | ||
| 458 | break; | ||
| 459 | case '\0': addnchar("\\000", 4); break; | ||
| 460 | default: luaL_addchar(*s); | ||
| 461 | } | ||
| 462 | s++; | ||
| 456 | } | 463 | } |
| 457 | luaL_addchar('"'); | 464 | luaL_addchar('"'); |
| 458 | } | 465 | } |
| @@ -490,7 +497,7 @@ static void str_format (void) | |||
| 490 | buff = luaL_openspace(1000); /* to store the formatted value */ | 497 | buff = luaL_openspace(1000); /* to store the formatted value */ |
| 491 | switch (*strfrmt++) { | 498 | switch (*strfrmt++) { |
| 492 | case 'q': | 499 | case 'q': |
| 493 | luaI_addquoted(luaL_check_string(arg)); | 500 | luaI_addquoted(arg); |
| 494 | continue; | 501 | continue; |
| 495 | case 's': { | 502 | case 's': { |
| 496 | char *s = luaL_check_string(arg); | 503 | char *s = luaL_check_string(arg); |
