|
@@ -1,5 +1,5 @@
|
|
/*
|
|
/*
|
|
-** $Id: lstrlib.c,v 1.146 2009/12/17 12:26:09 roberto Exp roberto $
|
|
|
|
|
|
+** $Id: lstrlib.c,v 1.147 2009/12/17 12:50:20 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
|
|
*/
|
|
*/
|
|
@@ -384,7 +384,15 @@ 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 L_ESC: {
|
|
|
|
|
|
+ case '\0': { /* end of pattern */
|
|
|
|
+ return s; /* match succeeded */
|
|
|
|
+ }
|
|
|
|
+ case '$': {
|
|
|
|
+ if (*(p+1) == '\0') /* is the `$' the last char in pattern? */
|
|
|
|
+ return (s == ms->src_end) ? s : NULL; /* check end of string */
|
|
|
|
+ else goto dflt;
|
|
|
|
+ }
|
|
|
|
+ case L_ESC: { /* escaped sequences not in the format class[*+?-]? */
|
|
switch (*(p+1)) {
|
|
switch (*(p+1)) {
|
|
case 'b': { /* balanced string? */
|
|
case 'b': { /* balanced string? */
|
|
s = matchbalance(ms, s, p+2);
|
|
s = matchbalance(ms, s, p+2);
|
|
@@ -403,25 +411,17 @@ static const char *match (MatchState *ms, const char *s, const char *p) {
|
|
!matchbracketclass(uchar(*s), p, ep-1)) return NULL;
|
|
!matchbracketclass(uchar(*s), p, ep-1)) return NULL;
|
|
p=ep; goto init; /* else return match(ms, s, ep); */
|
|
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, uchar(*(p+1)));
|
|
|
|
- if (s == NULL) return NULL;
|
|
|
|
- p+=2; goto init; /* else return match(ms, s, p+2) */
|
|
|
|
- }
|
|
|
|
- goto dflt; /* case default */
|
|
|
|
|
|
+ case '0': case '1': case '2': case '3':
|
|
|
|
+ case '4': case '5': case '6': case '7':
|
|
|
|
+ case '8': case '9': { /* capture results (%0-%9)? */
|
|
|
|
+ s = match_capture(ms, s, uchar(*(p+1)));
|
|
|
|
+ if (s == NULL) return NULL;
|
|
|
|
+ p+=2; goto init; /* else return match(ms, s, p+2) */
|
|
}
|
|
}
|
|
|
|
+ default: break; /* go through to 'dflt' */
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- case '\0': { /* end of pattern */
|
|
|
|
- return s; /* match succeeded */
|
|
|
|
- }
|
|
|
|
- case '$': {
|
|
|
|
- if (*(p+1) == '\0') /* is the `$' the last char in pattern? */
|
|
|
|
- return (s == ms->src_end) ? s : NULL; /* check end of string */
|
|
|
|
- else goto dflt;
|
|
|
|
- }
|
|
|
|
- default: dflt: { /* it is a pattern item */
|
|
|
|
|
|
+ default: dflt: { /* pattern class plus optional sufix */
|
|
const char *ep = classend(ms, p); /* points to what is next */
|
|
const char *ep = classend(ms, p); /* points to what is next */
|
|
int m = s<ms->src_end && singlematch(uchar(*s), p, ep);
|
|
int m = s<ms->src_end && singlematch(uchar(*s), p, ep);
|
|
switch (*ep) {
|
|
switch (*ep) {
|