** get information about the i-th capture. If there are no captures ** and 'i==0', return information about the whole match, which ** is the range 's'..'e'. If the capture is a string, return ** its length and put its address in '*cap'. If it is an integer ** (a position), push it on the stack and return CAP_POSITION. */
| 700 | ** (a position), push it on the stack and return CAP_POSITION. |
| 701 | */ |
| 702 | static size_t get_onecapture (MatchState *ms, int i, const char *s, |
| 703 | const char *e, const char **cap) { |
| 704 | if (i >= ms->level) { |
| 705 | if (l_unlikely(i != 0)) |
| 706 | luaL_error(ms->L, "invalid capture index %%%d", i + 1); |
| 707 | *cap = s; |
| 708 | return e - s; |
| 709 | } |
| 710 | else { |
| 711 | ptrdiff_t capl = ms->capture[i].len; |
| 712 | *cap = ms->capture[i].init; |
| 713 | if (l_unlikely(capl == CAP_UNFINISHED)) |
| 714 | luaL_error(ms->L, "unfinished capture"); |
| 715 | else if (capl == CAP_POSITION) |
| 716 | lua_pushinteger(ms->L, (ms->capture[i].init - ms->src_init) + 1); |
| 717 | return capl; |
| 718 | } |
| 719 | } |
| 720 | |
| 721 | |
| 722 | /* |
no test coverage detected