char value, just as Predicate does
for any Object. Also offers basic text processing methods based on this function.
Implementations are strongly encouraged to be side-effect-free and immutable.
Throughout the documentation of this class, the phrase "matching character" is used to mean
"any char value c for which this.matches(c) returns true".
Warning
This class deals only with char values, that is, BMP characters. It does not understand
supplementary Unicode code
points in the range 0x10000 to 0x10FFFF which includes the majority of
assigned characters, including important CJK characters and emoji.
Supplementary characters are encoded
into a String using surrogate pairs, and a CharMatcher treats these just as
two separate characters. countIn counts each supplementary character as 2 chars.
For up-to-date Unicode character properties (digit, letter, etc.) and support for supplementary code points, use ICU4J UCharacter and UnicodeSet (freeze() after building). For basic text processing based on UnicodeSet use the ICU4J UnicodeSetSpanner.
Example usages:
String trimmed =whitespace().trimFrom(userInput); if (ascii().matchesAllOf(s)) { ... }
See the Guava User Guide article on CharMatcher
.
| Modifier and Type | Class and Description |
|---|---|
| private static class | CharMatcher.
Implementation of |
| private static class | CharMatcher.
Implementation of |
| private static class | CharMatcher.
Implementation of |
| private static class | CharMatcher.
Implementation of |
| private static class | CharMatcher.
Fast matcher using a |
| private static class | CharMatcher.
Implementation of |
| private static class | CharMatcher.
Implementation of |
| pack-priv abstract static class | CharMatcher.
A matcher for which precomputation will not yield any significant benefit. |
| private static class | CharMatcher.
Implementation of |
| private static class | CharMatcher.
Implementation of |
| private static class | CharMatcher.
Implementation of |
| private static class | CharMatcher.
Implementation of |
| private static class | CharMatcher.
Implementation of |
| private static class | CharMatcher.
Implementation of |
| private static class | CharMatcher.
Implementation of |
| private static class | CharMatcher.
Implementation of |
| private static class | CharMatcher.
Implementation of |
| private static class | CharMatcher.
Implementation of |
| private static class | CharMatcher.
Implementation of |
| private static class | CharMatcher.
Implementation of |
| pack-priv abstract static class | CharMatcher.
|
| private static class | CharMatcher.
Implementation of |
| private static class | CharMatcher.
Negation of a |
| private static class | CharMatcher.
Implementation of |
| private static class | CharMatcher.
Implementation of |
| private static class | CharMatcher.
Implementation that matches characters that fall within multiple ranges. |
| private static class | CharMatcher.
Implementation of |
| pack-priv static class | CharMatcher.
Implementation of |
| Modifier and Type | Field and Description |
|---|---|
| private static final int |
| Access | Constructor and Description |
|---|---|
| protected |
| Modifier and Type | Method and Description |
|---|---|
| public CharMatcher | and(CharMatcher other)
Returns a matcher that matches any character matched by both this matcher and |
| public static CharMatcher | |
| public static CharMatcher | anyOf(final CharSequence sequence)
Returns a |
| public boolean | apply(Character character)
Implements com. input (Java 8+ users, see notes in the
class documentation above).
|
| public static CharMatcher | |
| public static CharMatcher | breakingWhitespace()
Determines whether a character is a breaking whitespace (that is, a whitespace which can be interpreted as a break between words for formatting purposes). |
| public String | Returns: the new stringthe character sequence to replace matching groups of characters in sequence, char the character to append to the result string in place of each group of
matching characters in replacement)sequenceReturns a string copy of the input character sequence, with each group of consecutive matching BMP characters replaced by a single replacement character. |
| public int | |
| public static CharMatcher | |
| private String | finishCollapseFrom(CharSequence sequence, int start, int end, char replacement, StringBuilder builder, boolean inMatchingGroup)
|
| public static CharMatcher | forPredicate(final Predicate<? super Character> predicate)
Returns a matcher with identical behavior to the given |
| public int | Returns: an index, or-1 if no character matchesthe character sequence to examine from the beginning sequence)Returns the index of the first matching BMP character in a character sequence, or |
| public int | Returns: the index of the first matching character, guaranteed to be no less thanstart,
or -1 if no character matchesthe character sequence to examine sequence, int the first index to examine; must be nonnegative and no greater than start)sequence.length()Returns the index of the first matching BMP character in a character sequence, starting from a
given position, or |
| public static CharMatcher | inRange(final char startInclusive, final char endInclusive)
Returns a |
| public static CharMatcher | invisible()
Deprecated
Most invisible characters are supplementary characters; see the class
documentation.
Determines whether a character is invisible; that is, if its Unicode category is any of
SPACE_SEPARATOR, LINE_SEPARATOR, PARAGRAPH_SEPARATOR, CONTROL, FORMAT, SURROGATE, and
PRIVATE_USE according to ICU4J.
|
| public static CharMatcher | |
| private static CharMatcher. | |
| public static CharMatcher | isNot(final char match)
Returns a |
| private static boolean | |
| public static CharMatcher | javaDigit()
Deprecated
Many digits are supplementary characters; see the class documentation.
Determines whether a character is a BMP digit according to Java's definition.
|
| public static CharMatcher | javaIsoControl()
Determines whether a character is an ISO control character as specified by |
| public static CharMatcher | javaLetter()
Deprecated
Most letters are supplementary characters; see the class documentation.
Determines whether a character is a BMP letter according to Java's definition.
|
| public static CharMatcher | javaLetterOrDigit()
Deprecated
Most letters and digits are supplementary characters; see the class documentation.
Determines whether a character is a BMP letter or digit according to Java's definition.
|
| public static CharMatcher | javaLowerCase()
Deprecated
Some lowercase characters are supplementary characters; see the class
documentation.
Determines whether a BMP character is lower case according to Java's definition.
|
| public static CharMatcher | javaUpperCase()
Deprecated
Some uppercase characters are supplementary characters; see the class
documentation.
Determines whether a BMP character is upper case according to Java's definition.
|
| public int | Returns: an index, or-1 if no character matchesthe character sequence to examine from the end sequence)Returns the index of the last matching BMP character in a character sequence, or |
| public abstract boolean | |
| public boolean | Returns: true if this matcher matches every character in the sequence, including when
the sequence is emptythe character sequence to examine, possibly empty sequence)Returns |
| public boolean | Returns: true if this matcher matches at least one character in the sequencethe character sequence to examine, possibly empty sequence)Returns |
| public boolean | Returns: true if this matcher matches no characters in the sequence, including when the
sequence is emptythe character sequence to examine, possibly empty sequence)Returns |
| public CharMatcher | negate()
Overrides default java. |
| public static CharMatcher | |
| public static CharMatcher | noneOf(CharSequence sequence)
Returns a |
| public CharMatcher | or(CharMatcher other)
Returns a matcher that matches any character matched by either this matcher or |
| public CharMatcher | precomputed()
Returns a |
| pack-priv CharMatcher | precomputedInternal()
This is the actual implementation of |
| private static CharMatcher | precomputedPositive(int totalCharacters, BitSet table, String description)
Helper method for |
| public String | removeFrom(CharSequence sequence)
Returns a string containing all non-matching characters of a character sequence, in order. |
| public String | Returns: the new stringthe character sequence to replace matching characters in sequence, char the character to append to the result string in place of each matching
character in replacement)sequenceReturns a string copy of the input character sequence, with each matching BMP character replaced by a given replacement character. |
| public String | Returns: the new stringthe character sequence to replace matching characters in sequence, CharSequence the characters to append to the result string in place of each matching
character in replacement)sequenceReturns a string copy of the input character sequence, with each matching BMP character replaced by a given replacement sequence. |
| public String | retainFrom(CharSequence sequence)
Returns a string containing all matching BMP characters of a character sequence, in order. |
| pack-priv void | |
| private static String | showCharacter(char c)
Returns the Java Unicode escape sequence for the given |
| public static CharMatcher | singleWidth()
Deprecated
Many such characters are supplementary characters; see the class documentation.
Determines whether a character is single-width (not double-width).
|
| public String | toString()
Overrides java. CharMatcher, such as CharMatcher.or(WHITESPACE, JAVA_DIGIT).
|
| public String | trimAndCollapseFrom(CharSequence sequence, char replacement)
Collapses groups of matching characters exactly as |
| public String | trimFrom(CharSequence sequence)
Returns a substring of the input character sequence that omits all matching BMP characters from the beginning and from the end of the string. |
| public String | trimLeadingFrom(CharSequence sequence)
Returns a substring of the input character sequence that omits all matching BMP characters from the beginning of the string. |
| public String | trimTrailingFrom(CharSequence sequence)
Returns a substring of the input character sequence that omits all matching BMP characters from the end of the string. |
| public static CharMatcher | whitespace()
Determines whether a character is whitespace according to the latest Unicode standard, as illustrated here. |