summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>1996-08-05 17:55:24 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>1996-08-05 17:55:24 -0300
commit25b6dae7c06a61d2f6d8890f4c071cc3fffee889 (patch)
treee42e211cdc72b6d0db1df82e0f566f79affa69a8
parent1630c2533a99e808ecf4649b637f45c964b1c477 (diff)
downloadlua-25b6dae7c06a61d2f6d8890f4c071cc3fffee889.tar.gz
lua-25b6dae7c06a61d2f6d8890f4c071cc3fffee889.tar.bz2
lua-25b6dae7c06a61d2f6d8890f4c071cc3fffee889.zip
singlematch and item_end are used by "read", in iolib.
-rw-r--r--lualib.h5
-rw-r--r--strlib.c14
2 files changed, 11 insertions, 8 deletions
diff --git a/lualib.h b/lualib.h
index 00c0235e..ba2d108d 100644
--- a/lualib.h
+++ b/lualib.h
@@ -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);
31char *luaI_addchar (int c); 31char *luaI_addchar (int c);
32void luaI_addquoted (char *s); 32void luaI_addquoted (char *s);
33 33
34char *item_end (char *p);
35int singlematch (int c, char *p);
36
34#endif 37#endif
35 38
diff --git a/strlib.c b/strlib.c
index 1fab7a20..bd471f7a 100644
--- a/strlib.c
+++ b/strlib.c
@@ -3,7 +3,7 @@
3** String library to LUA 3** String library to LUA
4*/ 4*/
5 5
6char *rcs_strlib="$Id: strlib.c,v 1.24 1996/05/22 21:59:07 roberto Exp roberto $"; 6char *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
181static char *item_end (char *p) 181char *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
215static int singlematch (int c, char *p) 215int 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