本文整理汇总了C++中regnode函数的典型用法代码示例。如果您正苦于以下问题:C++ regnode函数的具体用法?C++ regnode怎么用?C++ regnode使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了regnode函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: regbranch
/*
- regbranch - one alternative of an | operator
*
* Implements the concatenation operator.
*/
static int regbranch(regex_t *preg, int *flagp )
{
int ret;
int chain;
int latest;
int flags;
*flagp = WORST; /* Tentatively. */
ret = regnode(preg, BRANCH);
chain = 0;
while (*preg->regparse != '\0' && *preg->regparse != ')' &&
*preg->regparse != '|') {
latest = regpiece(preg, &flags);
if (latest == 0)
return 0;
*flagp |= flags&HASWIDTH;
if (chain == 0) {/* First piece. */
*flagp |= flags&SPSTART;
}
else {
regtail(preg, chain, latest);
}
chain = latest;
}
if (chain == 0) /* Loop ran zero times. */
(void) regnode(preg, NOTHING);
return(ret);
}
开发者ID:BitThunder,项目名称:bitthunder,代码行数:35,代码来源:jimregexp.c
示例2: regbranch
/*
- regbranch - one alternative of an | operator
*
* Implements the concatenation operator.
*/
static char *
regbranch( int *flagp )
{
register char *ret;
register char *chain;
register char *latest;
int flags;
*flagp = WORST; /* Tentatively. */
ret = regnode(BRANCH);
chain = NULL;
while (*regparse != '\0' && *regparse != ')' &&
*regparse != '\n' && *regparse != '|') {
latest = regpiece(&flags);
if (latest == NULL)
return(NULL);
*flagp |= flags&HASWIDTH;
if (chain == NULL) /* First piece. */
*flagp |= flags&SPSTART;
else
regtail(chain, latest);
chain = latest;
}
if (chain == NULL) /* Loop ran zero times. */
(void) regnode(NOTHING);
return(ret);
}
开发者ID:BlackYoup,项目名称:medusa,代码行数:34,代码来源:regexp.c
示例3: regnode
TCHAR *CRegExp::regbranch(int *flagp)
{
TCHAR *ret;
TCHAR *chain;
TCHAR *latest;
int flags;
int c;
*flagp = WORST; // Tentatively.
ret = regnode(BRANCH);
chain = NULL;
while ((c = *regparse) != _T('\0') && c != _T('|') && c != _T(')')) {
latest = regpiece(&flags);
if (latest == NULL)
return(NULL);
*flagp |= flags&HASWIDTH;
if (chain == NULL) // First piece.
*flagp |= flags&SPSTART;
else
regtail(chain, latest);
chain = latest;
}
if (chain == NULL) // Loop ran zero times.
(void) regnode(NOTHING);
return(ret);
}
开发者ID:apex-hughin,项目名称:CrimsonEditor,代码行数:28,代码来源:RegExp.cpp
示例4: switch
struct Node *regspcl (struct Expr *expr, uchar *type, struct Node *parent)
{
struct Node *node;
uchar *pat;
switch( *type ) {
case 'd': pat = "[0-9]"; break;
case 'D': pat = "[^0-9]"; break;
case 's': pat = "[ ]"; break;
case 'S': pat = "[^ ]"; break;
case 'i': pat = "[a-zA-Z_:]"; break;
case 'I': pat = "[^a-zA-Z_:]"; break;
default:
// pattern is escaped regular character
if( node = regnode (expr) ) {
node->maximum = 1;
node->minimum = 1;
node->typelen = 1;
node->type->pattern = type;
node->parent = parent;
}
return node;
}
if( node = regnode (expr) ) {
node->maximum = 1;
node->minimum = 1;
node->typelen = strlen(pat);
node->type->pattern = pat;
node->parent = parent;
}
return node;
}
开发者ID:telescreen,项目名称:misc,代码行数:35,代码来源:regexpr2.c
示例5: regnode
/*
- regbranch - one alternative of an | operator
*
* Implements the concatenation operator.
*/
char* ossimRegExp::regbranch (int *flagp) {
char* ret;
char* chain;
char* latest;
int flags;
*flagp = WORST; // Tentatively.
ret = regnode(BRANCH);
chain = NULL;
while (*regparse != '\0' && *regparse != '|' && *regparse != ')') {
latest = regpiece(&flags);
if (latest == NULL)
return (NULL);
*flagp |= flags & HASWIDTH;
if (chain == NULL) // First piece.
*flagp |= flags & SPSTART;
else
regtail(chain, latest);
chain = latest;
}
if (chain == NULL) // Loop ran zero times.
regnode(NOTHING);
return (ret);
}
开发者ID:ossimlabs,项目名称:ossim,代码行数:31,代码来源:ossimRegExp.cpp
示例6: regatom
/*
- regpiece - something followed by possible [*+?]
*
* Note that the branching code sequences used for ? and the general cases
* of * and + are somewhat optimized: they use the same NOTHING node as
* both the endmarker for their branch list and the body of the last branch.
* It might seem that this node could be dispensed with entirely, but the
* endmarker role is not redundant.
*/
char* ossimRegExp::regpiece (int *flagp) {
char* ret;
char op;
char* next;
int flags;
ret = regatom(&flags);
if (ret == NULL)
return (NULL);
op = *regparse;
if (!ISMULT(op)) {
*flagp = flags;
return (ret);
}
if (!(flags & HASWIDTH) && op != '?') {
//RAISE Error, SYM(ossimRegExp), SYM(Empty_Operand),
printf ("ossimRegExp::compile() : *+ operand could be empty.\n");
return 0;
}
*flagp = (op != '+') ? (WORST | SPSTART) : (WORST | HASWIDTH);
if (op == '*' && (flags & SIMPLE))
reginsert(STAR, ret);
else if (op == '*') {
// Emit x* as (x&|), where & means "self".
reginsert(BRANCH, ret); // Either x
regoptail(ret, regnode(BACK)); // and loop
regoptail(ret, ret); // back
regtail(ret, regnode(BRANCH)); // or
regtail(ret, regnode(NOTHING)); // null.
}
else if (op == '+' && (flags & SIMPLE))
reginsert(PLUS, ret);
else if (op == '+') {
// Emit x+ as x(&|), where & means "self".
next = regnode(BRANCH); // Either
regtail(ret, next);
regtail(regnode(BACK), ret); // loop back
regtail(next, regnode(BRANCH)); // or
regtail(ret, regnode(NOTHING)); // null.
}
else if (op == '?') {
// Emit x? as (x|)
reginsert(BRANCH, ret); // Either x
regtail(ret, regnode(BRANCH)); // or
next = regnode(NOTHING);// null.
regtail(ret, next);
regoptail(ret, next);
}
regparse++;
if (ISMULT(*regparse)) {
//RAISE Error, SYM(ossimRegExp), SYM(Nested_Operand),
printf ("ossimRegExp::compile(): Nested *?+.\n");
return 0;
}
return (ret);
}
开发者ID:ossimlabs,项目名称:ossim,代码行数:68,代码来源:ossimRegExp.cpp
示例7: regatom
/*
- regpiece - something followed by possible [*+?]
*
* Note that the branching code sequences used for ? and the general cases
* of * and + are somewhat optimized: they use the same NOTHING node as
* both the endmarker for their branch list and the body of the last branch.
* It might seem that this node could be dispensed with entirely, but the
* endmarker role is not redundant.
*/
static char *regpiece( int *flagp )
{
char *ret, op, *next;
int flags;
ret = regatom( &flags );
if( ret == NULL ) {
return( NULL );
}
op = *regparse;
if( !ISMULT( op ) ) {
*flagp = flags;
return( ret );
}
if( !( flags & HASWIDTH ) && op != '?' ) {
FAIL( ERR_RE_EMPTY_OPERAND );
}
*flagp = ( op != '+' ) ? ( WORST | SPSTART ) : ( WORST | HASWIDTH );
if( op == '*' && ( flags & SIMPLE ) ) {
reginsert( STAR, ret );
} else if( op == '*' ) {
/* Emit x* as (x&|), where & means "self". */
reginsert( BRANCH, ret ); /* Either x */
regoptail( ret, regnode( BACK ) ); /* and loop */
regoptail( ret, ret ); /* back */
regtail( ret, regnode( BRANCH ) ); /* or */
regtail( ret, regnode( NOTHING ) ); /* null. */
} else if( op == '+' && ( flags & SIMPLE ) ) {
reginsert( PLUS, ret );
} else if( op == '+' ) {
/* Emit x+ as x(&|), where & means "self". */
next = regnode( BRANCH ); /* Either */
regtail( ret, next );
regtail( regnode( BACK ), ret ); /* loop back */
regtail( next, regnode( BRANCH ) ); /* or */
regtail( ret, regnode( NOTHING ) ); /* null. */
} else if( op == '?' ) {
/* Emit x? as (x|) */
reginsert( BRANCH, ret ); /* Either x */
regtail( ret, regnode( BRANCH ) ); /* or */
next = regnode( NOTHING ); /* null. */
regtail( ret, next );
regoptail( ret, next );
}
regparse++;
if( ISMULT( *regparse ) ) {
FAIL( ERR_RE_NESTED_OPERAND );
}
return( ret );
}
开发者ID:ABratovic,项目名称:open-watcom-v2,代码行数:63,代码来源:regexp.c
示例8: regatom
/*
- regpiece - something followed by possible [*+?]
*
* Note that the branching code sequence used for ? and the general cases of
* * and + are somewhat optimized: they use the same NOTHING node as both the
* endmarker for their branch list and the body of the last branch. It might
* seem that this node could be dispensed with entirely, but the endmarker
* role is not redundant.
*/
static char *regpiece (int * flagp)
{
register char *ret;
register short op;
register char *nxt;
int flags;
ret = regatom(&flags);
if (ret == (char *) NULL)
return ((char *) NULL);
op = *regparse;
if (!ISMULT(op)) {
*flagp = flags;
return (ret);
}
if (!(flags & HASWIDTH) && op != QMARK)
FAIL("*+ operand could be empty\n");
*flagp = (op != PLUSS) ? (WORST | SPSTART) : (WORST | HASWIDTH);
if (op == ASTERIX && (flags & SIMPLE))
reginsert(STAR, ret);
else if (op == ASTERIX) {
/* Emit x* as (x&|), where & means "self". */
reginsert(BRANCH, ret); /* Either x */
regoptail(ret, regnode(BACK)); /* and loop */
regoptail(ret, ret); /* back */
regtail(ret, regnode(BRANCH)); /* or */
regtail(ret, regnode(NOTHING)); /* null. */
} else if (op == PLUSS && (flags & SIMPLE))
reginsert(PLUS, ret);
else if (op == PLUSS) {
/* Emit x+ as x(&|), where & means "self". */
nxt = regnode(BRANCH); /* Either */
regtail(ret, nxt);
regtail(regnode(BACK), ret); /* loop back */
regtail(nxt, regnode(BRANCH)); /* or */
regtail(ret, regnode(NOTHING)); /* null. */
} else if (op == QMARK) {
/* Emit x? as (x|) */
reginsert(BRANCH, ret); /* Either x */
regtail(ret, regnode(BRANCH)); /* or */
nxt = regnode(NOTHING); /* null. */
regtail(ret, nxt);
regoptail(ret, nxt);
}
regparse++;
if (ISMULT(*regparse))
FAIL("nested *?+\n");
return (ret);
}
开发者ID:Hobbitron,项目名称:tmi2_fluffos_v3,代码行数:61,代码来源:regexp.c
示例9:
struct Node *regpat (struct Expr *expr, uchar *pat, int len, struct Node *parent)
{
struct Node *node;
if( node = regnode (expr) ) {
node->maximum = 1;
node->minimum = 1;
node->typelen = len;
node->parent = parent;
node->type->pattern = pat;
}
return node;
}
开发者ID:telescreen,项目名称:misc,代码行数:13,代码来源:regexpr2.c
示例10: regatom
/*
- regatom - the lowest level
*
* Optimization: gobbles an entire sequence of ordinary characters so that
* it can turn them into a single node, which is smaller to store and
* faster to run. Backslashed characters are exceptions, each becoming a
* separate node; the code is simpler that way and it's not worth fixing.
*/
static char *
regatom(int *flagp)
{
register char *ret;
int flags;
*flagp = WORST; /* Tentatively. */
switch (*regparse++) {
case '^':
ret = regnode(BOL);
break;
case '$':
ret = regnode(EOL);
break;
case '.':
ret = regnode(ANY);
*flagp |= HASWIDTH|SIMPLE;
break;
case '[': {
register int chclass;
register int chclassend;
if (*regparse == '^') { /* Complement of range. */
ret = regnode(ANYBUT);
regparse++;
} else {
ret = regnode(ANYOF);
}
if (*regparse == ']' || *regparse == '-') {
regc(*regparse++);
}
while (*regparse != '\0' && *regparse != ']') {
if (*regparse == '-') {
regparse++;
if (*regparse == ']' || *regparse == '\0') {
regc('-');
} else {
chclass = UCHARAT(regparse-2)+1;
chclassend = UCHARAT(regparse);
if (chclass > chclassend+1) {
FAIL("invalid [] range");
}
for (; chclass <= chclassend; chclass++) {
regc(chclass);
}
regparse++;
}
} else if (*regparse == '\\') {
switch(*++regparse) {
case 'n' :
regc('\n');
regparse++;
break;
case 't' :
regc('\t');
regparse++;
break;
case ']' :
regc(']');
regparse++;
break;
case '-' :
regc('-');
regparse++;
break;
case '\\' :
regc('\\');
regparse++;
break;
default :
regparse--;
regc(*regparse++);
}
} else {
regc(*regparse++);
}
}
regc('\0');
if (*regparse != ']') {
FAIL("unmatched []");
}
regparse++;
*flagp |= HASWIDTH|SIMPLE;
}
break;
case '(':
ret = reg(1, &flags);
if (ret == NULL) {
return(NULL);
}
*flagp |= flags&(HASWIDTH|SPSTART);
//.........这里部分代码省略.........
开发者ID:jonathangray,项目名称:freebsd-1.x-ports,代码行数:101,代码来源:sre.c
示例11: FAIL
/*
* reg - regular expression, i.e. main body or parenthesized thing
*
* Caller must absorb opening parenthesis.
*
* Combining parenthesis handling with the base level of regular expression
* is a trifle forced, but the need to tie the tails of the branches to what
* follows makes it hard to avoid.
*/
static char *reg( int paren, int *flagp )
{
char *ret, *br, *ender;
int flags;
char parno = 0;
*flagp = HASWIDTH; /* Tentatively. */
/* Make an OPEN node, if parenthesized. */
if( paren ) {
if( regnpar >= NSUBEXP ) {
FAIL( ERR_RE_TOO_MANY_ROUND_BRACKETS );
}
parno = regnpar;
regnpar++;
ret = regnode( OPEN + parno );
} else {
ret = NULL;
}
/* Pick up the branches, linking them together. */
br = regbranch( &flags );
if( br == NULL ) {
return( NULL );
}
if( ret != NULL ) {
regtail( ret, br ); /* OPEN -> first. */
} else {
ret = br;
}
if( !( flags & HASWIDTH ) ) {
*flagp &= ~HASWIDTH;
}
*flagp |= flags & SPSTART;
while( *regparse == '|' ) {
regparse++;
br = regbranch( &flags );
if( br == NULL ) {
return( NULL );
}
regtail( ret, br ); /* BRANCH -> BRANCH. */
if( !( flags & HASWIDTH ) ) {
*flagp &= ~HASWIDTH;
}
*flagp |= flags & SPSTART;
}
/* Make a closing node, and hook it on the end. */
ender = regnode( ( paren ) ? CLOSE + parno : END );
regtail( ret, ender );
/* Hook the tails of the branches to the closing node. */
for( br = ret; br != NULL; br = regnext( br ) ) {
regoptail( br, ender );
}
/* Check for proper termination. */
if( paren && *regparse++ != ')' ) {
FAIL( ERR_RE_UNMATCHED_ROUND_BRACKETS );
} else if( !paren && *regparse != '\0' ) {
if( *regparse == ')' ) {
FAIL( ERR_RE_UNMATCHED_ROUND_BRACKETS );
} else {
FAIL( ERR_RE_INTERNAL_FOULUP ); /* "Can't happen". */
}
}
return( ret );
}
开发者ID:ABratovic,项目名称:open-watcom-v2,代码行数:78,代码来源:regexp.c
示例12: switch
TCHAR *CRegExp::regatom(int *flagp)
{
TCHAR *ret;
int flags;
*flagp = WORST; // Tentatively.
switch (*regparse++) {
case _T('^'):
ret = regnode(BOL);
break;
case _T('$'):
ret = regnode(EOL);
break;
case _T('.'):
ret = regnode(ANY);
*flagp |= HASWIDTH|SIMPLE;
break;
case _T('['): {
int range;
int rangeend;
int c;
if (*regparse == _T('^')) { // Complement of range.
ret = regnode(ANYBUT);
regparse++;
} else
ret = regnode(ANYOF);
if ((c = *regparse) == _T(']') || c == _T('-')) {
regc(c);
regparse++;
}
while ((c = *regparse++) != _T('\0') && c != _T(']')) {
if (c != _T('-'))
regc(c);
else if ((c = *regparse) == _T(']') || c == _T('\0'))
regc(_T('-'));
else
{
range = (unsigned) (TCHAR)*(regparse-2);
rangeend = (unsigned) (TCHAR)c;
if (range > rangeend)
{
TRACE0("invalid [] range\n");
return NULL;
}
for (range++; range <= rangeend; range++)
regc(range);
regparse++;
}
}
regc(_T('\0'));
if (c != _T(']'))
{
TRACE0("unmatched []\n");
return NULL;
}
*flagp |= HASWIDTH|SIMPLE;
break;
}
case _T('('):
ret = reg(1, &flags);
if (ret == NULL)
return(NULL);
*flagp |= flags&(HASWIDTH|SPSTART);
break;
case _T('\0'):
case _T('|'):
case _T(')'):
// supposed to be caught earlier
TRACE0("internal error: \\0|) unexpected\n");
return NULL;
break;
case _T('?'):
case _T('+'):
case _T('*'):
TRACE0("?+* follows nothing\n");
return NULL;
break;
case _T('\\'):
if (*regparse == _T('\0'))
{
TRACE0("trailing \\\n");
return NULL;
}
ret = regnode(EXACTLY);
regc(*regparse++);
regc(_T('\0'));
*flagp |= HASWIDTH|SIMPLE;
break;
default: {
size_t len;
TCHAR ender;
regparse--;
len = _tcscspn(regparse, META);
if (len == 0)
{
TRACE0("internal error: strcspn 0\n");
return NULL;
//.........这里部分代码省略.........
开发者ID:apex-hughin,项目名称:CrimsonEditor,代码行数:101,代码来源:RegExp.cpp
示例13: regatom
TCHAR *CRegExp::regpiece(int *flagp)
{
TCHAR *ret;
TCHAR op;
TCHAR *next;
int flags;
ret = regatom(&flags);
if (ret == NULL)
return(NULL);
op = *regparse;
if (!ISREPN(op)) {
*flagp = flags;
return(ret);
}
if (!(flags&HASWIDTH) && op != _T('?'))
{
TRACE0("*+ operand could be empty\n");
return NULL;
}
switch (op) {
case _T('*'): *flagp = WORST|SPSTART; break;
case _T('+'): *flagp = WORST|SPSTART|HASWIDTH; break;
case _T('?'): *flagp = WORST; break;
}
if (op == _T('*') && (flags&SIMPLE))
reginsert(STAR, ret);
else if (op == _T('*')) {
// Emit x* as (x&|), where & means "self".
reginsert(BRANCH, ret); // Either x
regoptail(ret, regnode(BACK)); // and loop
regoptail(ret, ret); // back
regtail(ret, regnode(BRANCH)); // or
regtail(ret, regnode(NOTHING)); // null.
} else if (op == _T('+') && (flags&SIMPLE))
reginsert(PLUS, ret);
else if (op == _T('+')) {
// Emit x+ as x(&|), where & means "self".
next = regnode(BRANCH); // Either
regtail(ret, next);
regtail(regnode(BACK), ret); // loop back
regtail(next, regnode(BRANCH)); // or
regtail(ret, regnode(NOTHING)); // null.
} else if (op == _T('?')) {
// Emit x? as (x|)
reginsert(BRANCH, ret); // Either x
regtail(ret, regnode(BRANCH)); // or
next = regnode(NOTHING); // null.
regtail(ret, next);
regoptail(ret, next);
}
regparse++;
if (ISREPN(*regparse))
{
TRACE0("nested *?+\n");
return NULL;
}
return(ret);
}
开发者ID:apex-hughin,项目名称:CrimsonEditor,代码行数:64,代码来源:RegExp.cpp
示例14: switch
/*
- regatom - the lowest level
*
* Optimization: gobbles an entire sequence of ordinary characters so that
* it can turn them into a single node, which is smaller to store and
* faster to run.
*/
static char *regatom (int * flagp)
{
register char *ret;
int flags;
*flagp = WORST; /* Tentatively. */
switch (*regparse++) {
case CARET:
ret = regnode(BOL);
break;
case DOLLAR:
ret = regnode(EOL);
break;
case DOT:
ret = regnode(ANY);
*flagp |= HASWIDTH | SIMPLE;
break;
case LSHBRAC:
ret = regnode(WORDSTART);
break;
case RSHBRAC:
ret = regnode(WORDEND);
break;
case LSQBRAC:{
register int classs;
register int classend;
if (*regparse == CARET) { /* Complement of range. */
ret = regnode(ANYBUT);
regparse++;
} else
ret = regnode(ANYOF);
if (*regparse == RSQBRAC || *regparse == '-')
regc(*regparse++);
while (*regparse != '\0' && *regparse != RSQBRAC) {
if (*regparse == '-') {
regparse++;
if (*regparse == RSQBRAC || *regparse == '\0')
regc('-');
else {
classs = (CHARBITS & *(regparse - 2)) + 1;
classend = (CHARBITS & *(regparse));
if (classs > classend + 1)
FAIL("invalid [] range\n");
for (; classs <= classend; classs++)
regc(classs);
regparse++;
}
} else
regc(*regparse++);
}
regc('\0');
if (*regparse != RSQBRAC)
FAIL("unmatched []\n");
regparse++;
*flagp |= HASWIDTH | SIMPLE;
}
break;
case LBRAC:
ret = reg(1, &flags);
if (ret == (char *) NULL)
return ((char *) NULL);
*flagp |= flags & (HASWIDTH | SPSTART);
break;
case '\0':
case OR_OP:
case RBRAC:
FAIL("internal urp\n"); /* Supposed to be caught earlier. */
break;
case ASTERIX:
FAIL("* follows nothing\n");
break;
case PLUSS:
FAIL("+ follows nothing\n");
break;
case QMARK:
FAIL("? follows nothing\n");
break;
default:{
register int len;
register short ender;
regparse--;
for (len = 0; regparse[len] &&
!(regparse[len] & SPECIAL) && regparse[len] != RSQBRAC; len++);
if (len <= 0) {
FAIL("unexpected ]\n");
}
ender = *(regparse + len);
if (len > 1 && ISMULT(ender))
len--; /* Back off clear of ?+* operand. */
*flagp |= HASWIDTH;
//.........这里部分代码省略.........
开发者ID:Hobbitron,项目名称:tmi2_fluffos_v3,代码行数:101,代码来源:regexp.c
示例15: TRACE1
TCHAR *CRegExp::reg(int paren, int *flagp)
{
char *ret;
char *br;
char *ender;
int parno;
int flags;
*flagp = HASWIDTH; // Tentatively.
if (paren)
{
// Make an OPEN node.
if (regnpar >= NSUBEXP)
{
TRACE1("Too many (). NSUBEXP is set to %d\n", NSUBEXP );
return NULL;
}
parno = regnpar;
regnpar++;
ret = regnode(OPEN+parno);
}
// Pick up the branches, linking them together.
br = regbranch(&flags);
if (br == NULL)
return(NULL);
if (paren)
regtail(ret, br); // OPEN -> first.
else
ret = br;
*flagp &= ~(~flags&HASWIDTH); // Clear bit if bit 0.
*flagp |= flags&SPSTART;
while (*regparse == _T('|')) {
regparse++;
br = regbranch(&flags);
if (br == NULL)
return(NULL);
regtail(ret, br); // BRANCH -> BRANCH.
*flagp &= ~(~flags&HASWIDTH);
*flagp |= flags&SPSTART;
}
// Make a closing node, and hook it on the end.
ender = regnode((paren) ? CLOSE+parno : END);
regtail(ret, ender);
// Hook the tails of the branches to the closing node.
for (br = ret; br != NULL; br = regnext(br))
regoptail(br, ender);
// Check for proper termination.
if (paren && *regparse++ != _T(')'))
{
TRACE0("unterminated ()\n");
return NULL;
}
else if (!paren && *regparse != _T('\0'))
{
if (*regparse == _T(')'))
{
TRACE0("unmatched ()\n");
return NULL;
}
else
{
TRACE0("internal error: junk on end\n");
return NULL;
}
// NOTREACHED
}
return(ret);
}
开发者ID:apex-hughin,项目名称:CrimsonEditor,代码行数:74,代码来源:RegExp.cpp
示例16: switch
/*
* regatom - the lowest level
*
* Optimization: gobbles an entire sequence of ordinary characters so that
* it can turn them into a single node, which is smaller to store and
* faster to run. Backslashed characters are exceptions, each becoming a
* separate node; the code is simpler that way and it's not worth fixing.
*/
static char *regatom( int *flagp )
{
char *ret;
int flags;
*flagp = WORST; /* Tentatively. */
switch( *regparse++ ) {
case '~':
if( *regparse == 0 ) {
FAIL( ERR_RE_INVALID_CASETOGGLE );
}
ret = regnode( CASEI );
break;
case '@':
if( *regparse == 0 ) {
FAIL( ERR_RE_INVALID_CASETOGGLE );
}
ret = regnode( NOCASEI );
break;
case '^':
ret = regnode( BOL );
break;
case '$':
ret = regnode( EOL );
break;
case '.':
ret = regnode( ANY );
*flagp |= HASWIDTH | SIMPLE;
break;
case '[':
{
if( *regparse == '^' ) { /* Complement of range. */
ret = regnode( ANYBUT );
regparse++;
} else {
ret = regnode( ANYOF );
}
if( *regparse == ']' || *regparse == '-' ) {
regc( *regparse++ );
}
while( *regparse != '\0' && *regparse != ']' ) {
if( *regparse == '-' ) {
regparse++;
if( *regparse == ']' || *regparse == '\0' ) {
regc( '-' );
} else {
int class;
int classend;
class = UCHARAT( regparse - 2 ) + 1;
classend = UCHARAT( regparse );
if( class > classend + 1 ) {
FAIL( ERR_RE_INVALID_SB_RANGE );
}
for( ; class <= classend; class++ ) {
regc( (char)class );
}
regparse++;
}
} else {
if( *regparse == '\\' && *( regparse + 1 ) == 't' && REALTABS ) {
regparse += 2;
regc( '\t' );
} else {
regc( *regparse++ );
}
}
}
regc( '\0' );
if( *regparse != ']' ) {
FAIL( ERR_RE_UNMATCHED_SQUARE_BRACKET );
}
regparse++;
*flagp |= HASWIDTH | SIMPLE;
}
开发者ID:ABratovic,项目名称:open-watcom-v2,代码行数:84,代码来源:regexp.c
示例17: reg
/*
- reg - regular expression, i.e. main body or parenthesized thing
*
* Caller must absorb opening parenthesis.
*
* Combining parenthesis handling with the base level of regular expression
* is a trifle forced, but the need to tie the tails of the branches to what
* follows makes it hard to avoid.
*/
static int reg(regex_t *preg, int paren /* Parenthesized? */, int *flagp )
{
int ret;
int br;
int ender;
int parno = 0;
int flags;
*flagp = HASWIDTH; /* Tentatively. */
/* Make an OPEN node, if parenthesized. */
if (paren) {
if (preg->regparse[0] == '?' && preg->regparse[1] == ':') {
/* non-capturing paren */
preg->regparse += 2;
parno = -1;
}
else {
parno = ++preg->re_nsub;
}
ret = regnode(preg, OPEN+parno);
} else
ret = 0;
/* Pick up the branches, linking them together. */
br = regbranch(preg, &flags);
if (br == 0)
return 0;
if (ret != 0)
regtail(preg, ret, br); /* OPEN -> first. */
else
ret = br;
if (!(flags&HASWIDTH))
*flagp &= ~HASWIDTH;
*flagp |= flags&SPSTART;
while (*preg->regparse == '|') {
preg->regparse++;
br = regbranch(preg, &flags);
if (br == 0)
return 0;
regtail(preg, ret, br); /* BRANCH -> BRANCH. */
if (!(flags&HASWIDTH))
*flagp &= ~HASWIDTH;
*flagp |= flags&SPSTART;
}
/* Make a closing node, and hook it on the end. */
ender = regnode(preg, (paren) ? CLOSE+parno : END);
regtail(preg, ret, ender);
/* Hook the tails of the branches to the closing node. */
for (br = ret; br != 0; br = regnext(preg, br))
regoptail(preg, br, ender);
/* Check for proper termination. */
if (paren && *preg->regparse++ != ')') {
preg->err = REG_ERR_UNMATCHED_PAREN;
return 0;
} else if (!paren && *preg->regparse != '\0') {
if (*preg->regparse == ')') {
preg->err = REG_ERR_UNMATCHED_PAREN;
return 0;
} else {
preg->err = REG_ERR_JUNK_ON_END;
return 0;
}
}
return(ret);
}
开发者ID:BitThunder,项目名称:bitthunder,代码行数:79,代码来源:jimregexp.c
示例18: printf
/*
- reg - regular expression, i.e. main body or parenthesized thing
*
* Caller must absorb opening parenthesis.
*
* Combining parenthesis handling with the base level of regular expression
* is a trifle forced, but the need to tie the tails of the branches to what
* follows makes it hard to avoid.
*/
char* ossimRegExp::reg (int paren, int *flagp) {
char* ret;
char* br;
char* ender;
int parno =0;
int flags;
*flagp = HASWIDTH; // Tentatively.
// Make an OPEN node, if parenthesized.
if (paren) {
if (regnpar >= NSUBEXP) {
//RAISE Error, SYM(ossimRegExp), SYM(Too_Many_Parens),
printf ("ossimRegExp::compile(): Too many parentheses.\n");
return 0;
}
parno = regnpar;
regnpar++;
ret = regnode(OPEN + parno);
}
else
ret = NULL;
// Pick up the branches, linking them together.
br = regbranch(&flags);
if (br == NULL)
return (NULL);
if (ret != NULL)
regtail(ret, br); // OPEN -> first.
else
ret = br;
if (!(flags & HASWIDTH))
*flagp &= ~HASWIDTH;
*flagp |= flags & SPSTART;
while (*regparse == '|') {
regparse++;
br = regbranch(&flags);
if (br == NULL)
return (NULL);
regtail(ret, br); // BRANCH -> BRANCH.
if (!(flags & HASWIDTH))
*flagp &= ~HASWIDTH;
*flagp |= flags & SPSTART;
}
// Make a closing node, and hook it on the end.
ender = regnode((paren) ? CLOSE + parno : END);
regtail(ret, ender);
// Hook the tails of the branches to the closing node.
for (br = ret; br != NULL; br = regnext(br))
regoptail(br, ender);
// Check for proper termination.
if (paren && *regparse++ != ')') {
//RAISE Error, SYM(ossimRegExp), SYM(Unmatched_Parens),
printf ("ossimRegExp::compile(): Unmatched parentheses.\n");
return 0;
}
else if (!paren && *regparse != '\0') {
if (*regparse == ')') {
//RAISE Error, SYM(ossimRegExp), SYM(Unmatched_Parens),
printf ("ossimRegExp::compile(): Unmatched parentheses.\n");
return 0;
}
else {
//RAISE Error, SYM(ossimRegExp), SYM(Internal_Error),
printf ("ossimRegExp::compile(): Internal error.\n");
return 0;
}
// NOTREACHED
}
return (ret);
}
开发者ID:ossimlabs,项目名称:ossim,代码行数:83,代码来源:ossimRegExp.cpp
示例19: regcomp
int regcomp (struct Expr *expr, int size, uchar *pat, int len)
{
int bnest = 0, off = 0, ch;
struct Node *node = NULL;
struct Node *prev = NULL;
struct Node *parent;
if( size < sizeof(*expr) )
return 0;
memset (expr, 0, sizeof(*expr));
expr->size = size;
if( parent = regpat(expr, NULL, 0, NULL) )
while( off < len ) {
switch( ch = pat[off] ) {
case '{':
if( node ) {
off += regminimax (expr, pat + off, len - off, node);
continue;
}
return 0;
case ']':
return 0;
case '[':
if( node = regpat(expr, pat + off++, 1, parent) )
bnest = 1;
else
return 0;
while( off < len && bnest )
if( pat[off] == '[' )
bnest++, off++, node->typelen++;
else if( pat[off] == ']' )
--bnest, off++, node->typelen++;
else
off++, node->typelen++;
regappend (node, prev);
prev = node;
continue;
// "or" node
case '|':
if( node = regnode(expr) ) {
node->typelen = -1;
node->parent = parent;
node->minimum = 0;
node->maximum = 1;
} else
return 0;
// if already underway,
// move node chain under
// new "or" node
if( parent->ornode ) {
node->type->child = parent->ornode->next;
parent->ornode->next = node;
} else {
node->type->child = parent->type->child;
parent->type->child = node;
}
parent->ornode = prev = node;
// reparent child nodes
// under new "or" node
if( node = node->type->child )
do node->parent = prev;
while( node = node->next );
off++;
continue;
case '(':
if( parent = regpat (expr, NULL, 0, parent) ) // expression node
regappend (parent, prev);
else
return 0;
prev = node = NULL;
off++;
continue;
case ')':
if( node = parent ) {
off++;
parent = node->parent;
if( prev = parent->type->child )
while( prev->next )
prev = prev->next;
continue;
}
return 0;
//.........这里部分代码省略.........
开发者ID:telescreen,项目名称:misc,代码行数:101,代码来源:regexpr2.c
示例20: regpiece
/*
- regpiece - something followed by possible [*+?]
*
* Note that the branching code sequences used for ? and the general cases
* of * and + are somewhat optimized: they use the same NOTHING node as
* both the endmarker for their branch list and the body of the last branch.
* It might seem that this node could be dispensed with entirely, but the
* endmarker role is not redundant.
*/
static int regpiece(regex_t *preg, int *flagp)
{
int ret;
char op;
int next;
int flags;
int min;
int max;
ret = regatom(preg, &flags);
if (ret == 0)
return 0;
op = *preg->regparse;
if (!ISMULT(op)) {
*flagp = flags;
return(ret);
}
if (!(flags&HASWIDTH) && op != '?') {
preg->err = REG_ERR_OPERAND_COULD_BE_EMPTY;
return 0;
}
/* Handle braces (counted repetition) by expansion */
if (op == '{') {
char *end;
min = strtoul(preg->regparse + 1, &end, 10);
if (end == preg->regparse + 1) {
preg->err = REG_ERR_BAD_COUNT;
return 0;
}
if (*end == '}') {
max = min;
}
else {
preg->regparse = end;
max = strtoul(preg->regparse + 1, &end, 10);
if (*end != '}') {
preg->err = REG_ERR_UNMATCHED_BRACES;
return 0;
}
}
if (end == preg->regparse + 1) {
max = MAX_REP_COUNT;
}
else if (max < min || max >= 100) {
preg->err = REG_ERR_BAD_COUNT;
return 0;
}
if (min >= 100) {
preg->err = REG_ERR_BAD_COUNT;
return 0;
}
preg->regparse = strchr(preg->regparse, '}');
}
else {
min = (op == '+');
max = (op == '?' ? 1 : MAX_REP_COUNT);
}
if (preg->regparse[1] == '?') {
preg->regparse++;
next = reginsert(preg, flags & SIMPLE ? REPMIN : REPXMIN, 5, ret);
}
else {
next = reginsert(preg, flags & SIMPLE ? REP: REPX, 5, ret);
}
preg->program[ret + 2] = max;
preg->program[ret + 3] = min;
preg->program[ret + 4] = 0;
*flagp = (min) ? (WORST|HASWIDTH) : (WORST|SPSTART);
if (!(flags & SIMPLE)) {
int back = regnode(preg, BACK);
regtail(preg, back, ret);
regtail(preg, next, back);
}
preg->regparse++;
if (ISMULT(*preg->regparse)) {
preg->err = REG_ERR_NESTED_COUNT;
return 0;
}
return ret;
}
开发者ID:BitThunder,项目名称:bitthunder,代码行数:99,代码来源:jimregexp.c
注:本文中的regnode函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论