MCPcopy Create free account
hub / github.com/Achain-Dev/Achain / match

Function match

src/Chain/libraries/glua/lstrlib.cpp:436–537  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

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.85
start_captureFunction · 0.85
end_captureFunction · 0.85
matchbalanceFunction · 0.85
classendFunction · 0.85
matchbracketclassFunction · 0.85
match_captureFunction · 0.85
singlematchFunction · 0.85
max_expandFunction · 0.85
min_expandFunction · 0.85

Tested by

no test coverage detected