org.freecompany.util.text
Class Scanner
public
class
Scanner
extends Object
Locates individual characters and sequences of characters within a block of characters.
This class utilizes the CharSequence interface for scan targets, allowing a wide
array of container objects to be searched.
The scanner provides set of static methods to perform character sequence scanning relative
to either a character sequence or a state object as provided by the caller.
Method Summary |
protected static int | end(CharSequence target, CharSequence sequence) |
static boolean | endsWith(CharSequence target, CharSequence sequence)
Convenience method that scans in order to determine if the token is the last set of characters in
the target. |
static int | last(CharSequence target, CharSequence sequence)
Convenience method that reverse scans an entire target. |
static boolean | match(CharSequence target, CharSequence sequence, int start)
Convenience method that matches the portion of the sequence from the provided index to the end. |
static boolean | match(CharSequence target, CharSequence sequence, int start, int end)
Matches the provided sequence against the target at the indicated index. |
static int | scan(State state, CharSequence sequence)
Scans for the next occurance of the provided sequence starting at the index stored in the internal
counter. |
static int | scan(CharSequence target, CharSequence sequence)
Convenience method that scans between the start and the end of the target. |
static int | scan(CharSequence target, CharSequence sequence, int start)
Convenience method which scans between the provided index and the end of the target. |
static int | scan(CharSequence target, CharSequence sequence, int start, int end)
Scans the provided target sequence for the whole of the provided sequence occurring between the start and
end indexes. |
static boolean | skip(State state, CharSequence sequence)
Skips a sequence if it is present at the cursor. |
static int | skip(CharSequence target, CharSequence sequence)
Skips a sequence using the default index of zero, meaning this method only searches the beginning of a sequence
for a particular match.
|
static int | skip(CharSequence target, CharSequence sequence, int index)
Skips a sequence if and only if it is found at the given index.
|
static boolean | startsWith(CharSequence target, CharSequence sequence)
Convenience method that scans in order to determine if the token is the first set of characters in
the target. |
protected static final int end(CharSequence target, CharSequence sequence)
public static final boolean endsWith(CharSequence target, CharSequence sequence)
Convenience method that scans in order to determine if the token is the last set of characters in
the target.
public static final int last(CharSequence target, CharSequence sequence)
Convenience method that reverse scans an entire target. This is equivalent to
calling scan
with the start and end arguments reversed.
public static final boolean match(CharSequence target, CharSequence sequence, int start)
Convenience method that matches the portion of the sequence from the provided index to the end. This is
equivalent to calling the match
method with the length of the sequence added to the start
index as the fourth argument.
public static final boolean match(CharSequence target, CharSequence sequence, int start, int end)
Matches the provided sequence against the target at the indicated index. This method tests that the target
contains as many of this exact sequences characters as fit between the start and end indexes.
Returns: true if the target contains the sequence between the start and end positions, ignoring extra characters
or false otherwise.
public static final int scan(
State state, CharSequence sequence)
Scans for the next occurance of the provided sequence starting at the index stored in the internal
counter. The internal counter will be updated to the end of the matched sequence or the next index
after the last possible match of the sequence. This is so that the target can be reset with a longer
sequence and scanning will resume at the next possible index where the match can occur.
Returns: the index of the next match, or -1 if no match was found.
public static final int scan(CharSequence target, CharSequence sequence)
Convenience method that scans between the start and the end of the target. This is equivalent to
calling scan
with zero as the third argument and the length of the sequence subtracted
from the length of the target as the fourth argument.
public static final int scan(CharSequence target, CharSequence sequence, int start)
Convenience method which scans between the provided index and the end of the target. This is equivalent
to calling the scan
method with the length of the sequence subtracted from the length of the target
as the fourth argument.
public static final int scan(CharSequence target, CharSequence sequence, int start, int end)
Scans the provided target sequence for the whole of the provided sequence occurring between the start and
end indexes. Reverse scans if the start is greater than the end.
Returns: the index of the first character of the sequence in the target, or -1 if the sequence was not found.
public static final boolean skip(
State state, CharSequence sequence)
Skips a sequence if it is present at the cursor. This method will reset the cursor to the new position
if a match is found or leave it untouched if not.
public static final int skip(CharSequence target, CharSequence sequence)
Skips a sequence using the default index of zero, meaning this method only searches the beginning of a sequence
for a particular match.
public static final int skip(CharSequence target, CharSequence sequence, int index)
Skips a sequence if and only if it is found at the given index.
Returns: the new index after possibly skipping a sequence. If the sequence was found then it returns the index
after advancing past the match. If not, the current index is returned.
public static final boolean startsWith(CharSequence target, CharSequence sequence)
Convenience method that scans in order to determine if the token is the first set of characters in
the target.