diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1996-03-14 12:52:35 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1996-03-14 12:52:35 -0300 |
commit | 2fee7e42c93ffdd4859fa4d06602760eacbef629 (patch) | |
tree | 0b24463cec17fdcc5664c306c3c5665dbb0d3832 | |
parent | 281db390e8c8bdb8423a21728a2d4ac703ac3f33 (diff) | |
download | lua-2fee7e42c93ffdd4859fa4d06602760eacbef629.tar.gz lua-2fee7e42c93ffdd4859fa4d06602760eacbef629.tar.bz2 lua-2fee7e42c93ffdd4859fa4d06602760eacbef629.zip |
new option 'q' in function "format".
-rw-r--r-- | strlib.c | 17 |
1 files changed, 16 insertions, 1 deletions
@@ -3,7 +3,7 @@ | |||
3 | ** String library to LUA | 3 | ** String library to LUA |
4 | */ | 4 | */ |
5 | 5 | ||
6 | char *rcs_strlib="$Id: strlib.c,v 1.18 1996/02/12 18:32:40 roberto Exp $"; | 6 | char *rcs_strlib="$Id: strlib.c,v 1.18 1996/02/12 18:34:44 roberto Exp roberto $"; |
7 | 7 | ||
8 | #include <string.h> | 8 | #include <string.h> |
9 | #include <stdio.h> | 9 | #include <stdio.h> |
@@ -175,6 +175,17 @@ static void str_ascii (void) | |||
175 | lua_pushnumber(s[pos]); | 175 | lua_pushnumber(s[pos]); |
176 | } | 176 | } |
177 | 177 | ||
178 | void luaI_addquoted (char *s) | ||
179 | { | ||
180 | luaI_addchar('"'); | ||
181 | for (; *s; s++) | ||
182 | { | ||
183 | if (*s == '"' || *s == '\\' || *s == '\n') | ||
184 | luaI_addchar('\\'); | ||
185 | luaI_addchar(*s); | ||
186 | } | ||
187 | luaI_addchar('"'); | ||
188 | } | ||
178 | 189 | ||
179 | #define MAX_CONVERTION 2000 | 190 | #define MAX_CONVERTION 2000 |
180 | #define MAX_FORMAT 50 | 191 | #define MAX_FORMAT 50 |
@@ -215,6 +226,10 @@ static void str_format (void) | |||
215 | form[i+1] = 0; /* ends string */ | 226 | form[i+1] = 0; /* ends string */ |
216 | switch (form[i]) | 227 | switch (form[i]) |
217 | { | 228 | { |
229 | case 'q': | ||
230 | luaI_addquoted(lua_check_string(arg++, "format")); | ||
231 | buff[0] = '\0'; /* addchar already done */ | ||
232 | break; | ||
218 | case 's': | 233 | case 's': |
219 | { | 234 | { |
220 | char *s = lua_check_string(arg++, "format"); | 235 | char *s = lua_check_string(arg++, "format"); |