| 526 | |
| 527 | |
| 528 | static const char *lmemfind (const char *s1, size_t l1, |
| 529 | const char *s2, size_t l2) { |
| 530 | if (l2 == 0) return s1; /* empty strings are everywhere */ |
| 531 | else if (l2 > l1) return NULL; /* avoids a negative 'l1' */ |
| 532 | else { |
| 533 | const char *init; /* to search for a '*s2' inside 's1' */ |
| 534 | l2--; /* 1st char will be checked by 'memchr' */ |
| 535 | l1 = l1-l2; /* 's2' cannot be found after that */ |
| 536 | while (l1 > 0 && (init = (const char *)memchr(s1, *s2, l1)) != NULL) { |
| 537 | init++; /* 1st char is already checked */ |
| 538 | if (memcmp(init, s2+1, l2) == 0) |
| 539 | return init-1; |
| 540 | else { /* correct 'l1' and 's1' to try again */ |
| 541 | l1 -= init-s1; |
| 542 | s1 = init; |
| 543 | } |
| 544 | } |
| 545 | return NULL; /* not found */ |
| 546 | } |
| 547 | } |
| 548 | |
| 549 | |
| 550 | static void push_onecapture (MatchState *ms, int i, const char *s, |