| 13956 | |
| 13957 | |
| 13958 | static const char *matchbalance (MatchState *ms, const char *s, |
| 13959 | const char *p) { |
| 13960 | if (*p == 0 || *(p+1) == 0) |
| 13961 | luaL_error(ms->L, "unbalanced pattern"); |
| 13962 | if (*s != *p) return NULL; |
| 13963 | else { |
| 13964 | int b = *p; |
| 13965 | int e = *(p+1); |
| 13966 | int cont = 1; |
| 13967 | while (++s < ms->src_end) { |
| 13968 | if (*s == e) { |
| 13969 | if (--cont == 0) return s+1; |
| 13970 | } |
| 13971 | else if (*s == b) cont++; |
| 13972 | } |
| 13973 | } |
| 13974 | return NULL; /* string ends out of balance */ |
| 13975 | } |
| 13976 | |
| 13977 | |
| 13978 | static const char *max_expand (MatchState *ms, const char *s, |