MCPcopy Create free account
hub / github.com/F-Stack/f-stack / match

Function match

freebsd/contrib/openzfs/module/lua/lstrlib.c:421–521  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

419
420
421static const char *match (MatchState *ms, const char *s, const char *p) {
422 if (ms->matchdepth-- == 0)
423 luaL_error(ms->L, "pattern too complex");
424 init: /* using goto's to optimize tail recursion */
425 if (p != ms->p_end) { /* end of pattern? */
426 switch (*p) {
427 case '(': { /* start capture */
428 if (*(p + 1) == ')') /* position capture? */
429 s = start_capture(ms, s, p + 2, CAP_POSITION);
430 else
431 s = start_capture(ms, s, p + 1, CAP_UNFINISHED);
432 break;
433 }
434 case ')': { /* end capture */
435 s = end_capture(ms, s, p + 1);
436 break;
437 }
438 case '$': {
439 if ((p + 1) != ms->p_end) /* is the `$' the last char in pattern? */
440 goto dflt; /* no; go to default */
441 s = (s == ms->src_end) ? s : NULL; /* check end of string */
442 break;
443 }
444 case L_ESC: { /* escaped sequences not in the format class[*+?-]? */
445 switch (*(p + 1)) {
446 case 'b': { /* balanced string? */
447 s = matchbalance(ms, s, p + 2);
448 if (s != NULL) {
449 p += 4; goto init; /* return match(ms, s, p + 4); */
450 } /* else fail (s == NULL) */
451 break;
452 }
453 case 'f': { /* frontier? */
454 const char *ep; char previous;
455 p += 2;
456 if (*p != '[')
457 luaL_error(ms->L, "missing " LUA_QL("[") " after "
458 LUA_QL("%%f") " in pattern");
459 ep = classend(ms, p); /* points to what is next */
460 previous = (s == ms->src_init) ? '\0' : *(s - 1);
461 if (!matchbracketclass(uchar(previous), p, ep - 1) &&
462 matchbracketclass(uchar(*s), p, ep - 1)) {
463 p = ep; goto init; /* return match(ms, s, ep); */
464 }
465 s = NULL; /* match failed */
466 break;
467 }
468 case '0': case '1': case '2': case '3':
469 case '4': case '5': case '6': case '7':
470 case '8': case '9': { /* capture results (%0-%9)? */
471 s = match_capture(ms, s, uchar(*(p + 1)));
472 if (s != NULL) {
473 p += 2; goto init; /* return match(ms, s, p + 2) */
474 }
475 break;
476 }
477 default: goto dflt;
478 }

Callers 7

max_expandFunction · 0.70
min_expandFunction · 0.70
start_captureFunction · 0.70
end_captureFunction · 0.70
str_find_auxFunction · 0.70
gmatch_auxFunction · 0.70
str_gsubFunction · 0.70

Calls 10

luaL_errorFunction · 0.70
start_captureFunction · 0.70
end_captureFunction · 0.70
matchbalanceFunction · 0.70
classendFunction · 0.70
matchbracketclassFunction · 0.70
match_captureFunction · 0.70
singlematchFunction · 0.70
max_expandFunction · 0.70
min_expandFunction · 0.70

Tested by

no test coverage detected