mirror of https://github.com/rusefi/lua.git
`frontier' patterns
This commit is contained in:
parent
c78aaa9a70
commit
12c4e48506
39
lstrlib.c
39
lstrlib.c
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
** $Id: lstrlib.c,v 1.87 2002/06/26 19:28:08 roberto Exp roberto $
|
** $Id: lstrlib.c,v 1.88 2002/08/21 19:39:31 roberto Exp roberto $
|
||||||
** Standard library for string operations and pattern-matching
|
** Standard library for string operations and pattern-matching
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
|
@ -339,18 +339,33 @@ static const char *match (MatchState *ms, const char *s, const char *p) {
|
||||||
case ')': { /* end capture */
|
case ')': { /* end capture */
|
||||||
return end_capture(ms, s, p+1);
|
return end_capture(ms, s, p+1);
|
||||||
}
|
}
|
||||||
case ESC: { /* may be %[0-9] or %b */
|
case ESC: {
|
||||||
if (isdigit(uchar(*(p+1)))) { /* capture? */
|
switch (*(p+1)) {
|
||||||
s = match_capture(ms, s, *(p+1));
|
case 'b': { /* balanced string? */
|
||||||
if (s == NULL) return NULL;
|
s = matchbalance(ms, s, p+2);
|
||||||
p+=2; goto init; /* else return match(ms, s, p+2) */
|
if (s == NULL) return NULL;
|
||||||
|
p+=4; goto init; /* else return match(ms, s, p+4); */
|
||||||
|
}
|
||||||
|
case 'f': { /* frontier? */
|
||||||
|
const char *ep; char previous;
|
||||||
|
p += 2;
|
||||||
|
if (*p != '[')
|
||||||
|
luaL_error(ms->L, "missing `[' after `%%f' in pattern");
|
||||||
|
ep = luaI_classend(ms, p); /* points to what is next */
|
||||||
|
previous = (s == ms->src_init) ? '\0' : *(s-1);
|
||||||
|
if (matchbracketclass(uchar(previous), p, ep-1) ||
|
||||||
|
!matchbracketclass(uchar(*s), p, ep-1)) return NULL;
|
||||||
|
p=ep; goto init; /* else return match(ms, s, ep); */
|
||||||
|
}
|
||||||
|
default: {
|
||||||
|
if (isdigit(uchar(*(p+1)))) { /* capture results (%0-%9)? */
|
||||||
|
s = match_capture(ms, s, *(p+1));
|
||||||
|
if (s == NULL) return NULL;
|
||||||
|
p+=2; goto init; /* else return match(ms, s, p+2) */
|
||||||
|
}
|
||||||
|
goto dflt; /* case default */
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (*(p+1) == 'b') { /* balanced string? */
|
|
||||||
s = matchbalance(ms, s, p+2);
|
|
||||||
if (s == NULL) return NULL;
|
|
||||||
p+=4; goto init; /* else return match(ms, s, p+4); */
|
|
||||||
}
|
|
||||||
else goto dflt; /* case default */
|
|
||||||
}
|
}
|
||||||
case '\0': { /* end of pattern */
|
case '\0': { /* end of pattern */
|
||||||
return s; /* match succeeded */
|
return s; /* match succeeded */
|
||||||
|
|
Loading…
Reference in New Issue