MCPcopy Create free account
hub / github.com/CppCXY/EmmyLuaCodeStyle / add_s

Function add_s

3rd/lua-5.4.3/src/lstrlib.c:871–898  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers 1

add_valueFunction · 0.85

Calls 5

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

Tested by

no test coverage detected