1
0
mirror of https://github.com/lua/lua.git synced 2025-01-14 05:43:00 +08:00

function "write_quoted" rewritten more clearly.

This commit is contained in:
Roberto Ierusalimschy 1996-02-22 17:56:33 -03:00
parent 8c1a9899d4
commit c7e834f424

23
iolib.c
View File

@ -3,7 +3,7 @@
** Input/output library to LUA ** Input/output library to LUA
*/ */
char *rcs_iolib="$Id: iolib.c,v 1.35 1996/02/09 19:35:23 roberto Exp roberto $"; char *rcs_iolib="$Id: iolib.c,v 1.36 1996/02/16 13:10:14 roberto Exp roberto $";
#include <stdio.h> #include <stdio.h>
#include <ctype.h> #include <ctype.h>
@ -373,24 +373,15 @@ static int write_string (char *s, int just, int m)
static int write_quoted (int just, int m) static int write_quoted (int just, int m)
{ {
char *s = lua_check_string(1, "write"); char *s;
luaI_addchar(0); luaI_addchar(0);
luaI_addchar('"'); luaI_addchar('"');
while (1) for (s = lua_check_string(1, "write"); *s; s++)
{ {
switch (*s) if (*s == '"' || *s == '\\' || *s == '\n')
{ luaI_addchar('\\');
case '"': case '\\': case '\n': luaI_addchar(*s);
luaI_addchar('\\'); }
luaI_addchar(*s);
break;
case 0:
goto END_WHILE;
default:
luaI_addchar(*s);
}
s++;
} END_WHILE:
luaI_addchar('"'); luaI_addchar('"');
return write_string(luaI_addchar(0), just, m); return write_string(luaI_addchar(0), just, m);
} }