| 640 | // leadingRegexp returns the leading regexp that re begins with. |
| 641 | // The regexp refers to storage in re or its children. |
| 642 | private static Regexp leadingRegexp(Regexp re) { |
| 643 | if (re.op == Regexp.Op.EMPTY_MATCH) { |
| 644 | return null; |
| 645 | } |
| 646 | if (re.op == Regexp.Op.CONCAT && re.subs.length > 0) { |
| 647 | Regexp sub = re.subs[0]; |
| 648 | if (sub.op == Regexp.Op.EMPTY_MATCH) { |
| 649 | return null; |
| 650 | } |
| 651 | return sub; |
| 652 | } |
| 653 | return re; |
| 654 | } |
| 655 | |
| 656 | // removeLeadingRegexp removes the leading regexp in re. |
| 657 | // It returns the replacement for re. |