| 152 | // Letting them call simplify1 makes sure the expressions they |
| 153 | // generate are simple. |
| 154 | private static Regexp simplify1(Regexp.Op op, int flags, Regexp sub, Regexp re) { |
| 155 | // Special case: repeat the empty string as much as |
| 156 | // you want, but it's still the empty string. |
| 157 | if (sub.op == Regexp.Op.EMPTY_MATCH) { |
| 158 | return sub; |
| 159 | } |
| 160 | // The operators are idempotent if the flags match. |
| 161 | if (op == sub.op && (flags & RE2.NON_GREEDY) == (sub.flags & RE2.NON_GREEDY)) { |
| 162 | return sub; |
| 163 | } |
| 164 | if (re != null |
| 165 | && re.op == op |
| 166 | && (re.flags & RE2.NON_GREEDY) == (flags & RE2.NON_GREEDY) |
| 167 | && sub == re.subs[0]) { |
| 168 | return re; |
| 169 | } |
| 170 | |
| 171 | re = new Regexp(op); |
| 172 | re.flags = flags; |
| 173 | re.subs = new Regexp[] {sub}; |
| 174 | return re; |
| 175 | } |
| 176 | |
| 177 | private Simplify() {} // uninstantiable |
| 178 | } |