MCPcopy Create free account
hub / github.com/EmmyLua/EmmyLuaDebugger / str_find_aux

Function str_find_aux

third-party/lua-5.4.6/src/lstrlib.c:773–816  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers 2

str_findFunction · 0.70
str_matchFunction · 0.70

Calls 11

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

Tested by

no test coverage detected