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.
| 744 | // If caller wants to hold on to LeadingRegexp(re), |
| 745 | // must have already Incref'ed it. |
| 746 | Regexp* 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, |
nothing calls this directly
no test coverage detected