| 323 | |
| 324 | |
| 325 | static const char *matchbalance (MatchState *ms, const char *s, |
| 326 | const char *p) { |
| 327 | if (p >= ms->p_end - 1) |
| 328 | luaL_error(ms->L, "malformed pattern " |
| 329 | "(missing arguments to " LUA_QL("%%b") ")"); |
| 330 | if (*s != *p) return NULL; |
| 331 | else { |
| 332 | int b = *p; |
| 333 | int e = *(p+1); |
| 334 | int cont = 1; |
| 335 | while (++s < ms->src_end) { |
| 336 | if (*s == e) { |
| 337 | if (--cont == 0) return s+1; |
| 338 | } |
| 339 | else if (*s == b) cont++; |
| 340 | } |
| 341 | } |
| 342 | return NULL; /* string ends out of balance */ |
| 343 | } |
| 344 | |
| 345 | |
| 346 | static const char *max_expand (MatchState *ms, const char *s, |