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

Function str_gsub

third-party/lua-5.2.4/src/lstrlib.c:735–777  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

733
734
735static int str_gsub (lua_State *L) {
736 size_t srcl, lp;
737 const char *src = luaL_checklstring(L, 1, &srcl);
738 const char *p = luaL_checklstring(L, 2, &lp);
739 int tr = lua_type(L, 3);
740 size_t max_s = luaL_optinteger(L, 4, srcl+1);
741 int anchor = (*p == '^');
742 size_t n = 0;
743 MatchState ms;
744 luaL_Buffer b;
745 luaL_argcheck(L, tr == LUA_TNUMBER || tr == LUA_TSTRING ||
746 tr == LUA_TFUNCTION || tr == LUA_TTABLE, 3,
747 "string/function/table expected");
748 luaL_buffinit(L, &b);
749 if (anchor) {
750 p++; lp--; /* skip anchor character */
751 }
752 ms.L = L;
753 ms.matchdepth = MAXCCALLS;
754 ms.src_init = src;
755 ms.src_end = src+srcl;
756 ms.p_end = p + lp;
757 while (n < max_s) {
758 const char *e;
759 ms.level = 0;
760 lua_assert(ms.matchdepth == MAXCCALLS);
761 e = match(&ms, src, p);
762 if (e) {
763 n++;
764 add_value(&ms, &b, src, e, tr);
765 }
766 if (e && e>src) /* non empty match? */
767 src = e; /* skip it */
768 else if (src < ms.src_end)
769 luaL_addchar(&b, *src++);
770 else break;
771 if (anchor) break;
772 }
773 luaL_addlstring(&b, src, ms.src_end-src);
774 luaL_pushresult(&b);
775 lua_pushinteger(L, n); /* number of substitutions */
776 return 2;
777}
778
779/* }====================================================== */
780

Callers

nothing calls this directly

Calls 9

luaL_checklstringFunction · 0.70
lua_typeFunction · 0.70
luaL_optintegerFunction · 0.70
luaL_buffinitFunction · 0.70
matchFunction · 0.70
add_valueFunction · 0.70
luaL_addlstringFunction · 0.70
luaL_pushresultFunction · 0.70
lua_pushintegerFunction · 0.70

Tested by

no test coverage detected