MCPcopy Create free account
hub / github.com/Achain-Dev/Achain / str_gsub

Function str_gsub

src/Chain/libraries/glua/lstrlib.cpp:845–881  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

843
844
845static int str_gsub(lua_State *L) {
846 size_t srcl, lp;
847 const char *src = luaL_checklstring(L, 1, &srcl);
848 const char *p = luaL_checklstring(L, 2, &lp);
849 int tr = lua_type(L, 3);
850 lua_Integer max_s = luaL_optinteger(L, 4, srcl + 1);
851 int anchor = (*p == '^');
852 lua_Integer n = 0;
853 MatchState ms;
854 luaL_Buffer b;
855 luaL_argcheck(L, tr == LUA_TNUMBER || tr == LUA_TSTRING ||
856 tr == LUA_TFUNCTION || tr == LUA_TTABLE, 3,
857 "string/function/table expected");
858 luaL_buffinit(L, &b);
859 if (anchor) {
860 p++; lp--; /* skip anchor character */
861 }
862 prepstate(&ms, L, src, srcl, p, lp);
863 while (n < max_s) {
864 const char *e;
865 reprepstate(&ms);
866 if ((e = match(&ms, src, p)) != nullptr) {
867 n++;
868 add_value(&ms, &b, src, e, tr);
869 }
870 if (e && e > src) /* non empty match? */
871 src = e; /* skip it */
872 else if (src < ms.src_end)
873 luaL_addchar(&b, *src++);
874 else break;
875 if (anchor) break;
876 }
877 luaL_addlstring(&b, src, ms.src_end - src);
878 luaL_pushresult(&b);
879 lua_pushinteger(L, n); /* number of substitutions */
880 return 2;
881}
882
883/* }====================================================== */
884

Callers

nothing calls this directly

Calls 10

luaL_checklstringFunction · 0.85
lua_typeFunction · 0.85
luaL_buffinitFunction · 0.85
prepstateFunction · 0.85
reprepstateFunction · 0.85
luaL_addlstringFunction · 0.85
luaL_pushresultFunction · 0.85
lua_pushintegerFunction · 0.85
matchFunction · 0.70
add_valueFunction · 0.70

Tested by

no test coverage detected