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