MCPcopy Create free account
hub / github.com/boostorg/build / regpiece

Function regpiece

v2/engine/regexp.c:416–469  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

414 * endmarker role is not redundant.
415 */
416static char *
417regpiece( int *flagp )
418{
419 register char *ret;
420 register char op;
421 register char *next;
422 int flags;
423
424 ret = regatom(&flags);
425 if (ret == NULL)
426 return(NULL);
427
428 op = *regparse;
429 if (!ISMULT(op)) {
430 *flagp = flags;
431 return(ret);
432 }
433
434 if (!(flags&HASWIDTH) && op != '?')
435 FAIL("*+ operand could be empty");
436 *flagp = (op != '+') ? (WORST|SPSTART) : (WORST|HASWIDTH);
437
438 if (op == '*' && (flags&SIMPLE))
439 reginsert(STAR, ret);
440 else if (op == '*') {
441 /* Emit x* as (x&|), where & means "self". */
442 reginsert(BRANCH, ret); /* Either x */
443 regoptail(ret, regnode(BACK)); /* and loop */
444 regoptail(ret, ret); /* back */
445 regtail(ret, regnode(BRANCH)); /* or */
446 regtail(ret, regnode(NOTHING)); /* null. */
447 } else if (op == '+' && (flags&SIMPLE))
448 reginsert(PLUS, ret);
449 else if (op == '+') {
450 /* Emit x+ as x(&|), where & means "self". */
451 next = regnode(BRANCH); /* Either */
452 regtail(ret, next);
453 regtail(regnode(BACK), ret); /* loop back */
454 regtail(next, regnode(BRANCH)); /* or */
455 regtail(ret, regnode(NOTHING)); /* null. */
456 } else if (op == '?') {
457 /* Emit x? as (x|) */
458 reginsert(BRANCH, ret); /* Either x */
459 regtail(ret, regnode(BRANCH)); /* or */
460 next = regnode(NOTHING); /* null. */
461 regtail(ret, next);
462 regoptail(ret, next);
463 }
464 regparse++;
465 if (ISMULT(*regparse))
466 FAIL("nested *?+");
467
468 return(ret);
469}
470
471/*
472 - regatom - the lowest level

Callers 1

regbranchFunction · 0.85

Calls 5

regatomFunction · 0.85
reginsertFunction · 0.85
regoptailFunction · 0.85
regnodeFunction · 0.85
regtailFunction · 0.85

Tested by

no test coverage detected