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

Function add_s

extlibs/lua/src/lstrlib.c:868–895  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

866
867
868static void add_s (MatchState *ms, luaL_Buffer *b, const char *s,
869 const char *e) {
870 size_t l;
871 lua_State *L = ms->L;
872 const char *news = lua_tolstring(L, 3, &l);
873 const char *p;
874 while ((p = (char *)memchr(news, L_ESC, l)) != NULL) {
875 luaL_addlstring(b, news, p - news);
876 p++; /* skip ESC */
877 if (*p == L_ESC) /* '%%' */
878 luaL_addchar(b, *p);
879 else if (*p == '0') /* '%0' */
880 luaL_addlstring(b, s, e - s);
881 else if (isdigit(uchar(*p))) { /* '%n' */
882 const char *cap;
883 ptrdiff_t resl = get_onecapture(ms, *p - '1', s, e, &cap);
884 if (resl == CAP_POSITION)
885 luaL_addvalue(b); /* add position to accumulated result */
886 else
887 luaL_addlstring(b, cap, resl);
888 }
889 else
890 luaL_error(L, "invalid use of '%c' in replacement string", L_ESC);
891 l -= p + 1 - news;
892 news = p + 1;
893 }
894 luaL_addlstring(b, news, l);
895}
896
897
898/*

Callers 1

add_valueFunction · 0.85

Calls 5

lua_tolstringFunction · 0.85
get_onecaptureFunction · 0.85
luaL_errorFunction · 0.85
luaL_addlstringFunction · 0.70
luaL_addvalueFunction · 0.70

Tested by

no test coverage detected