| 869 | |
| 870 | |
| 871 | static 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 | /* |
no test coverage detected