diff options
| -rw-r--r-- | lstrlib.c | 22 |
1 files changed, 11 insertions, 11 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lstrlib.c,v 1.109 2004/12/01 15:46:06 roberto Exp roberto $ | 2 | ** $Id: lstrlib.c,v 1.110 2005/03/08 20:10:05 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 | */ |
| @@ -176,7 +176,7 @@ typedef struct MatchState { | |||
| 176 | } MatchState; | 176 | } MatchState; |
| 177 | 177 | ||
| 178 | 178 | ||
| 179 | #define ESC '%' | 179 | #define L_ESC '%' |
| 180 | #define SPECIALS "^$*+?.([%-" | 180 | #define SPECIALS "^$*+?.([%-" |
| 181 | 181 | ||
| 182 | 182 | ||
| @@ -198,7 +198,7 @@ static int capture_to_close (MatchState *ms) { | |||
| 198 | 198 | ||
| 199 | static const char *classend (MatchState *ms, const char *p) { | 199 | static const char *classend (MatchState *ms, const char *p) { |
| 200 | switch (*p++) { | 200 | switch (*p++) { |
| 201 | case ESC: { | 201 | case L_ESC: { |
| 202 | if (*p == '\0') | 202 | if (*p == '\0') |
| 203 | luaL_error(ms->L, "malformed pattern (ends with `%%')"); | 203 | luaL_error(ms->L, "malformed pattern (ends with `%%')"); |
| 204 | return p+1; | 204 | return p+1; |
| @@ -208,7 +208,7 @@ static const char *classend (MatchState *ms, const char *p) { | |||
| 208 | do { /* look for a `]' */ | 208 | do { /* look for a `]' */ |
| 209 | if (*p == '\0') | 209 | if (*p == '\0') |
| 210 | luaL_error(ms->L, "malformed pattern (missing `]')"); | 210 | luaL_error(ms->L, "malformed pattern (missing `]')"); |
| 211 | if (*(p++) == ESC && *p != '\0') | 211 | if (*(p++) == L_ESC && *p != '\0') |
| 212 | p++; /* skip escapes (e.g. `%]') */ | 212 | p++; /* skip escapes (e.g. `%]') */ |
| 213 | } while (*p != ']'); | 213 | } while (*p != ']'); |
| 214 | return p+1; | 214 | return p+1; |
| @@ -246,7 +246,7 @@ static int matchbracketclass (int c, const char *p, const char *ec) { | |||
| 246 | p++; /* skip the `^' */ | 246 | p++; /* skip the `^' */ |
| 247 | } | 247 | } |
| 248 | while (++p < ec) { | 248 | while (++p < ec) { |
| 249 | if (*p == ESC) { | 249 | if (*p == L_ESC) { |
| 250 | p++; | 250 | p++; |
| 251 | if (match_class(c, uchar(*p))) | 251 | if (match_class(c, uchar(*p))) |
| 252 | return sig; | 252 | return sig; |
| @@ -265,7 +265,7 @@ static int matchbracketclass (int c, const char *p, const char *ec) { | |||
| 265 | static int singlematch (int c, const char *p, const char *ep) { | 265 | static int singlematch (int c, const char *p, const char *ep) { |
| 266 | switch (*p) { | 266 | switch (*p) { |
| 267 | case '.': return 1; /* matches any char */ | 267 | case '.': return 1; /* matches any char */ |
| 268 | case ESC: return match_class(c, uchar(*(p+1))); | 268 | case L_ESC: return match_class(c, uchar(*(p+1))); |
| 269 | case '[': return matchbracketclass(c, p, ep-1); | 269 | case '[': return matchbracketclass(c, p, ep-1); |
| 270 | default: return (uchar(*p) == c); | 270 | default: return (uchar(*p) == c); |
| 271 | } | 271 | } |
| @@ -371,7 +371,7 @@ static const char *match (MatchState *ms, const char *s, const char *p) { | |||
| 371 | case ')': { /* end capture */ | 371 | case ')': { /* end capture */ |
| 372 | return end_capture(ms, s, p+1); | 372 | return end_capture(ms, s, p+1); |
| 373 | } | 373 | } |
| 374 | case ESC: { | 374 | case L_ESC: { |
| 375 | switch (*(p+1)) { | 375 | switch (*(p+1)) { |
| 376 | case 'b': { /* balanced string? */ | 376 | case 'b': { /* balanced string? */ |
| 377 | s = matchbalance(ms, s, p+2); | 377 | s = matchbalance(ms, s, p+2); |
| @@ -567,7 +567,7 @@ static void add_s (MatchState *ms, luaL_Buffer *b, | |||
| 567 | size_t l = lua_strlen(L, 3); | 567 | size_t l = lua_strlen(L, 3); |
| 568 | size_t i; | 568 | size_t i; |
| 569 | for (i=0; i<l; i++) { | 569 | for (i=0; i<l; i++) { |
| 570 | if (news[i] != ESC) | 570 | if (news[i] != L_ESC) |
| 571 | luaL_putchar(b, news[i]); | 571 | luaL_putchar(b, news[i]); |
| 572 | else { | 572 | else { |
| 573 | i++; /* skip ESC */ | 573 | i++; /* skip ESC */ |
| @@ -682,7 +682,7 @@ static const char *scanformat (lua_State *L, const char *strfrmt, | |||
| 682 | luaL_error(L, "invalid format (width or precision too long)"); | 682 | luaL_error(L, "invalid format (width or precision too long)"); |
| 683 | if (p-strfrmt+2 > MAX_FORMAT) /* +2 to include `%' and the specifier */ | 683 | if (p-strfrmt+2 > MAX_FORMAT) /* +2 to include `%' and the specifier */ |
| 684 | luaL_error(L, "invalid format (too long)"); | 684 | luaL_error(L, "invalid format (too long)"); |
| 685 | form[0] = ESC; | 685 | form[0] = L_ESC; |
| 686 | strncpy(form+1, strfrmt, p-strfrmt+1); | 686 | strncpy(form+1, strfrmt, p-strfrmt+1); |
| 687 | form[p-strfrmt+2] = 0; | 687 | form[p-strfrmt+2] = 0; |
| 688 | return p; | 688 | return p; |
| @@ -697,9 +697,9 @@ static int str_format (lua_State *L) { | |||
| 697 | luaL_Buffer b; | 697 | luaL_Buffer b; |
| 698 | luaL_buffinit(L, &b); | 698 | luaL_buffinit(L, &b); |
| 699 | while (strfrmt < strfrmt_end) { | 699 | while (strfrmt < strfrmt_end) { |
| 700 | if (*strfrmt != ESC) | 700 | if (*strfrmt != L_ESC) |
| 701 | luaL_putchar(&b, *strfrmt++); | 701 | luaL_putchar(&b, *strfrmt++); |
| 702 | else if (*++strfrmt == ESC) | 702 | else if (*++strfrmt == L_ESC) |
| 703 | luaL_putchar(&b, *strfrmt++); /* %% */ | 703 | luaL_putchar(&b, *strfrmt++); /* %% */ |
| 704 | else { /* format item */ | 704 | else { /* format item */ |
| 705 | char form[MAX_FORMAT]; /* to store the format (`%...') */ | 705 | char form[MAX_FORMAT]; /* to store the format (`%...') */ |
