MCPcopy Create free account
hub / github.com/DFHack/dfhack / matchbalance

Function matchbalance

depends/lua/src/lstrlib.c:341–358  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers 1

matchFunction · 0.85

Calls 1

luaL_errorFunction · 0.85

Tested by

no test coverage detected