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:
        // continue below to handle the general case
    }
    // TODO(user): is it potentially worth just going ahead and building a precomputed matcher?
    final char[] chars = sequence.toString().toCharArray();
    Arrays.sort(chars);
    return new CharMatcher() {
      @Override public boolean matches(char c) {
        return Arrays.binarySearch(chars, c) >= 0;
      }

      @Override
      @GwtIncompatible("java.util.BitSet")
      void setBits(BitSet table) {
        for (char c : chars) {
          table.set(c);
        }
      }

      @Override public String toString() {
        StringBuilder description = new StringBuilder("CharMatcher.anyOf(\"");
        for (char c : chars) {
          description.append(showCharacter(c));
        }
        description.append("\")");
        return description.toString();
      }
    };
  }
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 : } final char [ ] chars = sequence . toString ( ) . toCharArray ( ) ; Arrays . sort ( chars ) ; return new CharMatcher ( ) { @ Override public boolean matches ( char c ) { return Arrays . binarySearch ( chars , c ) >= 0 ; } @ Override @ GwtIncompatible ( "java.util.BitSet" ) void setBits ( BitSet table ) { for ( char c : chars ) { table . set ( c ) ; } } @ Override public String toString ( ) { StringBuilder description = new StringBuilder ( "CharMatcher.anyOf(\"" ) ; for ( char c : chars ) { description . append ( showCharacter ( c ) ) ; } description . append ( "\")" ) ; return description . toString ( ) ; } } ; }
Returns a {@code char} matcher that matches any character present in the given character
sequence.