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