| java.lang.Object | |
| ↳ | com.google.gdata.util.common.base.CharMatcher |
Determines a true or false value for any Java 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 character c for which this.matches(c) returns true".
Note: This class deals only with char values; it does not
understand supplementary Unicode code points in the range 0x10000 to
0x10FFFF. Such logical characters are encoded into a String
using surrogate pairs, and a CharMatcher treats these just as two
separate characters.
| Nested Classes | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| CharMatcher.LookupTable | A bit array with one bit per char value, used by precomputed(). |
||||||||||
| Constants | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| String | ZEROES | ||||||||||
| Fields | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| ANY | Matches any character. | ||||||||||
| ASCII | Determines whether a character is ASCII, meaning that its code point is less than 128. | ||||||||||
| DIGIT | Determines whether a character is a digit according to Unicode. | ||||||||||
| INVISIBLE | 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. | ||||||||||
| JAVA_DIGIT | Determines whether a character is a digit according to Java's definition. |
||||||||||
| JAVA_ISO_CONTROL | Determines whether a character is an ISO control character according to
isISOControl(char). |
||||||||||
| JAVA_LETTER | Determines whether a character is a letter according to Java's definition. |
||||||||||
| JAVA_LETTER_OR_DIGIT | Determines whether a character is a letter or digit according to Java's definition. |
||||||||||
| JAVA_LOWER_CASE | Determines whether a character is lower case according to Java's definition. |
||||||||||
| JAVA_UPPER_CASE | Determines whether a character is upper case according to Java's definition. |
||||||||||
| JAVA_WHITESPACE | Determines whether a character is whitespace according to Java's definition; it is usually preferable
to use WHITESPACE. |
||||||||||
| LEGACY_WHITESPACE | Determines whether a character is whitespace according to an arbitrary
definition used by StringUtil for years. |
||||||||||
| NONE | Matches no characters. | ||||||||||
| WHITESPACE | Determines whether a character is whitespace according to the latest Unicode standard, as illustrated here. | ||||||||||
| Public Constructors | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| Public Methods | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
Returns a matcher that matches any character matched by both this matcher
and
other. | |||||||||||
Returns a
char matcher that matches any character present in the
given character sequence. | |||||||||||
Returns
true if this matcher matches the given character. | |||||||||||
Returns a string copy of the input character sequence, with each group of
consecutive characters that match this matcher replaced by a single
replacement character.
| |||||||||||
Returns the number of matching characters found in a character sequence.
| |||||||||||
Returns a matcher with identical behavior to the given Character-based predicate, but which operates on primitive
char
instances instead. | |||||||||||
Returns a
char matcher that matches any character in a given range
(both endpoints are inclusive). | |||||||||||
Returns the index of the first matching character in a character sequence,
or
-1 if no matching character is present. | |||||||||||
Returns the index of the first matching character in a character sequence,
starting from a given position, or
-1 if no character matches after
that position. | |||||||||||
Returns a
char matcher that matches only one specified character. | |||||||||||
Returns a
char matcher that matches any character except the one
specified. | |||||||||||
Returns the index of the last matching character in a character sequence,
or
-1 if no matching character is present. | |||||||||||
Determines a true or false value for the given character.
| |||||||||||
Returns
true if a character sequence contains only matching
characters. | |||||||||||
Returns
true if a character sequence contains no matching
characters. | |||||||||||
Returns a matcher that matches any character not matched by this matcher.
| |||||||||||
Returns a
char matcher that matches any character not present in
the given character sequence. | |||||||||||
Returns a matcher that matches any character matched by either this matcher
or
other. | |||||||||||
Returns a
char matcher functionally equivalent to this one, but
with its configuration cached in an eight-kilobyte bit array. | |||||||||||
Returns a string containing all non-matching characters of a character
sequence, in order.
| |||||||||||
Returns a string copy of the input character sequence, with each character
that matches this matcher replaced by a given replacement character.
| |||||||||||
Returns a string copy of the input character sequence, with each character
that matches this matcher replaced by a given replacement sequence.
| |||||||||||
Returns a string containing all matching characters of a character
sequence, in order.
| |||||||||||
Collapses groups of matching characters exactly as
collapseFrom(CharSequence, char)
does, except that groups of matching characters at the start or end of the
sequence are removed without replacement. | |||||||||||
Returns a substring of the input character sequence that omits all
characters this matcher matches from the beginning and from the end of the
string.
| |||||||||||
Returns a substring of the input character sequence that omits all
characters this matcher matches from the beginning of the
string.
| |||||||||||
Returns a substring of the input character sequence that omits all
characters this matcher matches from the end of the
string.
| |||||||||||
| Protected Methods | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
For use by implementors; sets the bit corresponding to each character ('\0'
to '') that matches this matcher in the given bit array, leaving all
other bits untouched.
| |||||||||||
|
[Expand]
Inherited Methods | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.lang.Object
| |||||||||||
From interface
com.google.gdata.util.common.base.Predicate
| |||||||||||
Determines whether a character is ASCII, meaning that its code point is less than 128.
Determines whether a character is a digit according to Unicode.
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.
Determines whether a character is a digit according to Java's definition. If you only care to match
ASCII digits, you can use inRange('0', '9').
Determines whether a character is an ISO control character according to
isISOControl(char).
Determines whether a character is a letter according to Java's definition. If you only care to match
letters of the Latin alphabet, you can use inRange('a', 'z').or(inRange('A', 'Z')).
Determines whether a character is a letter or digit according to Java's definition.
Determines whether a character is lower case according to Java's definition.
Determines whether a character is upper case according to Java's definition.
Determines whether a character is whitespace according to Java's definition; it is usually preferable
to use WHITESPACE. See a comparison of several definitions of
"whitespace" at go/white+space.
Determines whether a character is whitespace according to an arbitrary
definition used by StringUtil for years.
Most likely you don't want to use this. See a comparison of several
definitions of "whitespace" at
go/white+space.
Determines whether a character is whitespace according to the latest Unicode standard, as illustrated here. This is not the same definition used by other Java APIs. See a comparison of several definitions of "whitespace" at go/white+space. Note: as the Unicode definition evolves, we will modify this constant to keep it up to date.
Returns a matcher that matches any character matched by both this matcher
and other.
| other |
|---|
Returns a char matcher that matches any character present in the
given character sequence.
| sequence |
|---|
Returns true if this matcher matches the given character.
| character |
|---|
| NullPointerException | if character is null
|
|---|
Returns a string copy of the input character sequence, with each group of consecutive characters that match this matcher replaced by a single replacement character. For example:
CharMatcher.anyOf("eko").collapseFrom("bookkeeper", '-')
... returns "b-p-r".
The default implementation uses indexIn(CharSequence) to find
the first matching character, then iterates the remainder of the sequence
calling matches(char) for each character.
| sequence | The character sequence to replace matching groups of characters in |
|---|---|
| replacement | The character to append to the result string in place of
each group of matching characters in sequence |
Returns the number of matching characters found in a character sequence.
| sequence |
|---|
Returns a matcher with identical behavior to the given Character-based predicate, but which operates on primitive char
instances instead.
| predicate |
|---|
Returns a char matcher that matches any character in a given range
(both endpoints are inclusive). For example, to match any lowercase letter
of the English alphabet, use CharMatcher.inRange('a', 'z').
| startInclusive | |
|---|---|
| endInclusive |
| IllegalArgumentException | if endInclusive < startInclusive
|
|---|
Returns the index of the first matching character in a character sequence,
or -1 if no matching character is present.
The default implementation iterates over the sequence in forward order
calling matches(char) for each character.
| sequence | The character sequence to examine from the beginning |
|---|
-1 if no character matches
Returns the index of the first matching character in a character sequence,
starting from a given position, or -1 if no character matches after
that position.
The default implementation iterates over the sequence in forward order,
beginning at start, calling matches(char) for each character.
| sequence | The character sequence to examine |
|---|---|
| start | The first index to examine; must be nonnegative and no
greater than sequence.length() |
start, or -1 if no character matches| IndexOutOfBoundsException | if start is negative or greater than
sequence.length()
|
|---|
Returns a char matcher that matches only one specified character.
| match |
|---|
Returns a char matcher that matches any character except the one
specified.
To negate another CharMatcher, use negate().
| match |
|---|
Returns the index of the last matching character in a character sequence,
or -1 if no matching character is present.
The default implementation iterates over the sequence in reverse order
calling matches(char) for each character.
| sequence | The character sequence to examine from the end |
|---|
-1 if no character matches
Determines a true or false value for the given character.
| c |
|---|
Returns true if a character sequence contains only matching
characters.
The default implementation iterates over the sequence, invoking matches(char) for each character, until this returns false or the end
is reached.
| sequence | The character sequence to examine, possibly empty |
|---|
true if this matcher matches every character in the
sequence, including when the sequence is empty
Returns true if a character sequence contains no matching
characters.
The default implementation iterates over the sequence, invoking matches(char) for each character, until this returns false or the end is
reached.
| sequence | The character sequence to examine, possibly empty |
|---|
true if this matcher matches every character in the
sequence, including when the sequence is empty
Returns a matcher that matches any character not matched by this matcher.
Returns a char matcher that matches any character not present in
the given character sequence.
| sequence |
|---|
Returns a matcher that matches any character matched by either this matcher
or other.
| other |
|---|
Returns a char matcher functionally equivalent to this one, but
with its configuration cached in an eight-kilobyte bit array. In some
situations this produces a matcher which is faster to query than the
original; your mileage may vary.
The default implementation creates a new bit array and passes it to
setBits(LookupTable).
Returns a string containing all non-matching characters of a character sequence, in order. For example:
CharMatcher.is('a').removeFrom("bazaar")
... returns "bzr".
| sequence |
|---|
Returns a string copy of the input character sequence, with each character that matches this matcher replaced by a given replacement character. For example:
CharMatcher.is('a').replaceFrom("radar", 'o')
... returns "rodor".
The default implementation uses indexIn(CharSequence) to find
the first matching character, then iterates the remainder of the sequence
calling matches(char) for each character.
| sequence | The character sequence to replace matching characters in |
|---|---|
| replacement | The character to append to the result string in place of
each matching character in sequence |
Returns a string copy of the input character sequence, with each character that matches this matcher replaced by a given replacement sequence. For example:
CharMatcher.is('a').replaceFrom("yaha", "oo")
... returns "yoohoo".
Note: If the replacement is a fixed string with only one character,
you are better off calling replaceFrom(CharSequence, char) directly.
| sequence | The character sequence to replace matching characters in |
|---|---|
| replacement | The characters to append to the result string in place
of each matching character in sequence |
Returns a string containing all matching characters of a character sequence, in order. For example:
CharMatcher.is('a').retainFrom("bazaar")
... returns "aaa".
| sequence |
|---|
Collapses groups of matching characters exactly as collapseFrom(CharSequence, char)
does, except that groups of matching characters at the start or end of the
sequence are removed without replacement.
| sequence | |
|---|---|
| replacement |
Returns a substring of the input character sequence that omits all characters this matcher matches from the beginning and from the end of the string. For example:
CharMatcher.anyOf("ab").trimFrom("abacatbab")
... returns "cat".
Note that
CharMatcher.inRange('\0', ' ').trimFrom(str)
... is equivalent to trim().
| sequence |
|---|
Returns a substring of the input character sequence that omits all characters this matcher matches from the beginning of the string. For example:
CharMatcher.anyOf("ab").trimLeadingFrom("abacatbab")
... returns "catbab".
| sequence |
|---|
Returns a substring of the input character sequence that omits all characters this matcher matches from the end of the string. For example:
CharMatcher.anyOf("ab").trimTrailingFrom("abacatbab")
... returns "abacat".
| sequence |
|---|
For use by implementors; sets the bit corresponding to each character ('\0' to '') that matches this matcher in the given bit array, leaving all other bits untouched.
The default implementation loops over every possible character value,
invoking matches(char) for each one.
| table |
|---|