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

Method RemoveLeadingRegexp

extern/re2/re2/parse.cc:746–770  ·  view source on GitHub ↗

Removes LeadingRegexp(re) from re and returns what's left. Consumes the reference to re and may edit it in place. If caller wants to hold on to LeadingRegexp(re), must have already Incref'ed it.

Source from the content-addressed store, hash-verified

744// If caller wants to hold on to LeadingRegexp(re),
745// must have already Incref'ed it.
746Regexp* Regexp::RemoveLeadingRegexp(Regexp* re) {
747 if (re->op() == kRegexpEmptyMatch)
748 return re;
749 if (re->op() == kRegexpConcat && re->nsub() >= 2) {
750 Regexp** sub = re->sub();
751 if (sub[0]->op() == kRegexpEmptyMatch)
752 return re;
753 sub[0]->Decref();
754 sub[0] = NULL;
755 if (re->nsub() == 2) {
756 // Collapse concatenation to single regexp.
757 Regexp* nre = sub[1];
758 sub[1] = NULL;
759 re->Decref();
760 return nre;
761 }
762 // 3 or more -> 2 or more.
763 re->nsub_--;
764 memmove(sub, sub + 1, re->nsub_ * sizeof sub[0]);
765 return re;
766 }
767 Regexp::ParseFlags pf = re->parse_flags();
768 re->Decref();
769 return new Regexp(kRegexpEmptyMatch, pf);
770}
771
772// Returns the leading string that re starts with.
773// The returned Rune* points into a piece of re,

Callers

nothing calls this directly

Calls 5

nsubMethod · 0.80
parse_flagsMethod · 0.80
opMethod · 0.45
subMethod · 0.45
DecrefMethod · 0.45

Tested by

no test coverage detected