aboutsummaryrefslogtreecommitdiff
path: root/liolib.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>1999-05-05 16:23:11 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>1999-05-05 16:23:11 -0300
commit7808ea3a5ffe8c2045dc76099f8968e3b8104360 (patch)
treefdda1783dcbd47a5d7de0ab3ddae11b7c5afc275 /liolib.c
parent732741b62fe1cb9cf19ecca8b210474d076ba8b3 (diff)
downloadlua-7808ea3a5ffe8c2045dc76099f8968e3b8104360.tar.gz
lua-7808ea3a5ffe8c2045dc76099f8968e3b8104360.tar.bz2
lua-7808ea3a5ffe8c2045dc76099f8968e3b8104360.zip
new implementation for '*' in patterns + new option '+'
Diffstat (limited to 'liolib.c')
-rw-r--r--liolib.c26
1 files changed, 14 insertions, 12 deletions
diff --git a/liolib.c b/liolib.c
index 13719590..f43c3fd0 100644
--- a/liolib.c
+++ b/liolib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: liolib.c,v 1.37 1999/04/05 19:47:05 roberto Exp roberto $ 2** $Id: liolib.c,v 1.38 1999/04/14 20:40:32 roberto Exp $
3** Standard I/O (and system) library 3** Standard I/O (and system) library
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -244,23 +244,25 @@ static int read_pattern (FILE *f, char *p) {
244 p++; 244 p++;
245 continue; 245 continue;
246 default: { 246 default: {
247 char *ep; /* get what is next */ 247 char *ep = luaI_classend(p); /* get what is next */
248 int m; /* match result */ 248 int m; /* match result */
249 if (c == NEED_OTHER) c = getc(f); 249 if (c == NEED_OTHER) c = getc(f);
250 if (c != EOF) 250 m = (c==EOF) ? 0 : luaI_singlematch(c, p, ep);
251 m = luaI_singlematch(c, p, &ep);
252 else {
253 luaI_singlematch(0, p, &ep); /* to set "ep" */
254 m = 0; /* EOF matches no pattern */
255 }
256 if (m) { 251 if (m) {
257 if (!inskip) luaL_addchar(c); 252 if (!inskip) luaL_addchar(c);
258 c = NEED_OTHER; 253 c = NEED_OTHER;
259 } 254 }
260 switch (*ep) { 255 switch (*ep) {
261 case '*': /* repetition */ 256 case '+': /* repetition (1 or more) */
262 if (!m) p = ep+1; /* else stay in (repeat) the same item */ 257 if (!m) goto break_while; /* pattern fails? */
263 continue; 258 /* else go through */
259 case '*': /* repetition (0 or more) */
260 while (m) { /* reads the same item until it fails */
261 c = getc(f);
262 m = (c==EOF) ? 0 : luaI_singlematch(c, p, ep);
263 if (m && !inskip) luaL_addchar(c);
264 }
265 /* go through to continue reading the pattern */
264 case '?': /* optional */ 266 case '?': /* optional */
265 p = ep+1; /* continues reading the pattern */ 267 p = ep+1; /* continues reading the pattern */
266 continue; 268 continue;
@@ -336,7 +338,7 @@ static void io_read (void) {
336 success = 1; /* always success */ 338 success = 1; /* always success */
337 break; 339 break;
338 case 4: /* word */ 340 case 4: /* word */
339 success = read_pattern(f, "{%s*}%S%S*"); 341 success = read_pattern(f, "{%s*}%S+");
340 break; 342 break;
341 default: 343 default:
342 success = read_pattern(f, p); 344 success = read_pattern(f, p);