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

Function str_find_aux

extlibs/lua/src/lstrlib.c:770–813  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

768
769
770static int str_find_aux (lua_State *L, int find) {
771 size_t ls, lp;
772 const char *s = luaL_checklstring(L, 1, &ls);
773 const char *p = luaL_checklstring(L, 2, &lp);
774 size_t init = posrelatI(luaL_optinteger(L, 3, 1), ls) - 1;
775 if (init > ls) { /* start after string's end? */
776 luaL_pushfail(L); /* cannot find anything */
777 return 1;
778 }
779 /* explicit request or no special characters? */
780 if (find && (lua_toboolean(L, 4) || nospecials(p, lp))) {
781 /* do a plain search */
782 const char *s2 = lmemfind(s + init, ls - init, p, lp);
783 if (s2) {
784 lua_pushinteger(L, (s2 - s) + 1);
785 lua_pushinteger(L, (s2 - s) + lp);
786 return 2;
787 }
788 }
789 else {
790 MatchState ms;
791 const char *s1 = s + init;
792 int anchor = (*p == '^');
793 if (anchor) {
794 p++; lp--; /* skip anchor character */
795 }
796 prepstate(&ms, L, s, ls, p, lp);
797 do {
798 const char *res;
799 reprepstate(&ms);
800 if ((res=match(&ms, s1, p)) != NULL) {
801 if (find) {
802 lua_pushinteger(L, (s1 - s) + 1); /* start */
803 lua_pushinteger(L, res - s); /* end */
804 return push_captures(&ms, NULL, 0) + 2;
805 }
806 else
807 return push_captures(&ms, s1, res);
808 }
809 } while (s1++ < ms.src_end && !anchor);
810 }
811 luaL_pushfail(L); /* not found */
812 return 1;
813}
814
815
816static int str_find (lua_State *L) {

Callers 2

str_findFunction · 0.85
str_matchFunction · 0.85

Calls 11

luaL_checklstringFunction · 0.85
posrelatIFunction · 0.85
luaL_optintegerFunction · 0.85
lua_tobooleanFunction · 0.85
nospecialsFunction · 0.85
lmemfindFunction · 0.85
lua_pushintegerFunction · 0.85
prepstateFunction · 0.85
reprepstateFunction · 0.85
push_capturesFunction · 0.85
matchFunction · 0.70

Tested by

no test coverage detected