| 701 | |
| 702 | |
| 703 | static 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 | |
| 731 | static void add_value (MatchState *ms, luaL_Buffer *b, const char *s, |
no test coverage detected