MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / matchbalance

Function matchbalance

deps/lua/src/lstrlib.c:281–298  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

279
280
281static const char *matchbalance (MatchState *ms, const char *s,
282 const char *p) {
283 if (*p == 0 || *(p+1) == 0)
284 luaL_error(ms->L, "unbalanced pattern");
285 if (*s != *p) return NULL;
286 else {
287 int b = *p;
288 int e = *(p+1);
289 int cont = 1;
290 while (++s < ms->src_end) {
291 if (*s == e) {
292 if (--cont == 0) return s+1;
293 }
294 else if (*s == b) cont++;
295 }
296 }
297 return NULL; /* string ends out of balance */
298}
299
300
301static 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