@Override public int matches(String str, int start, int length) { if (next == TrueMatcher.INSTANCE) { int pos = indexOf(str, start); return pos >= 0 ? pos + pattern.length() : Constants.NO_MATCH; } else if (next == EndMatcher.INSTANCE) { return endsWith(str, start) ? length : Constants.NO_MATCH; } else { final int end = start + length; final int stop = end - next.minLength(); int pos = start; while (pos >= 0 && pos <= stop) { pos = indexOf(str, pos); if (pos >= 0) { int s = pos + pattern.length(); int p = next.matches(str, s, end - s); if (p >= 0) { return p; } ++pos; } } return Constants.NO_MATCH; } }
@Override public int matches(String str, int start, int length) { if (next == TrueMatcher.INSTANCE) { int pos = indexOf(str, start); return pos >= 0 ? pos + pattern.length() : Constants.NO_MATCH; } else if (next == EndMatcher.INSTANCE) { return endsWith(str, start) ? length : Constants.NO_MATCH; } else { final int end = start + length; final int stop = end - next.minLength(); int pos = start; while (pos >= 0 && pos <= stop) { pos = indexOf(str, pos); if (pos >= 0) { int s = pos + pattern.length(); int p = next.matches(str, s, end - s); if (p >= 0) { return p; } ++pos; } } return Constants.NO_MATCH; } }