MCPcopy Create free account
hub / github.com/DFHack/dfhack / add_s

Function add_s

depends/lua/src/lstrlib.c:703–728  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

701
702
703static void add_s (MatchState *ms, luaL_Buffer *b, const char *s,
704 const char *e) {
705 size_t l, i;
706 lua_State *L = ms->L;
707 const char *news = lua_tolstring(L, 3, &l);
708 for (i = 0; i < l; i++) {
709 if (news[i] != L_ESC)
710 luaL_addchar(b, news[i]);
711 else {
712 i++; /* skip ESC */
713 if (!isdigit(uchar(news[i]))) {
714 if (news[i] != L_ESC)
715 luaL_error(L, "invalid use of '%c' in replacement string", L_ESC);
716 luaL_addchar(b, news[i]);
717 }
718 else if (news[i] == '0')
719 luaL_addlstring(b, s, e - s);
720 else {
721 push_onecapture(ms, news[i] - '1', s, e);
722 luaL_tolstring(L, -1, NULL); /* if number, convert it to string */
723 lua_remove(L, -2); /* remove original value */
724 luaL_addvalue(b); /* add capture to accumulated result */
725 }
726 }
727 }
728}
729
730
731static void add_value (MatchState *ms, luaL_Buffer *b, const char *s,

Callers 1

add_valueFunction · 0.85

Calls 6

lua_tolstringFunction · 0.85
luaL_errorFunction · 0.85
luaL_addlstringFunction · 0.85
push_onecaptureFunction · 0.85
luaL_tolstringFunction · 0.85
luaL_addvalueFunction · 0.85

Tested by

no test coverage detected