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