| 481 | |
| 482 | |
| 483 | static const char *matchbalance (MatchState *ms, const char *s, |
| 484 | const char *p) { |
| 485 | if (p >= ms->p_end - 1) |
| 486 | luaL_error(ms->L, "malformed pattern (missing arguments to '%%b')"); |
| 487 | if (*s != *p) return NULL; |
| 488 | else { |
| 489 | int b = *p; |
| 490 | int e = *(p+1); |
| 491 | int cont = 1; |
| 492 | while (++s < ms->src_end) { |
| 493 | if (*s == e) { |
| 494 | if (--cont == 0) return s+1; |
| 495 | } |
| 496 | else if (*s == b) cont++; |
| 497 | } |
| 498 | } |
| 499 | return NULL; /* string ends out of balance */ |
| 500 | } |
| 501 | |
| 502 | |
| 503 | static const char *max_expand (MatchState *ms, const char *s, |