| 442 | |
| 443 | |
| 444 | static const char *lmemfind (const char *s1, size_t l1, |
| 445 | const char *s2, size_t l2) { |
| 446 | if (l2 == 0) return s1; /* empty strings are everywhere */ |
| 447 | else if (l2 > l1) return NULL; /* avoids a negative `l1' */ |
| 448 | else { |
| 449 | const char *init; /* to search for a `*s2' inside `s1' */ |
| 450 | l2--; /* 1st char will be checked by `memchr' */ |
| 451 | l1 = l1-l2; /* `s2' cannot be found after that */ |
| 452 | while (l1 > 0 && (init = (const char *)memchr(s1, *s2, l1)) != NULL) { |
| 453 | init++; /* 1st char is already checked */ |
| 454 | if (memcmp(init, s2+1, l2) == 0) |
| 455 | return init-1; |
| 456 | else { /* correct `l1' and `s1' to try again */ |
| 457 | l1 -= init-s1; |
| 458 | s1 = init; |
| 459 | } |
| 460 | } |
| 461 | return NULL; /* not found */ |
| 462 | } |
| 463 | } |
| 464 | |
| 465 | |
| 466 | static void push_onecapture (MatchState *ms, int i, const char *s, |