diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2010-01-04 14:37:19 -0200 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2010-01-04 14:37:19 -0200 |
| commit | 1fd4c482a03770384b8cedae466c85dd3346205a (patch) | |
| tree | 5c82db76f87637c0fbfb7e5f8357ad9a5b1010ca | |
| parent | 35e729fa6d96f39015c991e4036fbdb0a9c8977b (diff) | |
| download | lua-1fd4c482a03770384b8cedae466c85dd3346205a.tar.gz lua-1fd4c482a03770384b8cedae466c85dd3346205a.tar.bz2 lua-1fd4c482a03770384b8cedae466c85dd3346205a.zip | |
reorganization of switch in function 'match' (details)
| -rw-r--r-- | lstrlib.c | 36 |
1 files changed, 18 insertions, 18 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lstrlib.c,v 1.146 2009/12/17 12:26:09 roberto Exp roberto $ | 2 | ** $Id: lstrlib.c,v 1.147 2009/12/17 12:50:20 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 | */ |
| @@ -384,7 +384,15 @@ static const char *match (MatchState *ms, const char *s, const char *p) { | |||
| 384 | case ')': { /* end capture */ | 384 | case ')': { /* end capture */ |
| 385 | return end_capture(ms, s, p+1); | 385 | return end_capture(ms, s, p+1); |
| 386 | } | 386 | } |
| 387 | case L_ESC: { | 387 | case '\0': { /* end of pattern */ |
| 388 | return s; /* match succeeded */ | ||
| 389 | } | ||
| 390 | case '$': { | ||
| 391 | if (*(p+1) == '\0') /* is the `$' the last char in pattern? */ | ||
| 392 | return (s == ms->src_end) ? s : NULL; /* check end of string */ | ||
| 393 | else goto dflt; | ||
| 394 | } | ||
| 395 | case L_ESC: { /* escaped sequences not in the format class[*+?-]? */ | ||
| 388 | switch (*(p+1)) { | 396 | switch (*(p+1)) { |
| 389 | case 'b': { /* balanced string? */ | 397 | case 'b': { /* balanced string? */ |
| 390 | s = matchbalance(ms, s, p+2); | 398 | s = matchbalance(ms, s, p+2); |
| @@ -403,25 +411,17 @@ static const char *match (MatchState *ms, const char *s, const char *p) { | |||
| 403 | !matchbracketclass(uchar(*s), p, ep-1)) return NULL; | 411 | !matchbracketclass(uchar(*s), p, ep-1)) return NULL; |
| 404 | p=ep; goto init; /* else return match(ms, s, ep); */ | 412 | p=ep; goto init; /* else return match(ms, s, ep); */ |
| 405 | } | 413 | } |
| 406 | default: { | 414 | case '0': case '1': case '2': case '3': |
| 407 | if (isdigit(uchar(*(p+1)))) { /* capture results (%0-%9)? */ | 415 | case '4': case '5': case '6': case '7': |
| 408 | s = match_capture(ms, s, uchar(*(p+1))); | 416 | case '8': case '9': { /* capture results (%0-%9)? */ |
| 409 | if (s == NULL) return NULL; | 417 | s = match_capture(ms, s, uchar(*(p+1))); |
| 410 | p+=2; goto init; /* else return match(ms, s, p+2) */ | 418 | if (s == NULL) return NULL; |
| 411 | } | 419 | p+=2; goto init; /* else return match(ms, s, p+2) */ |
| 412 | goto dflt; /* case default */ | ||
| 413 | } | 420 | } |
| 421 | default: break; /* go through to 'dflt' */ | ||
| 414 | } | 422 | } |
| 415 | } | 423 | } |
| 416 | case '\0': { /* end of pattern */ | 424 | default: dflt: { /* pattern class plus optional sufix */ |
| 417 | return s; /* match succeeded */ | ||
| 418 | } | ||
| 419 | case '$': { | ||
| 420 | if (*(p+1) == '\0') /* is the `$' the last char in pattern? */ | ||
| 421 | return (s == ms->src_end) ? s : NULL; /* check end of string */ | ||
| 422 | else goto dflt; | ||
| 423 | } | ||
| 424 | default: dflt: { /* it is a pattern item */ | ||
| 425 | const char *ep = classend(ms, p); /* points to what is next */ | 425 | const char *ep = classend(ms, p); /* points to what is next */ |
| 426 | int m = s<ms->src_end && singlematch(uchar(*s), p, ep); | 426 | int m = s<ms->src_end && singlematch(uchar(*s), p, ep); |
| 427 | switch (*ep) { | 427 | switch (*ep) { |
