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

Method convert

src/cnf.cpp:384–435  ·  view source on GitHub ↗

convert CNF-normalized operator tree to terms, a CNF AND-list of ALT-term lists

Source from the content-addressed store, hash-verified

382
383// convert CNF-normalized operator tree to terms, a CNF AND-list of ALT-term lists
384void CNF::OpTree::convert(Terms& terms)
385{
386 if (op == OpTree::AND)
387 {
388 for (const auto& i : list)
389 {
390 if (!terms.back().empty())
391 terms.emplace_back();
392
393 if (i.op == OpTree::OR)
394 {
395 auto k = i.list.begin();
396 auto e = i.list.end();
397
398 while (k != e && (k->op != NONE || !k->regex.empty()))
399 ++k;
400
401 if (k != e)
402 {
403 // empty pattern found, ignore all other patterns
404 k->add_to(terms);
405 }
406 else
407 {
408 for (const auto& j : i.list)
409 j.add_to(terms);
410 }
411 }
412 else
413 {
414 i.add_to(terms);
415 }
416
417 if (terms.back().empty())
418 {
419 // pop unused ending '|' (or BRE '\|')
420 terms.pop_back();
421 if (flag_basic_regexp)
422 terms.pop_back();
423 }
424 }
425 }
426 else if (op == OpTree::OR)
427 {
428 for (const auto& i : list)
429 i.add_to(terms);
430 }
431 else
432 {
433 add_to(terms);
434 }
435}
436
437// add a [NOT] term of the operator tree to terms
438void CNF::OpTree::add_to(Terms& terms) const

Callers

nothing calls this directly

Calls 5

add_toMethod · 0.80
emptyMethod · 0.45
backMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected