public final class CharSet extends Object implements Immutable<CharSet>
A set of characters (typically used for parsing purpose where it is significantly faster than regular expressions for simple patterns). For example:
// Integration with Text. Text number; int exponentIndex = num.indexOfAny(CharSet.valueOf('e', 'E')); // Integration with TextFormat. public List<Integer> parse(CharSequence csq, Cursor cursor) { FastTable<Integer> numbers = FastTable.newInstance(); while (cursor.skip(CharSet.WHITESPACES, csq)) { numbers.add(TypeFormat.parseInt(csq, cursor)); } return numbers; }
Modifier and Type | Field and Description |
---|---|
static CharSet |
EMPTY
Represents an empty character set.
|
static CharSet |
ISO_CONTROLS
Represents ISO control characters according to Java
(see
Character.isISOControl(char) ). |
static CharSet |
SPACES
Represents spaces characters according to Java
(see
Character.isSpaceChar(char) ). |
static CharSet |
WHITESPACES
Represents white spaces characters according to Java
(see
Character.isWhitespace(char) ). |
Modifier and Type | Method and Description |
---|---|
boolean |
contains(char c)
Indicates if the specified character is contained by this character set.
|
int |
indexIn(char[] chars)
Equivalent to
indexIn(chars, 0) |
int |
indexIn(char[] chars,
int fromIndex)
Returns the first index in the specified character array of
one of the character of this set.
|
int |
indexIn(CharSequence csq)
Equivalent to
indexIn(csq, 0) |
int |
indexIn(CharSequence csq,
int fromIndex)
Returns the first index in the specified character sequence of
one of the character of this set.
|
int |
lastIndexIn(char[] chars)
Equivalent to
lastIndexIn(chars, chars.length-1) |
int |
lastIndexIn(char[] chars,
int fromIndex)
Returns the last index in the specified character array of
one of the character of this set.
|
int |
lastIndexIn(CharSequence csq)
Equivalent to
lastIndexIn(csq, csq.length()-1) |
int |
lastIndexIn(CharSequence csq,
int fromIndex)
Returns the last index in the specified character sequence of
one of the character of this set.
|
CharSet |
minus(CharSet that)
Returns the character set containing the characters from this
character minus the characters from the character set specified.
|
CharSet |
plus(CharSet that)
Returns the character set containing the characters from this
character set plus the characters from the character set specified.
|
static CharSet |
rangeOf(char first,
char last)
Returns the character set holding the characters in the specified
range.
|
String |
toString()
Returns the textual representation of this character set.
|
CharSet |
value()
Returns the constant value held by this object.
|
static CharSet |
valueOf(char... chars)
Returns the character set holding the specified characters.
|
public static final CharSet EMPTY
public static final CharSet WHITESPACES
Character.isWhitespace(char)
).public static final CharSet SPACES
Character.isSpaceChar(char)
).public static final CharSet ISO_CONTROLS
Character.isISOControl(char)
).public static CharSet valueOf(char... chars)
chars
- the characters contained by this character set.public static CharSet rangeOf(char first, char last)
first
- the first character.last
- the last character.IllegalArgumentException
- if first > last
public boolean contains(char c)
c
- the character to test.true
if this character set contains the specified
character; false
otherwise.public int indexIn(CharSequence csq)
indexIn(csq, 0)
csq
- the character sequence to be searched.-1
if none found.public int indexIn(CharSequence csq, int fromIndex)
csq
- the character sequence to be searched.fromIndex
- the index to search from.-1
if none found.public int indexIn(char[] chars)
indexIn(chars, 0)
-1
if none found.public int indexIn(char[] chars, int fromIndex)
chars
- the character array to be searched.fromIndex
- the index to search from.-1
if none found.public int lastIndexIn(CharSequence csq)
lastIndexIn(csq, csq.length()-1)
csq
- the character sequence to be searched.-1
if none found.public int lastIndexIn(CharSequence csq, int fromIndex)
csq
- the character sequence to be searched.fromIndex
- the index to search from (backward).-1
if none found.public int lastIndexIn(char[] chars)
lastIndexIn(chars, chars.length-1)
-1
if none found.public int lastIndexIn(char[] chars, int fromIndex)
chars
- the character array to be searched.fromIndex
- the index to search from (backward).-1
if none found.public CharSet plus(CharSet that)
that
- the set containing the characters to be added.this + that
public CharSet minus(CharSet that)
that
- the set containing the character to be removed.this - that
public String toString()
Copyright © 2005-2013 Javolution. All Rights Reserved.