本文整理汇总了C++中capture_to_close函数的典型用法代码示例。如果您正苦于以下问题:C++ capture_to_close函数的具体用法?C++ capture_to_close怎么用?C++ capture_to_close使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了capture_to_close函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: switch
static const char *match (const char *s, const char *p, struct Capture *cap)
{
init: /* using goto's to optimize tail recursion */
switch (*p) {
case '(': { /* start capture */
const char *res;
if (cap->level >= MAX_CAPT) lua_error("too many captures");
cap->capture[cap->level].init = s;
cap->capture[cap->level].len = -1;
cap->level++;
if ((res=match(s, p+1, cap)) == NULL) /* match failed? */
cap->level--; /* undo capture */
return res;
}
case ')': { /* end capture */
int32 l = capture_to_close(cap);
const char *res;
cap->capture[l].len = s - cap->capture[l].init; /* close capture */
if ((res = match(s, p+1, cap)) == NULL) /* match failed? */
cap->capture[l].len = -1; /* undo capture */
return res;
}
case '\0': case '$': /* (possibly) end of pattern */
if (*p == 0 || (*(p+1) == 0 && s == cap->src_end))
return s;
/* else go through */
default: { /* it is a pattern item */
const char *ep; /* get what is next */
const char *s1 = matchitem(s, p, cap, &ep);
switch (*ep) {
case '*': { /* repetition */
const char *res;
if (s1 && s1>s && ((res=match(s1, p, cap)) != NULL))
return res;
p=ep+1; goto init; /* else return match(s, ep+1, cap); */
}
case '?': { /* optional */
const char *res;
if (s1 && ((res=match(s1, ep+1, cap)) != NULL))
return res;
p=ep+1; goto init; /* else return match(s, ep+1, cap); */
}
case '-': { /* repetition */
const char *res;
if ((res = match(s, ep+1, cap)) != NULL)
return res;
else if (s1 && s1>s) {
s = s1;
goto init; /* return match(s1, p, cap); */
}
else
return NULL;
}
default:
if (s1) { s=s1; p=ep; goto init; } /* return match(s1, ep, cap); */
else return NULL;
}
}
}
}
开发者ID:Botje,项目名称:residualvm-tools,代码行数:60,代码来源:lstrlib.cpp
示例2: capture_to_close
static const char *end_capture (MatchState *ms, const char *s,
const char *p) {
int l = capture_to_close(ms);
const char *res;
ms->capture[l].len = s - ms->capture[l].init; /* close capture */
if ((res = match(ms, s, p)) == NULL) /* match failed? */
ms->capture[l].len = CAP_UNFINISHED; /* undo capture */
return res;
}
开发者ID:aronarts,项目名称:FireNET,代码行数:9,代码来源:lstrlib.c
示例3: capture_to_close
static const char *end_capture (lua_State *L, const char *s, const char *p,
struct Capture *cap) {
int l = capture_to_close(L, cap);
const char *res;
cap->capture[l].len = s - cap->capture[l].init; /* close capture */
if ((res = match(L, s, p+1, cap)) == NULL) /* match failed? */
cap->capture[l].len = -1; /* undo capture */
return res;
}
开发者ID:BackupTheBerlios,项目名称:gltron-svn,代码行数:9,代码来源:lstrlib.c
示例4:
static const char *end_capture(LuaMatchState *ms, const char *s,const char *p)
{
int l;
const char *res;
if(!capture_to_close(ms, &l)) return NULL;
ms->capture[l].len = s - ms->capture[l].init; // close capture
if ((res = match(ms, s, p)) == NULL) // match failed?
ms->capture[l].len = CAP_UNFINISHED; // undo capture
return res;
}
开发者ID:apitests,项目名称:libjl777,代码行数:10,代码来源:lua-regex.c
示例5: end_capture
static const char *
end_capture(struct match_state *ms, const char *s, const char *p)
{
int l = capture_to_close(ms);
const char *res;
if (l == -1)
return NULL;
/* close capture */
ms->capture[l].len = s - ms->capture[l].init;
/* undo capture if match failed */
if ((res = match(ms, s, p)) == NULL)
ms->capture[l].len = CAP_UNFINISHED;
return res;
}
开发者ID:Frankie-666,项目名称:lwan,代码行数:14,代码来源:patterns.c
示例6: switch
static char *match (char *s, char *p, int level)
{
init: /* using goto's to optimize tail recursion */
switch (*p) {
case '(': /* start capture */
if (level >= MAX_CAPT) lua_error("too many captures");
capture[level].init = s;
capture[level].len = -1;
level++; p++; goto init; /* return match(s, p+1, level); */
case ')': { /* end capture */
int l = capture_to_close(level);
char *res;
capture[l].len = s - capture[l].init; /* close capture */
if ((res = match(s, p+1, level)) == NULL) /* match failed? */
capture[l].len = -1; /* undo capture */
return res;
}
case ESC:
if (isdigit((unsigned char)(*(p+1)))) { /* capture */
int l = check_cap(*(p+1), level);
if (strncmp(capture[l].init, s, capture[l].len) == 0) {
/* return match(p+2, s+capture[l].len, level); */
p+=2; s+=capture[l].len; goto init;
}
else return NULL;
}
else if (*(p+1) == 'b') { /* balanced string */
if (*(p+2) == 0 || *(p+3) == 0)
lua_error("bad balanced pattern specification");
s = matchbalance(s, *(p+2), *(p+3));
if (s == NULL) return NULL;
else { /* return match(p+4, s, level); */
p+=4; goto init;
}
}
else goto dflt;
case '\0': case '$': /* (possibly) end of pattern */
if (*p == 0 || (*(p+1) == 0 && *s == 0)) {
num_captures = level;
return s;
}
else goto dflt;
default: dflt: { /* it is a pattern item */
int m = luaL_singlematch(*s, p);
char *ep = luaL_item_end(p); /* get what is next */
switch (*ep) {
case '*': { /* repetition */
char *res;
if (m && (res = match(s+1, p, level)))
return res;
p=ep+1; goto init; /* else return match(s, ep+1, level); */
}
case '-': { /* repetition */
char *res;
if ((res = match(s, ep+1, level)) != 0)
return res;
else if (m) {
s++;
goto init; /* return match(s+1, p, level); */
}
else
return NULL;
}
case '?': { /* optional */
char *res;
if (m && (res = match(s+1, ep+1, level)))
return res;
p=ep+1; goto init; /* else return match(s, ep+1, level); */
}
default:
if (m) { s++; p=ep; goto init; } /* return match(s+1, ep, level); */
else return NULL;
}
}
}
}
开发者ID:Akagi201,项目名称:learning-lua,代码行数:76,代码来源:strlib.c
注:本文中的capture_to_close函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论