- java.lang.Object
-
- io.helidon.common.http.CharMatcher
-
public abstract class CharMatcher extends Object
Extracted from Guava.Determines a true or false value for any Java
charvalue, just asPredicatedoes for anyObject. 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
charvaluecfor whichthis.matches(c)returnstrue".Warning: This class deals only with
charvalues; it does not understand supplementary Unicode code points in the range0x10000to0x10FFFF. Such logical characters are encoded into aStringusing surrogate pairs, and aCharMatchertreats these just as two separate characters.See the Guava User Guide article on
CharMatcher.- Author:
- Kevin Bourrillion
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedCharMatcher()Constructor for use by subclasses.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description CharMatcherand(CharMatcher other)Returns a matcher that matches any character matched by both this matcher andother.static CharMatcherany()Matches any character.static CharMatcheranyOf(CharSequence sequence)Returns acharmatcher that matches any character present in the given character sequence.static CharMatcherascii()Determines whether a character is ASCII, meaning that its code point is less than 128.intcountIn(CharSequence sequence)Returns the number of matching characters found in a character sequence.intindexIn(CharSequence sequence)Returns the index of the first matching character in a character sequence, or-1if no matching character is present.intindexIn(CharSequence sequence, int start)Returns the index of the first matching character in a character sequence, starting from a given position, or-1if no character matches after that position.static CharMatcheris(char match)Returns acharmatcher that matches only one specified character.static CharMatcherisNot(char match)Returns acharmatcher that matches any character except the one specified.static CharMatcherjavaIsoControl()Determines whether a character is an ISO control character as specified byCharacter.isISOControl(char).abstract booleanmatches(char c)Determines a true or false value for the given character.booleanmatchesAllOf(CharSequence sequence)Returnstrueif a character sequence contains only matching characters.booleanmatchesAnyOf(CharSequence sequence)Returnstrueif a character sequence contains at least one matching character.booleanmatchesNoneOf(CharSequence sequence)Returnstrueif a character sequence contains no matching characters.CharMatchernegate()Returns a matcher that matches any character not matched by this matcher.static CharMatchernone()Matches no character.static CharMatchernoneOf(CharSequence sequence)Returns acharmatcher that matches any character not present in the given character sequence.CharMatcheror(CharMatcher other)Returns a matcher that matches any character matched by either this matcher orother.
-
-
-
Method Detail
-
ascii
public static CharMatcher ascii()
Determines whether a character is ASCII, meaning that its code point is less than 128.- Returns:
- a CharMatcher instance that matches ASCII characters
-
isNot
public static CharMatcher isNot(char match)
Returns acharmatcher that matches any character except the one specified.To negate another
CharMatcher, usenegate().- Parameters:
match- the character that should not match- Returns:
- a CharMatcher instance that matches any character except the one specified
-
any
public static CharMatcher any()
Matches any character.- Returns:
- a CharMatcher that matches any character
-
none
public static CharMatcher none()
Matches no character.- Returns:
- a CharMatcher that matches no character
-
javaIsoControl
public static CharMatcher javaIsoControl()
Determines whether a character is an ISO control character as specified byCharacter.isISOControl(char).- Returns:
- a CharMatcher that matches ISO control character
-
is
public static CharMatcher is(char match)
Returns acharmatcher that matches only one specified character.- Parameters:
match- the character that should match- Returns:
- a CharMatcher that matches the one specified character
-
noneOf
public static CharMatcher noneOf(CharSequence sequence)
Returns acharmatcher that matches any character not present in the given character sequence.- Parameters:
sequence- all the characters that should not be matched- Returns:
- a CharMatcher that matches any character not present in the given sequence
-
anyOf
public static CharMatcher anyOf(CharSequence sequence)
Returns acharmatcher that matches any character present in the given character sequence.- Parameters:
sequence- all the characters that should be matched- Returns:
- a CharMatcher that matches any character present in the given sequence
-
matches
public abstract boolean matches(char c)
Determines a true or false value for the given character.- Parameters:
c- the character to match- Returns:
trueif thisCharMatcherinstance matches the given character,falseotherwise
-
negate
public CharMatcher negate()
Returns a matcher that matches any character not matched by this matcher.- Returns:
- new
CharMatcherinstance representing the logical negation of this instance
-
and
public CharMatcher and(CharMatcher other)
Returns a matcher that matches any character matched by both this matcher andother.- Parameters:
other- the other instance- Returns:
- new
CharMatcherinstance representing the logical and of this instance and theotherinstance
-
or
public CharMatcher or(CharMatcher other)
Returns a matcher that matches any character matched by either this matcher orother.- Parameters:
other- the other instance- Returns:
- new
CharMatcherinstance representing the logical and of this instance and theotherinstance
-
matchesAnyOf
public boolean matchesAnyOf(CharSequence sequence)
Returnstrueif a character sequence contains at least one matching character. Equivalent to!matchesNoneOf(sequence).The default implementation iterates over the sequence, invoking
matches(char)for each character, until this returnstrueor the end is reached.- Parameters:
sequence- the character sequence to examine, possibly empty- Returns:
trueif this matcher matches at least one character in the sequence- Since:
- 8.0
-
matchesAllOf
public boolean matchesAllOf(CharSequence sequence)
Returnstrueif a character sequence contains only matching characters.The default implementation iterates over the sequence, invoking
matches(char)for each character, until this returnsfalseor the end is reached.- Parameters:
sequence- the character sequence to examine, possibly empty- Returns:
trueif this matcher matches every character in the sequence, including when the sequence is empty
-
matchesNoneOf
public boolean matchesNoneOf(CharSequence sequence)
Returnstrueif a character sequence contains no matching characters. Equivalent to!matchesAnyOf(sequence).The default implementation iterates over the sequence, invoking
matches(char)for each character, until this returnstrueor the end is reached.- Parameters:
sequence- the character sequence to examine, possibly empty- Returns:
trueif this matcher matches no characters in the sequence, including when the sequence is empty
-
indexIn
public int indexIn(CharSequence sequence)
Returns the index of the first matching character in a character sequence, or-1if no matching character is present.The default implementation iterates over the sequence in forward order calling
matches(char)for each character.- Parameters:
sequence- the character sequence to examine from the beginning- Returns:
- an index, or
-1if no character matches
-
indexIn
public int indexIn(CharSequence sequence, int start)
Returns the index of the first matching character in a character sequence, starting from a given position, or-1if no character matches after that position.The default implementation iterates over the sequence in forward order, beginning at
start, callingmatches(char)for each character.- Parameters:
sequence- the character sequence to examinestart- the first index to examine; must be nonnegative and no greater thansequence.length()- Returns:
- the index of the first matching character, guaranteed to be no less than
start, or-1if no character matches - Throws:
IndexOutOfBoundsException- if start is negative or greater thansequence.length()
-
countIn
public int countIn(CharSequence sequence)
Returns the number of matching characters found in a character sequence.- Parameters:
sequence- sequence to count the number of matching characters- Returns:
- count of matching characters
-
-