MCPcopy Create free account
hub / github.com/google/re2j / simplify1

Method simplify1

java/com/google/re2j/Simplify.java:154–175  ·  view source on GitHub ↗
(Regexp.Op op, int flags, Regexp sub, Regexp re)

Source from the content-addressed store, hash-verified

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}

Callers 1

simplifyMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected