diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1996-02-22 17:56:33 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1996-02-22 17:56:33 -0300 |
commit | c7e834f424f97f3b300cda931e607c37612cd2a4 (patch) | |
tree | 22374f3f3d6d1806a9147304737bcf6ec536f3b5 | |
parent | 8c1a9899d4460aa19780919f4245c08d7ebba0e9 (diff) | |
download | lua-c7e834f424f97f3b300cda931e607c37612cd2a4.tar.gz lua-c7e834f424f97f3b300cda931e607c37612cd2a4.tar.bz2 lua-c7e834f424f97f3b300cda931e607c37612cd2a4.zip |
function "write_quoted" rewritten more clearly.
-rw-r--r-- | iolib.c | 23 |
1 files changed, 7 insertions, 16 deletions
@@ -3,7 +3,7 @@ | |||
3 | ** Input/output library to LUA | 3 | ** Input/output library to LUA |
4 | */ | 4 | */ |
5 | 5 | ||
6 | char *rcs_iolib="$Id: iolib.c,v 1.35 1996/02/09 19:35:23 roberto Exp roberto $"; | 6 | char *rcs_iolib="$Id: iolib.c,v 1.36 1996/02/16 13:10:14 roberto Exp roberto $"; |
7 | 7 | ||
8 | #include <stdio.h> | 8 | #include <stdio.h> |
9 | #include <ctype.h> | 9 | #include <ctype.h> |
@@ -373,24 +373,15 @@ static int write_string (char *s, int just, int m) | |||
373 | 373 | ||
374 | static int write_quoted (int just, int m) | 374 | static int write_quoted (int just, int m) |
375 | { | 375 | { |
376 | char *s = lua_check_string(1, "write"); | 376 | char *s; |
377 | luaI_addchar(0); | 377 | luaI_addchar(0); |
378 | luaI_addchar('"'); | 378 | luaI_addchar('"'); |
379 | while (1) | 379 | for (s = lua_check_string(1, "write"); *s; s++) |
380 | { | 380 | { |
381 | switch (*s) | 381 | if (*s == '"' || *s == '\\' || *s == '\n') |
382 | { | 382 | luaI_addchar('\\'); |
383 | case '"': case '\\': case '\n': | 383 | luaI_addchar(*s); |
384 | luaI_addchar('\\'); | 384 | } |
385 | luaI_addchar(*s); | ||
386 | break; | ||
387 | case 0: | ||
388 | goto END_WHILE; | ||
389 | default: | ||
390 | luaI_addchar(*s); | ||
391 | } | ||
392 | s++; | ||
393 | } END_WHILE: | ||
394 | luaI_addchar('"'); | 385 | luaI_addchar('"'); |
395 | return write_string(luaI_addchar(0), just, m); | 386 | return write_string(luaI_addchar(0), just, m); |
396 | } | 387 | } |