本文整理汇总了C++中push_captures函数的典型用法代码示例。如果您正苦于以下问题:C++ push_captures函数的具体用法?C++ push_captures怎么用?C++ push_captures使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了push_captures函数的19个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: str_find_aux
static int str_find_aux (lua_State *L, int find) {
size_t ls, lp;
const char *s = luaL_checklstring(L, 1, &ls);
const char *p = luaL_checklstring(L, 2, &lp);
size_t init = posrelat(luaL_optinteger(L, 3, 1), ls);
if (init < 1) init = 1;
else if (init > ls + 1) { /* start after string's end? */
lua_pushnil(L); /* cannot find anything */
return 1;
}
/* explicit request or no special characters? */
if (find && (lua_toboolean(L, 4) || nospecials(p, lp))) {
/* do a plain search */
const char *s2 = lmemfind(s + init - 1, ls - init + 1, p, lp);
if (s2) {
lua_pushinteger(L, s2 - s + 1);
lua_pushinteger(L, s2 - s + lp);
return 2;
}
}
else {
MatchState ms;
const char *s1 = s + init - 1;
int anchor = (*p == '^');
if (anchor) {
p++; lp--; /* skip anchor character */
}
ms.L = L;
ms.matchdepth = MAXCCALLS;
ms.src_init = s;
ms.src_end = s + ls;
ms.p_end = p + lp;
do {
const char *res;
ms.level = 0;
lua_assert(ms.matchdepth == MAXCCALLS);
if ((res=match(&ms, s1, p)) != NULL) {
if (find) {
lua_pushinteger(L, s1 - s + 1); /* start */
lua_pushinteger(L, res - s); /* end */
return push_captures(&ms, NULL, 0) + 2;
}
else
return push_captures(&ms, s1, res);
}
} while (s1++ < ms.src_end && !anchor);
}
lua_pushnil(L); /* not found */
return 1;
}
开发者ID:dgkang,项目名称:skynet_v0.1_with_notes,代码行数:50,代码来源:lstrlib.c
示例2: gfind_aux
static int gfind_aux (lua_State *L) {
MatchState ms;
const char *s = lua_tostring(L, lua_upvalueindex(1));
size_t ls = lua_strlen(L, lua_upvalueindex(1));
const char *p = lua_tostring(L, lua_upvalueindex(2));
unsigned int idx3 = lua_tonumber(L, lua_upvalueindex(3));
const char *src;
ms.L = L;
ms.src_init = s;
ms.src_end = s+ls;
for (src = s + idx3;
src <= ms.src_end;
src++) {
const char *e;
ms.level = 0;
if ((e = match(&ms, src, p)) != NULL) {
int newstart = e-s;
if (e == src) newstart++; /* empty match? go at least one position */
lua_pushnumber(L, (lua_Number)newstart);
lua_replace(L, lua_upvalueindex(3));
return push_captures(&ms, src, e);
}
}
return 0; /* not found */
}
开发者ID:TKr,项目名称:Wive-ng-rt8186,代码行数:25,代码来源:lstrlib.c
示例3: str_find
static void str_find (void)
{
char *s = luaL_check_string(1);
char *p = luaL_check_string(2);
long init = (long)luaL_opt_number(3, 1) - 1;
luaL_arg_check(0 <= init && init <= strlen(s), 3, "out of range");
if (lua_getparam(4) != LUA_NOOBJECT ||
strpbrk(p, SPECIALS) == NULL) { /* no special caracters? */
char *s2 = strstr(s+init, p);
if (s2) {
lua_pushnumber(s2-s+1);
lua_pushnumber(s2-s+strlen(p));
}
}
else {
int anchor = (*p == '^') ? (p++, 1) : 0;
char *s1=s+init;
do {
char *res;
if ((res=match(s1, p, 0)) != NULL) {
lua_pushnumber(s1-s+1); /* start */
lua_pushnumber(res-s); /* end */
push_captures();
return;
}
} while (*s1++ && !anchor);
}
}
开发者ID:Akagi201,项目名称:learning-lua,代码行数:28,代码来源:strlib.c
示例4: str_find
static void str_find (void)
{
int32 l;
const char *s = luaL_check_lstr(1, &l);
const char *p = luaL_check_string(2);
int32 init = posrelat((int32)luaL_opt_number(3, 1), l) - 1;
struct Capture cap;
luaL_arg_check(0 <= init && init <= l, 3, "out of range");
if (lua_getparam(4) != LUA_NOOBJECT ||
strpbrk(p, SPECIALS) == NULL) { /* no special characters? */
const char *s2 = strstr(s+init, p);
if (s2) {
lua_pushnumber(s2-s+1);
lua_pushnumber(s2-s+strlen(p));
return;
}
}
else {
int32 anchor = (*p == '^') ? (p++, 1) : 0;
const char *s1=s+init;
cap.src_end = s+l;
do {
const char *res;
cap.level = 0;
if ((res=match(s1, p, &cap)) != NULL) {
lua_pushnumber(s1-s+1); /* start */
lua_pushnumber(res-s); /* end */
push_captures(&cap);
return;
}
} while (s1++<cap.src_end && !anchor);
}
lua_pushnil(); /* if arrives here, it didn't find */
}
开发者ID:Botje,项目名称:residualvm-tools,代码行数:34,代码来源:lstrlib.cpp
示例5: str_find
static int str_find (lua_State *L) {
size_t l1, l2;
const char *s = luaL_check_lstr(L, 1, &l1);
const char *p = luaL_check_lstr(L, 2, &l2);
long init = posrelat(luaL_opt_long(L, 3, 1), l1) - 1;
struct Capture cap;
luaL_arg_check(L, 0 <= init && (size_t)init <= l1, 3, "out of range");
if (lua_gettop(L) > 3 || /* extra argument? */
strpbrk(p, SPECIALS) == NULL) { /* or no special characters? */
const char *s2 = lmemfind(s+init, l1-init, p, l2);
if (s2) {
lua_pushnumber(L, s2-s+1);
lua_pushnumber(L, s2-s+l2);
return 2;
}
}
else {
int anchor = (*p == '^') ? (p++, 1) : 0;
const char *s1=s+init;
cap.src_end = s+l1;
do {
const char *res;
cap.level = 0;
if ((res=match(L, s1, p, &cap)) != NULL) {
lua_pushnumber(L, s1-s+1); /* start */
lua_pushnumber(L, res-s); /* end */
return push_captures(L, &cap) + 2;
}
} while (s1++<cap.src_end && !anchor);
}
lua_pushnil(L); /* not found */
return 1;
}
开发者ID:BackupTheBerlios,项目名称:gltron-svn,代码行数:33,代码来源:lstrlib.c
示例6: add_value
static void add_value (MatchState *ms, luaL_Buffer *b, const char *s,
const char *e) {
lua_State *L = ms->L;
switch (lua_type(L, 3)) {
case LUA_TNUMBER:
case LUA_TSTRING: {
add_s(ms, b, s, e);
return;
}
case LUA_TFUNCTION: {
int n;
lua_pushvalue(L, 3);
n = push_captures(ms, s, e);
lua_call(L, n, 1);
break;
}
case LUA_TTABLE: {
push_onecapture(ms, 0, s, e);
lua_gettable(L, 3);
break;
}
default: {
luaL_argerror(L, 3, "string/function/table expected");
return;
}
}
if (!lua_toboolean(L, -1)) { /* nil or false? */
lua_pop(L, 1);
lua_pushlstring(L, s, e - s); /* keep original text */
}
else if (!lua_isstring(L, -1))
luaL_error(L, "invalid replacement value (a %s)", luaL_typename(L, -1));
luaL_addvalue(b); /* add result to accumulator */
}
开发者ID:aronarts,项目名称:FireNET,代码行数:34,代码来源:lstrlib.c
示例7: add_s
static void add_s (MatchState *ms, luaL_Buffer *b,
const lua_WChar *s, const lua_WChar *e) {
lua_State *L = ms->L;
if (lua_iswstring(L, 3)) {
const lua_WChar *news = lua_towstring(L, 3);
size_t l = lua_strlen(L, 3);
size_t i;
for (i=0; i<l; i++) {
if (news[i] != ESC)
luaL_putwchar(b, news[i]);
else {
i++; /* skip ESC */
if (!iswdigit(news[i]))
luaL_putwchar(b, news[i]);
else {
int level = check_capture(ms, news[i]);
push_onecapture(ms, level);
luaL_addvalue(b); /* add capture to accumulated result */
}
}
}
}
else { /* is a function */
int n;
lua_pushvalue(L, 3);
n = push_captures(ms, s, e);
lua_call(L, n, 1);
if (lua_iswstring(L, -1))
luaL_addvalue(b); /* add return to accumulated result */
else
lua_pop(L, 1); /* function result is not a string: pop it */
}
}
开发者ID:anissen,项目名称:WikiAdventure,代码行数:33,代码来源:lwstrlib.c
示例8: str_find_aux
static int
str_find_aux(struct match_state *ms, const char *pattern, const char *string,
struct str_find *sm, size_t nsm, off_t init)
{
size_t ls = strlen(string);
size_t lp = strlen(pattern);
const char *s = string;
const char *p = pattern;
const char *s1, *s2;
int anchor, i;
if (init < 0)
init = 0;
else if (init > (off_t)ls)
return match_error(ms, "starting after string's end");
s1 = s + init;
if (nospecials(p, lp)) {
/* do a plain search */
s2 = lmemfind(s1, ls - (size_t)init, p, lp);
if (s2 == NULL)
return (0);
i = 0;
sm[i].sm_so = 0;
sm[i].sm_eo = (off_t)ls;
if (nsm > 1) {
i++;
sm[i].sm_so = s2 - s;
sm[i].sm_eo = (off_t)((s2 - s) + (off_t)lp);
}
return (i + 1);
}
anchor = (*p == '^');
if (anchor) {
p++;
lp--; /* skip anchor character */
}
ms->maxcaptures = (int)((nsm > MAXCAPTURES ? MAXCAPTURES : nsm) - 1);
ms->matchdepth = MAXCCALLS;
ms->repetitioncounter = MAXREPETITION;
ms->src_init = s;
ms->src_end = s + ls;
ms->p_end = p + lp;
do {
const char *res;
ms->level = 0;
if ((res = match(ms, s1, p)) != NULL) {
sm->sm_so = 0;
sm->sm_eo = (off_t)ls;
return push_captures(ms, s1, res, sm + 1, nsm - 1) + 1;
} else if (ms->error != NULL) {
return 0;
}
} while (s1++ < ms->src_end && !anchor);
return 0;
}
开发者ID:Frankie-666,项目名称:lwan,代码行数:60,代码来源:patterns.c
示例9: gmatch_aux
static int gmatch_aux (lua_State *L) {
MatchState ms;
size_t ls, lp;
const char *s = lua_tolstring(L, lua_upvalueindex(1), &ls);
const char *p = lua_tolstring(L, lua_upvalueindex(2), &lp);
const char *src;
ms.L = L;
ms.matchdepth = MAXCCALLS;
ms.src_init = s;
ms.src_end = s+ls;
ms.p_end = p + lp;
for (src = s + (size_t)lua_tointeger(L, lua_upvalueindex(3));
src <= ms.src_end;
src++) {
const char *e;
ms.level = 0;
lua_assert(ms.matchdepth == MAXCCALLS);
if ((e = match(&ms, src, p)) != NULL) {
lua_Integer newstart = e-s;
if (e == src) newstart++; /* empty match? go at least one position */
lua_pushinteger(L, newstart);
lua_replace(L, lua_upvalueindex(3));
return push_captures(&ms, src, e);
}
}
return 0; /* not found */
}
开发者ID:dgkang,项目名称:skynet_v0.1_with_notes,代码行数:27,代码来源:lstrlib.c
示例10: add_s
static void add_s (lua_State *L, luaL_Buffer *b, struct Capture *cap) {
if (lua_isstring(L, 3)) {
const char *news = lua_tostring(L, 3);
size_t l = lua_strlen(L, 3);
size_t i;
for (i=0; i<l; i++) {
if (news[i] != ESC)
luaL_putchar(b, news[i]);
else {
i++; /* skip ESC */
if (!isdigit((unsigned char)news[i]))
luaL_putchar(b, news[i]);
else {
int level = check_capture(L, news[i], cap);
luaL_addlstring(b, cap->capture[level].init, cap->capture[level].len);
}
}
}
}
else { /* is a function */
int n;
lua_pushvalue(L, 3);
n = push_captures(L, cap);
lua_rawcall(L, n, 1);
if (lua_isstring(L, -1))
luaL_addvalue(b); /* add return to accumulated result */
else
lua_pop(L, 1); /* function result is not a string: pop it */
}
}
开发者ID:BackupTheBerlios,项目名称:gltron-svn,代码行数:30,代码来源:lstrlib.c
示例11: add_value
static void add_value (MatchState *ms, luaL_Buffer *b, const char *s,
const char *e, int tr, int table) {
lua_State *L = ms->L;
switch (tr) {
case LUA_TFUNCTION: {
int n;
lua_pushvalue(L, 3);
if (table) n = build_result_table(ms, s, e); /* EXT */
else n = push_captures(ms, s, e);
lua_call(L, n, 1);
break;
}
case LUA_TTABLE: {
push_onecapture(ms, 0, s, e);
lua_gettable(L, 3);
break;
}
default: { /* LUA_TNUMBER or LUA_TSTRING */
add_s(ms, b, s, e);
return;
}
}
if (!lua_toboolean(L, -1)) { /* nil or false? */
lua_pop(L, 1);
lua_pushlstring(L, s, e - s); /* keep original text */
}
else if (!lua_isstring(L, -1))
luaL_error(L, "invalid replacement value (a %s)", luaL_typename(L, -1));
luaL_addvalue(b); /* add result to accumulator */
}
开发者ID:jcgoble3,项目名称:lua-matchext,代码行数:30,代码来源:matchext.c
示例12: str_find_aux
static int str_find_aux (lua_State *L, int mode) { /* EXT */
size_t ls, lp;
const char *s = luaL_checklstring(L, 1, &ls);
const char *p = luaL_checklstring(L, 2, &lp);
lua_Integer init = posrelat(luaL_optinteger(L, 3, 1), ls);
if (init < 1) init = 1;
else if (init > (lua_Integer)ls + 1) { /* start after string's end? */
lua_pushnil(L); /* cannot find anything */
return 1;
}
/* explicit request or no special characters? */ /* EXT */
if (mode == MODE_FIND && (lua_toboolean(L, 4) || nospecials(p, lp))) {
/* do a plain search */
const char *s2 = lmemfind(s + init - 1, ls - (size_t)init + 1, p, lp);
if (s2) {
lua_pushinteger(L, (s2 - s) + 1);
lua_pushinteger(L, (s2 - s) + lp);
return 2;
}
}
else {
MatchState ms;
const char *s1 = s + init - 1;
int anchor = (*p == '^');
prepstate(&ms, L, s, ls, p, lp); /* EXT (moved before anchor check) */
if (anchor)
p++; /* skip anchor character */ /* EXT */
do {
const char *res;
reprepstate(&ms);
if ((res=match(&ms, s1, p)) != NULL) {
if (mode == MODE_FIND) { /* EXT */
lua_pushinteger(L, (s1 - s) + 1); /* start */
lua_pushinteger(L, res - s); /* end */
return push_captures(&ms, NULL, 0) + 2;
}
else if (mode == MODE_MATCH) /* EXT */
return push_captures(&ms, s1, res);
else { /* EXT */
return build_result_table(&ms, s1, res);
}
}
} while (s1++ < ms.src_end && !anchor);
}
lua_pushnil(L); /* not found */
return 1;
}
开发者ID:jcgoble3,项目名称:lua-matchext,代码行数:47,代码来源:matchext.c
示例13: str_find_aux
static int str_find_aux (lua_State *L, int find) {
size_t l1, l2;
const char *s = luaL_checklstring(L, 1, &l1);
const char *p = luaL_checklstring(L, 2, &l2);
ptrdiff_t init = posrelat(luaL_optinteger(L, 3, 1), l1) - 1;
if (init < 0) init = 0;
else if ((size_t)(init) > l1) init = (ptrdiff_t)l1;
if (find && (lua_toboolean(L, 4) || /* explicit request? */
strpbrk(p, SPECIALS) == NULL)) { /* or no special characters? */
/* do a plain search */
const char *s2 = lmemfind(s+init, l1-init, p, l2);
if (s2) {
lua_pushinteger(L, s2-s+1);
lua_pushinteger(L, s2-s+l2);
return 2;
}
}
else {
MatchState ms;
int anchor = (*p == '^') ? (p++, 1) : 0;
const char *s1=s+init;
ms.L = L;
ms.src_init = s;
ms.src_end = s+l1;
do {
const char *res;
ms.level = 0;
if ((res=match(&ms, s1, p)) != NULL) {
if (find) {
lua_pushinteger(L, s1-s+1); /* start */
lua_pushinteger(L, res-s); /* end */
return push_captures(&ms, NULL, 0) + 2;
}
else
return push_captures(&ms, s1, res);
}
} while (s1++ < ms.src_end && !anchor);
}
lua_pushnil(L); /* not found */
return 1;
}
开发者ID:aronarts,项目名称:FireNET,代码行数:41,代码来源:lstrlib.c
示例14: gmatch_aux
static int gmatch_aux (lua_State *L) {
GMatchState *gm = (GMatchState *)lua_touserdata(L, lua_upvalueindex(3));
const char *src;
gm->ms.L = L;
for (src = gm->src; src <= gm->ms.src_end; src++) {
const char *e;
reprepstate(&gm->ms);
if ((e = match(&gm->ms, src, gm->p)) != NULL && e != gm->lastmatch) {
gm->src = gm->lastmatch = e;
return push_captures(&gm->ms, src, e);
}
}
return 0; /* not found */
}
开发者ID:guodawei,项目名称:lua,代码行数:14,代码来源:lstrlib.c
示例15: gfind_aux
//mod by nirenr
static int gfind_aux (lua_State *L) {
size_t ls, lp;
const char *s = lua_tolstring(L, lua_upvalueindex(1), &ls);
const char *p = lua_tolstring(L, lua_upvalueindex(2), &lp);
lua_Integer init = posrelat(luaL_optinteger(L, lua_upvalueindex(3), 1), ls);
if (init < 1) init = 1;
else if (init > (lua_Integer)ls + 1) { /* start after string's end? */
return 0; /* cannot find anything */
}
/* explicit request or no special characters? */
if (lua_toboolean(L, lua_upvalueindex(4)) || nospecials(p, lp)) {
/* do a plain search */
const char *s2 = lmemfind(s + init - 1, ls - (size_t)init + 1, p, lp);
if (s2) {
lua_pushinteger(L, (s2 - s) + 1);
lua_pushinteger(L, (s2 - s) + lp);
lua_pushinteger(L,(s2 - s) + lp + 1);
lua_replace(L, lua_upvalueindex(3));
return 2;
}
}
else {
MatchState ms;
const char *s1 = s + init - 1;
int anchor = (*p == '^');
if (anchor) {
p++; lp--; /* skip anchor character */
}
ms.L = L;
ms.matchdepth = MAXCCALLS;
ms.src_init = s;
ms.src_end = s + ls;
ms.p_end = p + lp;
do {
const char *res;
ms.level = 0;
lua_assert(ms.matchdepth == MAXCCALLS);
if ((res=match(&ms, s1, p)) != NULL) {
lua_pushinteger(L, (s1 - s) + 1); /* start */
lua_pushinteger(L, res - s); /* end */
lua_pushinteger(L, res - s + 1);
lua_replace(L, lua_upvalueindex(3));
return push_captures(&ms, NULL, 0) + 2;
}
} while (s1++ < ms.src_end && !anchor);
}
return 0; /* not found */
}
开发者ID:cthunter,项目名称:AndroLua_pro,代码行数:49,代码来源:lstrlib.c
示例16: gmatch_aux
static int gmatch_aux (lua_State *L) {
GMatchState *gm = (GMatchState *)lua_touserdata(L, lua_upvalueindex(3));
const char *src;
for (src = gm->src; src <= gm->ms.src_end; src++) {
const char *e;
reprepstate(&gm->ms);
if ((e = match(&gm->ms, src, gm->p)) != NULL) {
if (e == src) /* empty match? */
gm->src =src + 1; /* go at least one position */
else
gm->src = e;
return push_captures(&gm->ms, src, e);
}
}
return 0; /* not found */
}
开发者ID:raistlin,项目名称:widelands,代码行数:16,代码来源:lstrlib.c
示例17: add_s
static void add_s (lua_Object newp, struct Capture *cap)
{
if (lua_isstring(newp)) {
const char *news = lua_getstring(newp);
int32 l = lua_strlen(newp);
int32 i;
for (i=0; i<l; i++) {
if (news[i] != ESC)
luaL_addchar(news[i]);
else {
i++; /* skip ESC */
if (!isdigit((byte)news[i]))
luaL_addchar(news[i]);
else {
int32 level = check_cap(news[i], cap);
addnchar(cap->capture[level].init, cap->capture[level].len);
}
}
}
}
else { /* is a function */
lua_Object res;
int32 status;
int32 oldbuff;
lua_beginblock();
push_captures(cap);
/* function may use buffer, so save it and create a new one */
oldbuff = luaL_newbuffer(0);
status = lua_callfunction(newp);
/* restore old buffer */
luaL_oldbuffer(oldbuff);
if (status != 0) {
lua_endblock();
lua_error(NULL);
}
res = lua_getresult(1);
if (lua_isstring(res))
addnchar(lua_getstring(res), lua_strlen(res));
lua_endblock();
}
}
开发者ID:Botje,项目名称:residualvm-tools,代码行数:41,代码来源:lstrlib.cpp
示例18: add_s
static void add_s (lua_Object newp, lua_Object table, int n)
{
if (lua_isstring(newp)) {
char *news = lua_getstring(newp);
while (*news) {
if (*news != ESC || !isdigit((unsigned char)*++news))
luaI_addchar(*news++);
else {
int l = check_cap(*news++, num_captures);
addnchar(capture[l].init, capture[l].len);
}
}
}
else if (lua_isfunction(newp)) {
lua_Object res;
struct lbuff oldbuff;
int status;
lua_beginblock();
if (lua_istable(table)) {
lua_pushobject(table);
lua_pushnumber(n);
}
push_captures();
/* function may use lbuffer, so save it and create a new one */
oldbuff = lbuffer;
lbuffer.b = NULL; lbuffer.max = lbuffer.size = 0;
status = lua_callfunction(newp);
/* restore old buffer */
free(lbuffer.b);
lbuffer = oldbuff;
if (status != 0)
lua_error(NULL);
res = lua_getresult(1);
addstr(lua_isstring(res) ? lua_getstring(res) : "");
lua_endblock();
}
else luaL_arg_check(0, 3, NULL);
}
开发者ID:Akagi201,项目名称:learning-lua,代码行数:38,代码来源:strlib.c
示例19: str_find
static int str_find (lua_State *L) {
size_t l1, l2;
const lua_WChar *s = luaL_checklwstring(L, 1, &l1);
const lua_WChar *p = luaL_checklwstring(L, 2, &l2);
sint32 init = posrelat(luaL_optlong(L, 3, 1), l1) - 1;
luaL_argcheck(L, 0 <= init && (size_t)(init) <= l1, 3, "out of range");
if (lua_toboolean(L, 4) || /* explicit request? */
lua_WChar_pbrk(p, SPECIALS) == NULL) { /* or no special characters? */
/* do a plain search */
const lua_WChar *s2 = lmemfind(s+init, l1-init, p, l2);
if (s2) {
lua_pushnumber(L, s2-s+1);
lua_pushnumber(L, s2-s+l2);
return 2;
}
}
else {
MatchState ms;
int anchor = (*p == '^') ? (p++, 1) : 0;
const lua_WChar *s1=s+init;
ms.L = L;
ms.src_init = s;
ms.src_end = s+l1;
do {
const lua_WChar *res;
ms.level = 0;
if ((res=match(&ms, s1, p)) != NULL) {
lua_pushnumber(L, s1-s+1); /* start */
lua_pushnumber(L, res-s); /* end */
return push_captures(&ms, NULL, 0) + 2;
}
} while (s1++<ms.src_end && !anchor);
}
lua_pushnil(L); /* not found */
return 1;
}
开发者ID:anissen,项目名称:WikiAdventure,代码行数:36,代码来源:lwstrlib.c
注:本文中的push_captures函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论