Class CharacterSet
java.lang.Object
com.google.common.labs.parse.CharacterSet
- All Implemented Interfaces:
CharPredicate
Represents a set of characters specified by a regex-like character set string.
For example charsIn("[a-zA-Z-_]") is a shorthand of
CharPredicate.range('a', 'z').orRange('A', 'Z').or('-').or('_').
You can also use '^' to get negative character set like:
charsIn("[^a-zA-Z]"), which is any non-alphabet character.
Note that it's different from CharPredicate.anyOf(string),
which treats the string as a list of literal characters, not a regex-like
character set.
It's strongly recommended to install the mug-errorprone plugin (v9.4+) in your compiler's and IDE's annotationProcessorPaths so that you can get instant feedback against incorrect character set syntax.
Implementation Note: regex isn't used during parsing. The character set string is translated
to a plain CharPredicate at construction time.
- Since:
- 9.4
-
Field Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic CharacterSetReturns aCharacterSetinstance compiled from the givencharacterSetspecifier.booleaninthashCode()booleantest(char ch) Returns true if this set contains the characterch.toString()Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface com.google.mu.util.CharPredicate
and, isPrefixOf, isSuffixOf, matchesAllOf, matchesAnyOf, matchesNoneOf, not, or, or, orRange
-
Method Details
-
charsIn
Returns aCharacterSetinstance compiled from the givencharacterSetspecifier.- Parameters:
characterSet- A regex-like character set string (e.g."[a-zA-Z0-9-_]"), but disallows backslash so doesn't support escaping. If your character set includes special characters like literal backslash or right bracket, useCharPredicateinstead.- Throws:
IllegalArgumentException- ifcharacterSetincludes backslash or the right bracket (except the outmost pairs of[]).
-
test
public boolean test(char ch) Returns true if this set contains the characterch.- Specified by:
testin interfaceCharPredicate
-
equals
-
hashCode
-
toString
-