diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1996-08-05 17:55:24 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1996-08-05 17:55:24 -0300 |
commit | 25b6dae7c06a61d2f6d8890f4c071cc3fffee889 (patch) | |
tree | e42e211cdc72b6d0db1df82e0f566f79affa69a8 | |
parent | 1630c2533a99e808ecf4649b637f45c964b1c477 (diff) | |
download | lua-25b6dae7c06a61d2f6d8890f4c071cc3fffee889.tar.gz lua-25b6dae7c06a61d2f6d8890f4c071cc3fffee889.tar.bz2 lua-25b6dae7c06a61d2f6d8890f4c071cc3fffee889.zip |
singlematch and item_end are used by "read", in iolib.
-rw-r--r-- | lualib.h | 5 | ||||
-rw-r--r-- | strlib.c | 14 |
2 files changed, 11 insertions, 8 deletions
@@ -2,7 +2,7 @@ | |||
2 | ** Libraries to be used in LUA programs | 2 | ** Libraries to be used in LUA programs |
3 | ** Grupo de Tecnologia em Computacao Grafica | 3 | ** Grupo de Tecnologia em Computacao Grafica |
4 | ** TeCGraf - PUC-Rio | 4 | ** TeCGraf - PUC-Rio |
5 | ** $Id: lualib.h,v 1.8 1996/04/30 21:13:55 roberto Exp roberto $ | 5 | ** $Id: lualib.h,v 1.9 1996/08/01 14:55:33 roberto Exp roberto $ |
6 | */ | 6 | */ |
7 | 7 | ||
8 | #ifndef lualib_h | 8 | #ifndef lualib_h |
@@ -31,5 +31,8 @@ long lua_opt_number (int numArg, long def, char *funcname); | |||
31 | char *luaI_addchar (int c); | 31 | char *luaI_addchar (int c); |
32 | void luaI_addquoted (char *s); | 32 | void luaI_addquoted (char *s); |
33 | 33 | ||
34 | char *item_end (char *p); | ||
35 | int singlematch (int c, char *p); | ||
36 | |||
34 | #endif | 37 | #endif |
35 | 38 | ||
@@ -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.24 1996/05/22 21:59:07 roberto Exp roberto $"; | 6 | char *rcs_strlib="$Id: strlib.c,v 1.25 1996/08/01 14:55:33 roberto Exp roberto $"; |
7 | 7 | ||
8 | #include <string.h> | 8 | #include <string.h> |
9 | #include <stdio.h> | 9 | #include <stdio.h> |
@@ -178,7 +178,7 @@ static void str_ascii (void) | |||
178 | #define ESC '%' | 178 | #define ESC '%' |
179 | #define SPECIALS "^$*?.([%" | 179 | #define SPECIALS "^$*?.([%" |
180 | 180 | ||
181 | static char *item_end (char *p) | 181 | char *item_end (char *p) |
182 | { | 182 | { |
183 | switch (*p) { | 183 | switch (*p) { |
184 | case '\0': return p; | 184 | case '\0': return p; |
@@ -212,9 +212,9 @@ static int matchclass (int c, int cl) | |||
212 | return (islower(cl) ? res : !res); | 212 | return (islower(cl) ? res : !res); |
213 | } | 213 | } |
214 | 214 | ||
215 | static int singlematch (int c, char *p) | 215 | int singlematch (int c, char *p) |
216 | { | 216 | { |
217 | if (c == 0) return 0; | 217 | if (c <= 0) return 0; /* \0, EOF or other strange flags */ |
218 | switch (*p) { | 218 | switch (*p) { |
219 | case '.': return 1; | 219 | case '.': return 1; |
220 | case ESC: return matchclass(c, *(p+1)); | 220 | case ESC: return matchclass(c, *(p+1)); |
@@ -323,13 +323,13 @@ static char *match (char *s, char *p, int level) | |||
323 | int m = singlematch(*s, p); | 323 | int m = singlematch(*s, p); |
324 | char *ep = item_end(p); /* get what is next */ | 324 | char *ep = item_end(p); /* get what is next */ |
325 | switch (*ep) { | 325 | switch (*ep) { |
326 | case '*': { /* repetition? */ | 326 | case '*': { /* repetition */ |
327 | char *res; | 327 | char *res; |
328 | if (m && (res = match(s+1, p, level))) | 328 | if (m && (res = match(s+1, p, level))) |
329 | return res; | 329 | return res; |
330 | p=ep+1; goto init; /* else return match(s, ep+1, level); */ | 330 | p=ep+1; goto init; /* else return match(s, ep+1, level); */ |
331 | } | 331 | } |
332 | case '?': { /* optional? */ | 332 | case '?': { /* optional */ |
333 | char *res; | 333 | char *res; |
334 | if (m && (res = match(s+1, ep+1, level))) | 334 | if (m && (res = match(s+1, ep+1, level))) |
335 | return res; | 335 | return res; |
@@ -487,7 +487,7 @@ static struct lua_reg strlib[] = { | |||
487 | {"ascii", str_ascii}, | 487 | {"ascii", str_ascii}, |
488 | {"format", str_format}, | 488 | {"format", str_format}, |
489 | {"strfind", str_find}, | 489 | {"strfind", str_find}, |
490 | {"s", str_s} | 490 | {"gsub", str_s} |
491 | }; | 491 | }; |
492 | 492 | ||
493 | 493 | ||