MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / get_onecapture

Function get_onecapture

lib/lua/src/lstrlib.c:702–719  ·  view source on GitHub ↗

** 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. */

Source from the content-addressed store, hash-verified

700** (a position), push it on the stack and return CAP_POSITION.
701*/
702static 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/*

Callers 2

push_onecaptureFunction · 0.85
add_sFunction · 0.85

Calls 2

luaL_errorFunction · 0.85
lua_pushintegerFunction · 0.85

Tested by

no test coverage detected