Lines Matching refs:re
60 bool PushRegexp(Regexp* re);
180 for (Regexp* re = stacktop_; re != NULL; re = next) {
181 next = re->down_;
182 re->down_ = NULL;
183 if (re->op() == kLeftParen)
184 delete re->name_;
185 re->Decref();
192 Regexp* Regexp::ParseState::FinishRegexp(Regexp* re) {
193 if (re == NULL)
195 re->down_ = NULL;
197 if (re->op_ == kRegexpCharClass && re->ccb_ != NULL) {
198 CharClassBuilder* ccb = re->ccb_;
199 re->ccb_ = NULL;
200 re->cc_ = ccb->GetCharClass();
204 return re;
209 bool Regexp::ParseState::PushRegexp(Regexp* re) {
217 if (re->op_ == kRegexpCharClass) {
218 if (re->ccb_->size() == 1) {
219 Rune r = re->ccb_->begin()->lo;
220 re->Decref();
221 re = new Regexp(kRegexpLiteral, flags_);
222 re->rune_ = r;
223 } else if (re->ccb_->size() == 2) {
224 Rune r = re->ccb_->begin()->lo;
225 if ('A' <= r && r <= 'Z' && re->ccb_->Contains(r + 'a' - 'A')) {
226 re->Decref();
227 re = new Regexp(kRegexpLiteral, flags_ | FoldCase);
228 re->rune_ = r + 'a' - 'A';
233 if (!IsMarker(re->op()))
234 re->simple_ = re->ComputeSimple();
235 re->down_ = stacktop_;
236 stacktop_ = re;
326 if (!cc->AddRange(lo, hi)) // lo-hi was already there? we're done
371 Regexp* re = new Regexp(kRegexpCharClass, flags_ & ~FoldCase);
372 re->ccb_ = new CharClassBuilder;
376 re->ccb_->AddRange(r, r);
380 re->ccb_->RemoveAbove(rune_max_);
381 return PushRegexp(re);
392 Regexp* re = new Regexp(kRegexpLiteral, flags_);
393 re->rune_ = r;
394 return PushRegexp(re);
431 Regexp* re = new Regexp(kRegexpCharClass, flags_ & ~FoldCase);
432 re->ccb_ = new CharClassBuilder;
433 re->ccb_->AddRange(0, '\n' - 1);
434 re->ccb_->AddRange('\n' + 1, rune_max_);
435 return PushRegexp(re);
440 Regexp* re = new Regexp(op, flags_);
441 return PushRegexp(re);
457 Regexp* re = new Regexp(op, fl);
458 re->AllocSub(1);
459 re->down_ = stacktop_->down_;
460 re->sub()[0] = FinishRegexp(stacktop_);
461 re->simple_ = re->ComputeSimple();
462 stacktop_ = re;
484 Regexp* re = new Regexp(kRegexpRepeat, fl);
485 re->min_ = min;
486 re->max_ = max;
487 re->AllocSub(1);
488 re->down_ = stacktop_->down_;
489 re->sub()[0] = FinishRegexp(stacktop_);
490 re->simple_ = re->ComputeSimple();
492 stacktop_ = re;
504 Regexp* re = new Regexp(kLeftParen, flags_);
505 re->cap_ = ++ncap_;
507 re->name_ = new string(name.as_string());
508 return PushRegexp(re);
513 Regexp* re = new Regexp(kLeftParen, flags_);
514 re->cap_ = -1;
515 return PushRegexp(re);
609 Regexp* re = r2;
610 flags_ = re->parse_flags();
613 if (re->cap_ > 0) {
614 re->op_ = kRegexpCapture;
615 // re->cap_ is already set
616 re->AllocSub(1);
617 re->sub()[0] = FinishRegexp(r1);
618 re->simple_ = re->ComputeSimple();
620 re->Decref();
621 re = r1;
623 return PushRegexp(re);
629 Regexp* re = stacktop_;
630 if (re != NULL && re->down_ != NULL) {
636 return FinishRegexp(re);
639 // Returns the leading regexp that re starts with.
640 // The returned Regexp* points into a piece of re,
641 // so it must not be used after the caller calls re->Decref().
642 Regexp* Regexp::LeadingRegexp(Regexp* re) {
643 if (re->op() == kRegexpEmptyMatch)
645 if (re->op() == kRegexpConcat && re->nsub() >= 2) {
646 Regexp** sub = re->sub();
651 return re;
654 // Removes LeadingRegexp(re) from re and returns what's left.
655 // Consumes the reference to re and may edit it in place.
656 // If caller wants to hold on to LeadingRegexp(re),
658 Regexp* Regexp::RemoveLeadingRegexp(Regexp* re) {
659 if (re->op() == kRegexpEmptyMatch)
660 return re;
661 if (re->op() == kRegexpConcat && re->nsub() >= 2) {
662 Regexp** sub = re->sub();
664 return re;
667 if (re->nsub() == 2) {
671 re->Decref();
675 re->nsub_--;
676 memmove(sub, sub + 1, re->nsub_ * sizeof sub[0]);
677 return re;
679 Regexp::ParseFlags pf = re->parse_flags();
680 re->Decref();
684 // Returns the leading string that re starts with.
685 // The returned Rune* points into a piece of re,
686 // so it must not be used after the caller calls re->Decref().
687 Rune* Regexp::LeadingString(Regexp* re, int *nrune,
689 while (re->op() == kRegexpConcat && re->nsub() > 0)
690 re = re->sub()[0];
692 *flags = static_cast<Regexp::ParseFlags>(re->parse_flags_ & Regexp::FoldCase);
694 if (re->op() == kRegexpLiteral) {
696 return &re->rune_;
699 if (re->op() == kRegexpLiteralString) {
700 *nrune = re->nrunes_;
701 return re->runes_;
708 // Removes the first n leading runes from the beginning of re.
709 // Edits re in place.
710 void Regexp::RemoveLeadingString(Regexp* re, int n) {
718 while (re->op() == kRegexpConcat) {
720 stk[d++] = re;
721 re = re->sub()[0];
724 // Remove leading string from re.
725 if (re->op() == kRegexpLiteral) {
726 re->rune_ = 0;
727 re->op_ = kRegexpEmptyMatch;
728 } else if (re->op() == kRegexpLiteralString) {
729 if (n >= re->nrunes_) {
730 delete[] re->runes_;
731 re->runes_ = NULL;
732 re->nrunes_ = 0;
733 re->op_ = kRegexpEmptyMatch;
734 } else if (n == re->nrunes_ - 1) {
735 Rune rune = re->runes_[re->nrunes_ - 1];
736 delete[] re->runes_;
737 re->runes_ = NULL;
738 re->nrunes_ = 0;
739 re->rune_ = rune;
740 re->op_ = kRegexpLiteral;
742 re->nrunes_ -= n;
743 memmove(re->runes_, re->runes_ + n, re->nrunes_ * sizeof re->runes_[0]);
747 // If re is now empty, concatenations might simplify too.
749 re = stk[d];
750 Regexp** sub = re->sub();
755 switch (re->nsub()) {
759 LOG(DFATAL) << "Concat of " << re->nsub();
760 re->submany_ = NULL;
761 re->op_ = kRegexpEmptyMatch;
765 // Replace re with sub[1].
768 re->Swap(old);
775 re->nsub_--;
776 memmove(sub, sub + 1, re->nsub_ * sizeof sub[0]);
954 Regexp* re = sub[j];
955 if (re->op() == kRegexpCharClass) {
956 CharClass* cc = re->cc();
959 } else if (re->op() == kRegexpLiteral) {
960 ccb.AddRangeFlags(re->rune(), re->rune(), re->parse_flags());
962 LOG(DFATAL) << "RE2: unexpected op: " << re->op() << " "
963 << re->ToString();
965 re->Decref();
1031 Regexp* re = ConcatOrAlternate(op, subs, n, flags_, true);
1033 re->simple_ = re->ComputeSimple();
1034 re->down_ = next;
1035 stacktop_ = re;
1044 Regexp* re = new Regexp(kRegexpEmptyMatch, flags_);
1045 PushRegexp(re);
1451 // But if we're adding the negation of the group,
1457 // Normally AddRangeFlags does this, but we're bypassing AddRangeFlags.
1673 Regexp* re = new Regexp(kRegexpCharClass, flags_ & ~FoldCase);
1674 re->ccb_ = new CharClassBuilder;
1682 re->ccb_->AddRange('\n', '\n');
1696 re->Decref();
1701 re->Decref();
1708 switch (ParseCCName(s, flags_, re->ccb_, status)) {
1712 re->Decref();
1723 switch (ParseUnicodeGroup(s, flags_, re->ccb_, status)) {
1727 re->Decref();
1737 AddUGroup(re->ccb_, g, g->sign, flags_);
1744 re->Decref();
1752 re->ccb_->AddRangeFlags(rr.lo, rr.hi, flags_ | Regexp::ClassNL);
1757 re->Decref();
1763 re->ccb_->Negate();
1764 re->ccb_->RemoveAbove(rune_max_);
1766 *out_re = re;
2046 Regexp* re;
2047 if (!ps.ParseCharClass(&t, &re, status))
2049 if (!ps.PushRegexp(re))
2174 Regexp* re = new Regexp(kRegexpCharClass, ps.flags() & ~FoldCase);
2175 re->ccb_ = new CharClassBuilder;
2176 re->ccb_, status)) {
2178 if (!ps.PushRegexp(re))
2182 re->Decref();
2185 re->Decref();
2192 Regexp* re = new Regexp(kRegexpCharClass, ps.flags() & ~FoldCase);
2193 re->ccb_ = new CharClassBuilder;
2194 AddUGroup(re->ccb_, g, g->sign, ps.flags());
2195 if (!ps.PushRegexp(re))