MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / luaL_gsub

Function luaL_gsub

deps/lua/src/lauxlib.c:340–354  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

338
339
340LUALIB_API const char *luaL_gsub (lua_State *L, const char *s, const char *p,
341 const char *r) {
342 const char *wild;
343 size_t l = strlen(p);
344 luaL_Buffer b;
345 luaL_buffinit(L, &b);
346 while ((wild = strstr(s, p)) != NULL) {
347 luaL_addlstring(&b, s, wild - s); /* push prefix */
348 luaL_addstring(&b, r); /* push replacement in place of pattern */
349 s = wild + l; /* continue after `p' */
350 }
351 luaL_addstring(&b, s); /* push last suffix */
352 luaL_pushresult(&b);
353 return lua_tostring(L, -1);
354}
355
356
357LUALIB_API const char *luaL_findtable (lua_State *L, int idx,

Callers 4

setprogdirFunction · 0.85
findfileFunction · 0.85
mkfuncnameFunction · 0.85
setpathFunction · 0.85

Calls 4

luaL_buffinitFunction · 0.85
luaL_addlstringFunction · 0.85
luaL_addstringFunction · 0.85
luaL_pushresultFunction · 0.85

Tested by

no test coverage detected