| 339 | |
| 340 | |
| 341 | static const char *matchbalance (MatchState *ms, const char *s, |
| 342 | const char *p) { |
| 343 | if (p >= ms->p_end - 1) |
| 344 | luaL_error(ms->L, "malformed pattern (missing arguments to '%%b')"); |
| 345 | if (*s != *p) return NULL; |
| 346 | else { |
| 347 | int b = *p; |
| 348 | int e = *(p+1); |
| 349 | int cont = 1; |
| 350 | while (++s < ms->src_end) { |
| 351 | if (*s == e) { |
| 352 | if (--cont == 0) return s+1; |
| 353 | } |
| 354 | else if (*s == b) cont++; |
| 355 | } |
| 356 | } |
| 357 | return NULL; /* string ends out of balance */ |
| 358 | } |
| 359 | |
| 360 | |
| 361 | static const char *max_expand (MatchState *ms, const char *s, |