AbstractParserpublic abstract class AbstractParser extends Object AbstractParser is the base class for parsers found
in this package.
All parsers work on a String and the AbstractParser
keeps a reference to that string along with the current position
(@see #currentPos) and current character (@see current).
The key methods for this class are read which reads the next
character in the parsed string, setString which sets the string
to be parsed, and the utility methods skipCommaSpaces ,
skipSpaces and skipSpacesCommaSpaces which can
be used by descendants to skip common separators.
For an implementation example, see {@link TransformListParser}. |
Fields Summary |
---|
protected int | currentPosThe current position in the string | protected String | sThe String being parsed | protected int | currentThe current character being parsed
This is accessible by sub-classes |
Methods Summary |
---|
protected final boolean | currentStartsWith(java.lang.String str)Tests if the current substring (i.e. the substring beginning at the
current position) starts with the specified prefix. If the current
substring starts with the specified prefix, the current character will
be updated to point to the character immediately following the last
character in the prefix; otherwise, the currentPos will
not be affected. For example, if the string being parsed is
"timingAttr", and the current character is 'A':
currentStartsWith("Att") returns true, current == 'r'
currentStartsWith("Attr") returns true, current == -1
currentStartsWith("Attx") returns false, current == 'A'
if (currentPos <= 0) {
return false;
}
if (s.startsWith(str, currentPos - 1)) {
currentPos += str.length() - 1;
current = read();
return true;
}
return false;
| protected final int | read()
if (currentPos < s.length()) {
return s.charAt(currentPos++);
}
return -1;
| protected final void | setString(java.lang.String str)Sets this parser's String. This also resets the
current position to 0
if (str == null) {
throw new IllegalArgumentException();
}
this.s = str;
this.currentPos = 0;
this.current = -1;
| protected final void | skipCommaSpaces()Skips the whitespaces and an optional comma.
skipSepSpaces(',");
| protected final void | skipSepSpaces(char sep)Skips the whitespaces and an optional comma.
wsp1: for (;;) {
switch (current) {
default:
break wsp1;
case 0x20:
case 0x9:
case 0xD:
case 0xA:
}
current = read();
}
if (current == sep) {
wsp2: for (;;) {
switch (current = read()) {
default:
break wsp2;
case 0x20:
case 0x9:
case 0xD:
case 0xA:
}
}
}
| protected final void | skipSpaces()Skips the whitespaces in the current reader.
for (;;) {
switch (current) {
default:
return;
case 0x20:
case 0x09:
case 0x0D:
case 0x0A:
}
current = read();
}
| protected final void | skipSpacesCommaSpaces()Skips wsp*,wsp* and throws an IllegalArgumentException
if no comma is found.
skipSpaces();
if (current != ',") {
throw new IllegalArgumentException();
}
current = read();
skipSpaces();
|
|