/** * If a character class is empty, then it will not match anything and can be treated * as false. */ static Matcher convertEmptyCharClassToFalse(Matcher matcher) { if (matcher instanceof CharClassMatcher) { return matcher.<CharClassMatcher>as().set().isEmpty() ? FalseMatcher.INSTANCE : matcher; } return matcher; }
/** * If a character class is empty, then it will not match anything and can be treated * as false. */ static Matcher convertEmptyCharClassToFalse(Matcher matcher) { if (matcher instanceof CharClassMatcher) { return matcher.<CharClassMatcher>as().set().isEmpty() ? FalseMatcher.INSTANCE : matcher; } return matcher; }
/** * If a character class has a single value, then just match that value ({@code "[a]" => "a"}). * This allows other optimizations to merge the value into adjacent matchers to get a larger * prefix or indexOf check. */ static Matcher convertSingleCharClassToSeq(Matcher matcher) { if (matcher instanceof CharClassMatcher) { Optional<Character> opt = matcher.<CharClassMatcher>as().set().character(); if (opt.isPresent()) { return new CharSeqMatcher(opt.get()); } } return matcher; }
/** * If a character class has a single value, then just match that value ({@code "[a]" => "a"}). * This allows other optimizations to merge the value into adjacent matchers to get a larger * prefix or indexOf check. */ static Matcher convertSingleCharClassToSeq(Matcher matcher) { if (matcher instanceof CharClassMatcher) { Optional<Character> opt = matcher.<CharClassMatcher>as().set().character(); if (opt.isPresent()) { return new CharSeqMatcher(opt.get()); } } 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; } }