MCPcopy Create free account
hub / github.com/FirebirdSQL/firebird / Search

Method Search

extern/re2/re2/nfa.cc:448–629  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

446}
447
448bool NFA::Search(const StringPiece& text, const StringPiece& const_context,
449 bool anchored, bool longest,
450 StringPiece* submatch, int nsubmatch) {
451 if (start_ == 0)
452 return false;
453
454 StringPiece context = const_context;
455 if (context.data() == NULL)
456 context = text;
457
458 // Sanity check: make sure that text lies within context.
459 if (text.begin() < context.begin() || text.end() > context.end()) {
460 LOG(DFATAL) << "context does not contain text";
461 return false;
462 }
463
464 if (prog_->anchor_start() && context.begin() != text.begin())
465 return false;
466 if (prog_->anchor_end() && context.end() != text.end())
467 return false;
468 anchored |= prog_->anchor_start();
469 if (prog_->anchor_end()) {
470 longest = true;
471 endmatch_ = true;
472 }
473
474 if (nsubmatch < 0) {
475 LOG(DFATAL) << "Bad args: nsubmatch=" << nsubmatch;
476 return false;
477 }
478
479 // Save search parameters.
480 ncapture_ = 2*nsubmatch;
481 longest_ = longest;
482
483 if (nsubmatch == 0) {
484 // We need to maintain match[0], both to distinguish the
485 // longest match (if longest is true) and also to tell
486 // whether we've seen any matches at all.
487 ncapture_ = 2;
488 }
489
490 match_ = new const char*[ncapture_];
491 memset(match_, 0, ncapture_*sizeof match_[0]);
492 matched_ = false;
493
494 // For debugging prints.
495 btext_ = context.data();
496 // For convenience.
497 etext_ = text.data() + text.size();
498
499 if (ExtraDebug)
500 fprintf(stderr, "NFA::Search %s (context: %s) anchored=%d longest=%d\n",
501 std::string(text).c_str(), std::string(context).c_str(), anchored, longest);
502
503 // Set up search.
504 Threadq* runq = &q0_;
505 Threadq* nextq = &q1_;

Callers 1

SearchNFAMethod · 0.45

Calls 15

FormatCaptureFunction · 0.85
StringPieceClass · 0.85
anchor_startMethod · 0.80
anchor_endMethod · 0.80
instMethod · 0.80
opcodeMethod · 0.80
outMethod · 0.80
can_prefix_accelMethod · 0.80
PrefixAccelMethod · 0.80
swapFunction · 0.50
dataMethod · 0.45
beginMethod · 0.45

Tested by

no test coverage detected