|
J avolution v5.3 (J2SE 1.5+) | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectjava.text.ParsePosition
javolution.text.Cursor
public class Cursor
This class represents a parsing cursor over characters. Cursor
allows for token iterations over any CharSequence.
Prints the following output:
CharSequence csq = "this is a test";
for (Cursor cursor = new Cursor(); cursor.skip(CharSet.WHITESPACES, csq);) {
System.out.println(cursor.nextToken(csq, CharSet.WHITESPACES));
}
this
is
a
test
Cursors are typically used with TextFormat instances.
public Font parse(CharSequence csq, Cursor cursor) {
CharSequence fontName = cursor.nextToken(csq, CharSet.WHITESPACE);
return Font.decode(fontName.toString());
}
| Constructor Summary | |
|---|---|
Cursor()
Default constructor. |
|
| Method Summary | |
|---|---|
boolean |
equals(java.lang.Object obj)
Indicates if this cursor is equals to the specified object. |
int |
getIndex()
Returns this cursor index. |
int |
hashCode()
Returns the hash code for this cursor. |
boolean |
hasNext(java.lang.CharSequence csq)
Indicates if this cursor points to a valid character in the specified character sequence. |
Cursor |
increment()
Increments the cursor index by one. |
Cursor |
increment(int i)
Increments the cursor index by the specified value. |
char |
next(java.lang.CharSequence csq)
Returns the next character at this cursor position. |
java.lang.CharSequence |
nextToken(java.lang.CharSequence csq,
char c)
Returns the subsequence from the specified cursor position not holding the specified character. |
java.lang.CharSequence |
nextToken(java.lang.CharSequence csq,
CharSet charSet)
Returns the subsequence from the specified cursor position not holding any of the characters specified. |
void |
reset()
Resets this cursor instance. |
void |
setIndex(int i)
Sets the cursor current index. |
boolean |
skip(char c,
java.lang.CharSequence csq)
Moves this cursor forward until it points to a character different from the specified character. |
boolean |
skip(CharSet charSet,
java.lang.CharSequence csq)
Moves this cursor forward until it points to a character different from any of the character in the specified set. |
java.lang.String |
toString()
Returns the string representation of this cursor. |
| Methods inherited from class java.text.ParsePosition |
|---|
getErrorIndex, setErrorIndex |
| Methods inherited from class java.lang.Object |
|---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public Cursor()
| Method Detail |
|---|
public final int getIndex()
getIndex in class java.text.ParsePositionpublic void setIndex(int i)
setIndex in class java.text.ParsePositioni - the index of the next character to parse.public final boolean hasNext(java.lang.CharSequence csq)
csq - the character sequence iterated by this cursor.
true if this cursor points to a valid character
position; false otherwise.public final char next(java.lang.CharSequence csq)
csq - the character sequence iterated by this cursor.
false otherwise.
java.lang.IndexOutOfBoundsException - if !hasNext(csq)
public final boolean skip(char c,
java.lang.CharSequence csq)
c - the character to skip.csq - the character sequence iterated by this cursor.
true if this cursor points to a character
different from the ones specified; false
otherwise (end of sequence reached).
public final boolean skip(CharSet charSet,
java.lang.CharSequence csq)
// Reads numbers separated by tabulations or spaces.
FastTable<Integer> numbers = new FastTable<Integer>();
while (cursor.skip(CharSet.SPACE_OR_TAB, csq)) {
numbers.add(TypeFormat.parseInt(csq, cursor));
}
charSet - the character to skip.csq - the character sequence iterated by this cursor.
true if this cursor points to a character
different from the ones specified; false
otherwise (e.g. end of sequence reached).
public final java.lang.CharSequence nextToken(java.lang.CharSequence csq,
char c)
CharSequence csq = "This is a test";
for (CharSequence token; (token=cursor.nextToken(csq, ' '))!= null;) {
System.out.println(token); // Prints one word at a time.
}
csq - the character sequence iterated by this cursor.c - the character being skipped.
null if none.
public final java.lang.CharSequence nextToken(java.lang.CharSequence csq,
CharSet charSet)
CharSequence csq = "This is a test";
for (CharSequence token; (token=cursor.nextToken(csq, CharSet.WHITESPACE))!= null;) {
System.out.println(token); // Prints one word at a time.
}
csq - the character sequence iterated by this cursor.charSet - the characters being skipped.
null if none.public final Cursor increment()
thispublic final Cursor increment(int i)
i - the increment value.
thispublic java.lang.String toString()
toString in class java.text.ParsePositionpublic boolean equals(java.lang.Object obj)
equals in class java.text.ParsePositiontrue if the specified object is a cursor
at the same index; false otherwise.public int hashCode()
hashCode in class java.text.ParsePositionpublic void reset()
reset in interface ReusableReusable
|
J avolution v5.3 (J2SE 1.5+) | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||