aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2002-08-23 16:45:24 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2002-08-23 16:45:24 -0300
commit12c4e4850640e094a243a8ca45a6d3d8aa70be22 (patch)
treec829bc6c5262f4b29acb9fc950964b2cec8846f3
parentc78aaa9a70cabf53c0386077e253eac48f45b71f (diff)
downloadlua-12c4e4850640e094a243a8ca45a6d3d8aa70be22.tar.gz
lua-12c4e4850640e094a243a8ca45a6d3d8aa70be22.tar.bz2
lua-12c4e4850640e094a243a8ca45a6d3d8aa70be22.zip
`frontier' patterns
-rw-r--r--lstrlib.c39
1 files changed, 27 insertions, 12 deletions
diff --git a/lstrlib.c b/lstrlib.c
index 673ad0f2..9cce456a 100644
--- a/lstrlib.c
+++ b/lstrlib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lstrlib.c,v 1.87 2002/06/26 19:28:08 roberto Exp roberto $ 2** $Id: lstrlib.c,v 1.88 2002/08/21 19:39:31 roberto Exp roberto $
3** Standard library for string operations and pattern-matching 3** Standard library for string operations and pattern-matching
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -339,18 +339,33 @@ static const char *match (MatchState *ms, const char *s, const char *p) {
339 case ')': { /* end capture */ 339 case ')': { /* end capture */
340 return end_capture(ms, s, p+1); 340 return end_capture(ms, s, p+1);
341 } 341 }
342 case ESC: { /* may be %[0-9] or %b */ 342 case ESC: {
343 if (isdigit(uchar(*(p+1)))) { /* capture? */ 343 switch (*(p+1)) {
344 s = match_capture(ms, s, *(p+1)); 344 case 'b': { /* balanced string? */
345 if (s == NULL) return NULL; 345 s = matchbalance(ms, s, p+2);
346 p+=2; goto init; /* else return match(ms, s, p+2) */ 346 if (s == NULL) return NULL;
347 } 347 p+=4; goto init; /* else return match(ms, s, p+4); */
348 else if (*(p+1) == 'b') { /* balanced string? */ 348 }
349 s = matchbalance(ms, s, p+2); 349 case 'f': { /* frontier? */
350 if (s == NULL) return NULL; 350 const char *ep; char previous;
351 p+=4; goto init; /* else return match(ms, s, p+4); */ 351 p += 2;
352 if (*p != '[')
353 luaL_error(ms->L, "missing `[' after `%%f' in pattern");
354 ep = luaI_classend(ms, p); /* points to what is next */
355 previous = (s == ms->src_init) ? '\0' : *(s-1);
356 if (matchbracketclass(uchar(previous), p, ep-1) ||
357 !matchbracketclass(uchar(*s), p, ep-1)) return NULL;
358 p=ep; goto init; /* else return match(ms, s, ep); */
359 }
360 default: {
361 if (isdigit(uchar(*(p+1)))) { /* capture results (%0-%9)? */
362 s = match_capture(ms, s, *(p+1));
363 if (s == NULL) return NULL;
364 p+=2; goto init; /* else return match(ms, s, p+2) */
365 }
366 goto dflt; /* case default */
367 }
352 } 368 }
353 else goto dflt; /* case default */
354 } 369 }
355 case '\0': { /* end of pattern */ 370 case '\0': { /* end of pattern */
356 return s; /* match succeeded */ 371 return s; /* match succeeded */