/** * If a char sequence is adjacent to a starts with matcher, then append the sequence to * the prefix pattern of the starts with matcher. */ static Matcher combineCharSeqAfterStartsWith(Matcher matcher) { if (matcher instanceof SeqMatcher) { List<Matcher> matchers = matcher.<SeqMatcher>as().matchers(); if (matchers.size() >= 2 && matchers.get(0) instanceof StartsWithMatcher && matchers.get(1) instanceof CharSeqMatcher) { List<Matcher> ms = new ArrayList<>(); String prefix = matchers.get(0).<StartsWithMatcher>as().pattern() + matchers.get(1).<CharSeqMatcher>as().pattern(); ms.add(new StartsWithMatcher(prefix)); ms.addAll(matchers.subList(2, matchers.size())); return SeqMatcher.create(ms); } else { return matcher; } } return matcher; }
/** * If a char sequence is adjacent to a starts with matcher, then append the sequence to * the prefix pattern of the starts with matcher. */ static Matcher combineCharSeqAfterStartsWith(Matcher matcher) { if (matcher instanceof SeqMatcher) { List<Matcher> matchers = matcher.<SeqMatcher>as().matchers(); if (matchers.size() >= 2 && matchers.get(0) instanceof StartsWithMatcher && matchers.get(1) instanceof CharSeqMatcher) { List<Matcher> ms = new ArrayList<>(); String prefix = matchers.get(0).<StartsWithMatcher>as().pattern() + matchers.get(1).<CharSeqMatcher>as().pattern(); ms.add(new StartsWithMatcher(prefix)); ms.addAll(matchers.subList(2, matchers.size())); return SeqMatcher.create(ms); } else { return matcher; } } return matcher; }
/** Convert to a matchers that ignores the case. */ static Matcher ignoreCase(Matcher matcher) { if (matcher instanceof CharClassMatcher) { CharClassMatcher m = matcher.as(); return new CharClassMatcher(m.set(), true); } else if (matcher instanceof CharSeqMatcher) { CharSeqMatcher m = matcher.as(); return new CharSeqMatcher(m.pattern(), true); } else if (matcher instanceof IndexOfMatcher) { IndexOfMatcher m = matcher.as(); return new IndexOfMatcher(m.pattern(), m.next(), true); } else if (matcher instanceof StartsWithMatcher) { StartsWithMatcher m = matcher.as(); return new StartsWithMatcher(m.pattern(), true); } else { return matcher; } }
/** Convert to a matchers that ignores the case. */ static Matcher ignoreCase(Matcher matcher) { if (matcher instanceof CharClassMatcher) { CharClassMatcher m = matcher.as(); return new CharClassMatcher(m.set(), true); } else if (matcher instanceof CharSeqMatcher) { CharSeqMatcher m = matcher.as(); return new CharSeqMatcher(m.pattern(), true); } else if (matcher instanceof IndexOfMatcher) { IndexOfMatcher m = matcher.as(); return new IndexOfMatcher(m.pattern(), m.next(), true); } else if (matcher instanceof StartsWithMatcher) { StartsWithMatcher m = matcher.as(); return new StartsWithMatcher(m.pattern(), true); } else { return matcher; } }