MCPcopy Create free account
hub / github.com/Genivia/ugrep / new_pattern

Method new_pattern

src/cnf.cpp:477–539  ·  view source on GitHub ↗

add an ALT pattern or ALT-NOT pattern, optionally negated (option -N)

Source from the content-addressed store, hash-verified

475
476// add an ALT pattern or ALT-NOT pattern, optionally negated (option -N)
477void CNF::new_pattern(PATTERN mask, const char *pattern)
478{
479 if (terms.empty())
480 terms.emplace_back();
481
482 if (flag_bool)
483 {
484 // --bool: compile to CNF
485 compile(pattern);
486 }
487 else
488 {
489 Term& term = terms.back();
490
491 // -e PATTERN, -N PATTERN, --and PATTERN, --not PATTERN
492 std::string spattern(pattern);
493
494 // -F
495 if (flag_fixed_strings)
496 quote(spattern);
497
498 // -w and -x
499 anchor(spattern);
500
501 // -N PATTERN
502 if ((mask & PATTERN::NEG) && !spattern.empty())
503 spattern.insert(0, "(?^").append(")");
504
505 // --not
506 if ((mask & PATTERN::NOT))
507 {
508 if (!spattern.empty())
509 {
510 if (term.empty())
511 term.emplace_back();
512 else if (term.front() && term.front()->empty())
513 return; // empty pattern means anything matches
514
515 term.emplace_back(new std::string(spattern));
516 }
517 }
518 else
519 {
520 if (term.empty())
521 term.emplace_back(new std::string(spattern));
522 else if (!term.front())
523 term.front() = Pattern(new std::string(spattern));
524 else if (term.front()->empty())
525 ; // empty pattern means anything matches
526 else if (spattern.empty())
527 term.front()->clear(); // empty pattern means anything matches
528 else
529 term.front()->append(flag_basic_regexp ? "\\|" : "|").append(spattern);
530
531 // empty pattern means anything matches
532 if (term.front()->empty())
533 {
534 auto i = term.begin();

Callers 2

initFunction · 0.80
ugrepFunction · 0.80

Calls 8

PatternClass · 0.85
emptyMethod · 0.45
backMethod · 0.45
insertMethod · 0.45
clearMethod · 0.45
beginMethod · 0.45
eraseMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected