@Override public boolean isCaseSensitive() { // We could test // !ranges.equals(CaseCanonicalize.expandToAllMatched(ranges)) // but we get better optimizations by leaving the 'i' flag on in most // cases. // Check whether skipping all the character groups that are known // case-insensitive leaves us with something that matches the above // definition. CharRanges withoutNamedGroups = decompose().ranges; return !withoutNamedGroups.equals( CaseCanonicalize.expandToAllMatched(withoutNamedGroups)); }
DecomposedCharset decompose() { CharRanges negRanges = CharRanges.ALL_CODE_UNITS.difference(ranges); if (!ieExplicits.isEmpty()) { if (negRanges.intersection(ieExplicits).isEmpty()) { return decompose(ranges, false); } else if (ranges.intersection(ieExplicits).isEmpty()) { return decompose(negRanges, true); } } DecomposedCharset positive = decompose(ranges, false); DecomposedCharset negative = decompose(negRanges, true); return positive.complexity() <= negative.complexity() ? positive : negative; }
@Override public RegExpTree simplify(String flags) { RegExpTree simpleBody = body.simplify(flags); if (simpleBody instanceof Empty) { if (positive) { // Always true return simpleBody; } } return new LookaheadAssertion(simpleBody, positive); }
@Override protected void appendSourceCode(StringBuilder sb) { if (DOT_CHARSET.ranges.equals(ranges)) { sb.append('.'); return; } decompose().appendSourceCode(sb); }
@Override public RegExpTree simplify(String flags) { return new CapturingGroup(body.simplify(flags)); }
/** * Returns an instance containing all and only the given members. */ public static CharRanges withMembers(int... members) { return new CharRanges(intArrayToRanges(members)); }
@Override public RegExpTree simplify(String flags) { RegExpTree simpleBody = body.simplify(flags); if (simpleBody instanceof Empty) { if (positive) { // Always true return simpleBody; } } return new LookbehindAssertion(simpleBody, positive); }
@Override public RegExpTree simplify(String flags) { return new NamedCaptureGroup(body.simplify(flags), name); }
/** * True if the regular expression contains capturing groups. */ public final boolean hasCapturingGroup() { return numCapturingGroups() != 0; }
@Override public int hashCode() { return 0x55781738 ^ body.hashCode(); } }
@Override public boolean equals(Object o) { if (!(o instanceof LookaheadAssertion)) { return false; } LookaheadAssertion that = (LookaheadAssertion) o; return this.positive == that.positive && this.body.equals(that.body); }
@Override public int hashCode() { return ranges.hashCode() ^ 0xdede2246; } }
@Override public boolean isCaseSensitive() { for (RegExpTree element : elements) { if (element.isCaseSensitive()) { return true; } } return false; }
DecomposedCharset decompose() { CharRanges negRanges = CharRanges.ALL_CODE_UNITS.difference(ranges); if (!ieExplicits.isEmpty()) { if (negRanges.intersection(ieExplicits).isEmpty()) { return decompose(ranges, false); } else if (ranges.intersection(ieExplicits).isEmpty()) { return decompose(negRanges, true); } } DecomposedCharset positive = decompose(ranges, false); DecomposedCharset negative = decompose(negRanges, true); return positive.complexity() <= negative.complexity() ? positive : negative; }
@Override public boolean isCaseSensitive() { // We could test // !ranges.equals(CaseCanonicalize.expandToAllMatched(ranges)) // but we get better optimizations by leaving the 'i' flag on in most // cases. // Check whether skipping all the character groups that are known // case-insensitive leaves us with something that matches the above // definition. CharRanges withoutNamedGroups = decompose().ranges; return !withoutNamedGroups.equals( CaseCanonicalize.expandToAllMatched(withoutNamedGroups)); }
@Override protected void appendSourceCode(StringBuilder sb) { if (DOT_CHARSET.ranges.equals(ranges)) { sb.append('.'); return; } decompose().appendSourceCode(sb); }
@Override public RegExpTree simplify(String flags) { RegExpTree simpleBody = body.simplify(flags); if (simpleBody instanceof Empty) { if (positive) { // Always true return simpleBody; } } return new LookaheadAssertion(simpleBody, positive); }
@Override public RegExpTree simplify(String flags) { return new CapturingGroup(body.simplify(flags)); }
@Override public int numCapturingGroups() { int n = 0; for (RegExpTree alternative : alternatives) { n += alternative.numCapturingGroups(); } return n; }
@Override public int hashCode() { return 0x723aba9 ^ body.hashCode(); } }