@Override public int countIn(CharSequence sequence) { return sequence.length() - original.countIn(sequence); }
/** * Returns the index of the first matching character in a character sequence, or {@code -1} if no * matching character is present. * * <p>The default implementation iterates over the sequence in forward order calling * {@link #matches} for each character. * * @param sequence the character sequence to examine from the beginning * @return an index, or {@code -1} if no character matches */ public int indexIn(CharSequence sequence) { return indexIn(sequence, 0); }
/** * Returns a {@code char} matcher that matches any character present in the given character * sequence. */ public static CharMatcher anyOf(final CharSequence sequence) { switch (sequence.length()) { case 0: return none(); case 1: return is(sequence.charAt(0)); case 2: return isEither(sequence.charAt(0), sequence.charAt(1)); default: // TODO(lowasser): is it potentially worth just going ahead and building a precomputed // matcher? return new AnyOf(sequence); } }
@Override public boolean matchesNoneOf(CharSequence sequence) { return original.matchesAllOf(sequence); }
@Override public boolean matchesAllOf(CharSequence sequence) { return original.matchesNoneOf(sequence); }
if ('\\' == tokenizer.previewChar()) { tokenizer.consumeCharacter('\\'); valueBuilder.append(tokenizer.consumeCharacter(CharMatcher.ascii())); } else { valueBuilder.append(tokenizer.consumeToken(QUOTED_TEXT_MATCHER));
@Override public boolean matches(char c) { return !original.matches(c); }
private static String normalizeToken(String token) { checkState(TOKEN_MATCHER.matchesAllOf(token), () -> String.format("Parameter '%s' doesn't match token matcher: %s", token, TOKEN_MATCHER)); return Ascii.toLowerCase(token); }
/** * Returns {@code true} if a character sequence contains at least one matching character. * Equivalent to {@code !matchesNoneOf(sequence)}. * * <p>The default implementation iterates over the sequence, invoking {@link #matches} for each * character, until this returns {@code true} or the end is reached. * * @param sequence the character sequence to examine, possibly empty * @return {@code true} if this matcher matches at least one character in the sequence * @since 8.0 */ public boolean matchesAnyOf(CharSequence sequence) { return !matchesNoneOf(sequence); }
/** * Returns {@code true} if a character sequence contains no matching characters. Equivalent to * {@code !matchesAnyOf(sequence)}. * * <p>The default implementation iterates over the sequence, invoking {@link #matches} for each * character, until this returns {@code true} or the end is reached. * * @param sequence the character sequence to examine, possibly empty * @return {@code true} if this matcher matches no characters in the sequence, including when * the sequence is empty */ public boolean matchesNoneOf(CharSequence sequence) { return indexIn(sequence) == -1; }
/** * Sets bits in {@code table} matched by this matcher. */ void setBits(BitSet table) { for (int c = Character.MAX_VALUE; c >= Character.MIN_VALUE; c--) { if (matches((char) c)) { table.set(c); } } }
/** * Returns the number of matching characters found in a character sequence. */ public int countIn(CharSequence sequence) { int count = 0; for (int i = 0; i < sequence.length(); i++) { if (matches(sequence.charAt(i))) { count++; } } return count; }
/** * Returns {@code true} if a character sequence contains only matching characters. * * <p>The default implementation iterates over the sequence, invoking {@link #matches} for each * character, until this returns {@code false} or the end is reached. * * @param sequence the character sequence to examine, possibly empty * @return {@code true} if this matcher matches every character in the sequence, including when * the sequence is empty */ public boolean matchesAllOf(CharSequence sequence) { for (int i = sequence.length() - 1; i >= 0; i--) { if (!matches(sequence.charAt(i))) { return false; } } return true; }
@Override public CharMatcher and(CharMatcher other) { return other.matches(match) ? this : none(); }
@Override public CharMatcher or(CharMatcher other) { return other.matches(match) ? other : super.or(other); }
@Override public CharMatcher and(CharMatcher other) { return other.matches(match) ? super.and(other) : other; }