| 279 | |
| 280 | |
| 281 | static const char *matchbalance (MatchState *ms, const char *s, |
| 282 | const char *p) { |
| 283 | if (*p == 0 || *(p+1) == 0) |
| 284 | luaL_error(ms->L, "unbalanced pattern"); |
| 285 | if (*s != *p) return NULL; |
| 286 | else { |
| 287 | int b = *p; |
| 288 | int e = *(p+1); |
| 289 | int cont = 1; |
| 290 | while (++s < ms->src_end) { |
| 291 | if (*s == e) { |
| 292 | if (--cont == 0) return s+1; |
| 293 | } |
| 294 | else if (*s == b) cont++; |
| 295 | } |
| 296 | } |
| 297 | return NULL; /* string ends out of balance */ |
| 298 | } |
| 299 | |
| 300 | |
| 301 | static const char *max_expand (MatchState *ms, const char *s, |