MCPcopy Create free account
hub / github.com/ObEngine/ObEngine / lmemfind

Function lmemfind

extlibs/lua/src/lstrlib.c:670–689  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

668
669
670static const char *lmemfind (const char *s1, size_t l1,
671 const char *s2, size_t l2) {
672 if (l2 == 0) return s1; /* empty strings are everywhere */
673 else if (l2 > l1) return NULL; /* avoids a negative 'l1' */
674 else {
675 const char *init; /* to search for a '*s2' inside 's1' */
676 l2--; /* 1st char will be checked by 'memchr' */
677 l1 = l1-l2; /* 's2' cannot be found after that */
678 while (l1 > 0 && (init = (const char *)memchr(s1, *s2, l1)) != NULL) {
679 init++; /* 1st char is already checked */
680 if (memcmp(init, s2+1, l2) == 0)
681 return init-1;
682 else { /* correct 'l1' and 's1' to try again */
683 l1 -= init-s1;
684 s1 = init;
685 }
686 }
687 return NULL; /* not found */
688 }
689}
690
691
692/*

Callers 1

str_find_auxFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected