| 784 | |
| 785 | |
| 786 | static void add_s(MatchState *ms, luaL_Buffer *b, const char *s, |
| 787 | const char *e) { |
| 788 | size_t l, i; |
| 789 | lua_State *L = ms->L; |
| 790 | const char *news = lua_tolstring(L, 3, &l); |
| 791 | for (i = 0; i < l; i++) { |
| 792 | if (news[i] != L_ESC) |
| 793 | luaL_addchar(b, news[i]); |
| 794 | else { |
| 795 | i++; /* skip ESC */ |
| 796 | if (!isdigit(uchar(news[i]))) { |
| 797 | if (news[i] != L_ESC) |
| 798 | luaL_error(L, "invalid use of '%c' in replacement string", L_ESC); |
| 799 | luaL_addchar(b, news[i]); |
| 800 | } |
| 801 | else if (news[i] == '0') |
| 802 | luaL_addlstring(b, s, e - s); |
| 803 | else { |
| 804 | push_onecapture(ms, news[i] - '1', s, e); |
| 805 | luaL_tolstring(L, -1, nullptr); /* if number, convert it to string */ |
| 806 | lua_remove(L, -2); /* remove original value */ |
| 807 | luaL_addvalue(b); /* add capture to accumulated result */ |
| 808 | } |
| 809 | } |
| 810 | } |
| 811 | } |
| 812 | |
| 813 | |
| 814 | static void add_value(MatchState *ms, luaL_Buffer *b, const char *s, |
no test coverage detected