public class ReaderTokenizer
extends java.lang.Object
The tokenizer reads characters from a Reader, removes comments and
whitespace, and parses the remainder into tokens. One token is parsed for
each call to nextToken
. The following tokens may be
generated:
parseNumbers
.
_
),
and any character whose unicode value exceeds 0xA0. Other characters can be
designated as word characters using wordChar
or its sibling
methods.
'
and "
are enabled as quote
characters. Other characters can be designated as quote characters using
quoteChar
. Strings include the usual C-style escape
sequences beginning with backslash (\
). Setting backslash to
a quote character is likely to produce strange result.
ordinaryChar
or its sibling methods. The
method resetSyntax
sets all characters to be ordinary.
eolIsSignificant
.
/**/
) comments, enabled or disabled using
slashStarComments
//
) comments, enabled or disabled using
slashSlashComments
commentChar
.
#
is designated as a comment character and C/C++
comments are disabled.
By default, whitespace consists of any character with an ascii value from
0x00
to 0x20
. This includes new lines,
carriage returns, and spaces. Other characters can be designated as
whitespace using whitespaceChar
and its sibling
routines.
We first give a simple example that reads in pairs of words and numbers, such as following:
foo 1.67 dayton 678 thadius 1e-4This can be parsed with the following code:
HashMap<String,Double> wordNumberPairs = new HashMap<String,Double>(); ReaderTokenizer rtok = new ReaderTokenizer (new FileReader ("foo.txt")); while (rtok.nextToken() != ReaderTokenizer.TT_EOF) { if (rtok.ttype != ReaderTokenizer.TT_WORD) { throw new IOException ("word expected, line " + rtok.lineno()); } String word = rtok.sval; if (rtok.nextToken() != ReaderTokenizer.TT_NUMBER) { throw new IOException ("number expected, line " + rtok.lineno()); } Double number = Double.valueOf (rtok.nval); wordNumberPairs.put (word, number); }The application uses
nextToken
to continuously read tokens
until the end of the file. Once a token is read, its type is inspected using
the ttype
field. If the type is inappropriate, then an
exception is thrown, along with the tokenizer's current line number which is
obtained using lineno
. The numeric value for a number token
is stored in the field nval
, while the string value for a word
token is stored in the field sval
.
We now give a more complex example that expects input to consist of either
vectors of numbers, or file names, as indicated by the keywords
vector
and file
. Keywords should be followed
by an equal sign (=
), vectors can be any length but should
be surrounded by square brackets ([ ]
), and file names
should be enclosed in double quotes ("
), as in the following
sample:
vector=[ 0.4 0.4 6.7 ] file="bar.txt" vector = [ 1.3 0.4 6.7 1.2 ]This can be parsed with the following code:
ReaderTokenizer rtok = new ReaderTokenizer (new InputStreamReader (System.in)); ArrayList<Double> vector = new ArrayList<Double>(); String fileName = null; while (rtok.nextToken() != ReaderTokenizer.TT_EOF) { if (rtok.ttype != ReaderTokenizer.TT_WORD) { throw new IOException ("keyword expected, line " + rtok.lineno()); } String keyword = rtok.sval; if (keyword.equals ("vector")) { rtok.scanToken ('='); rtok.scanToken ('['); vector.clear(); while (rtok.nextToken() == ReaderTokenizer.TT_NUMBER) { vector.add (rtok.nval); } if (rtok.ttype != ']') { throw new IOException ("']' expected, line " + rtok.lineno()); } // do something with vector ... } else if (keyword.equals ("file")) { rtok.scanToken ('='); rtok.nextToken(); if (!rtok.tokenIsQuotedString ('"')) { throw new IOException ("quoted string expected, line " + rtok.lineno()); } fileName = rtok.sval; // do something with file ... } else { throw new IOException ("unrecognized keyword, line " + rtok.lineno()); } }This code is similar to the first example, except that it also uses the methods
scanToken
and tokenIsQuotedString
. The first is a convenience routine that reads the next
token and verifies that it's a specific type of ordinary character token (and
throws a diagnostic exception if this is not the case). This facilitates
compact code in cases where we know exactly what sort of input is expected.
Similar methods exist for other token types, such as
scanNumber
, scanWord
, or
scanQuotedString
. The second method,
tokenIsQuotedString
, verifies that the most
recently read token is in fact a string delimited by a specific quote
character. Similar methods exist to verify other token types:
tokenIsNumber
, tokenIsWord
, or
tokenIsBoolean
.
pushBack
. Push back is implemented very
efficiently, and so applications should not be shy about using it.
Here is an example consisting of a routine that reads in a set of numbers and stops when a non-numeric token is read:
public Double[] readNumbers (ReaderTokenizer rtok) throws IOException { ArrayList<Double> numbers = new ArrayList<Double>(); while (rtok.nextToken() == ReaderTokenizer.TT_NUMBER) { numbers.add (rtok.nval); } rtok.pushBack(); return numbers.toArray (new Double[0]); }The non-numeric token is returned to the input stream so that it is available to whatever parsing code is invoked next.
e
or E
are correctly handled;
lval
as well as
nval
; this permits integer values to be stored exactly with no
loss of precision;
0x
or 0X
.
One can use tokenIsInteger
to query whether or not a
numeric token corresponds to an integer value. Similarly, the convenience
routines scanInteger
, scanLong
, and
scanShort
can be used to require that an integer value is
scanned and converted to either int
, long
, or
short
. Another convenience routine,
scanNumbers
, can be used to read a sequence of numbers
and place them in an array.
ReaderTokenizer allows of its state variables to be queried, so a that parsing routine can set and restore state transparently:
void specialParsingRoutine (ReaderTokenizer rtok) { boolean eolTokenSave = rtok.getEolIsSignificant(); // save rtok.eolIsSignificant(true); ... do parsing that requires EOL tokens ... rtok.eolIsSignificant(eolTokenSave); // restore }
This includes the ability to save and restore the type settings for
individual characters. In the following example, $
,
@
, and &
are set to word characters, and then
restored to whatever their previous settings were:
void anotherSpecialParsingRoutine (ReaderTokenizer rtok) { int[] charSaves = rtok.getCharSettings ("$@&"); rtok.wordChars ("$@&"); // do parsing that requires $, @, and & to be word characters rtok.setCharSettings ("$@&", typeSaves); // restore settings }
Modifier and Type | Field and Description |
---|---|
long |
lval
If the current token is an integer as well as a number, then this field
contains the long value of that integer.
|
double |
nval
If the current token is a number, then this field contains the value of
that number.
|
java.lang.String |
sval
If the current token is a word or string, then this field contains the
value of that word or string.
|
static int |
TT_EOF
A constant indicating the end of the input.
|
static int |
TT_EOL
A constant indicating the end of a line.
|
static int |
TT_NOTHING
A constant indicating that the current token has no value
|
static int |
TT_NUMBER
A constant indicating that the current token is a number.
|
static int |
TT_WORD
A constant indicating that the current token is a word.
|
int |
ttype
Contains the type of the token read after a call to
nextToken . |
Constructor and Description |
---|
ReaderTokenizer(java.io.Reader reader)
Creates a new ReaderTokenizer from the specified Reader.
|
Modifier and Type | Method and Description |
---|---|
void |
clearNumericExtensionChars()
Clears all numeric extension characters.
|
void |
close()
Close the underlying reader for this tokenizer.
|
void |
commentChar(int ch)
Sets the specified character to be a comment character.
|
void |
eolIsSignificant(boolean enable)
Specifies whether or not end-of-line should be treated as a token.
|
int |
getCharSetting(int ch)
Gets the setting associated with a character.
|
int[] |
getCharSettings(int low,
int high)
Gets the settings associated with a set of characters specified by the
range
low <= ch <= high . |
int[] |
getCharSettings(java.lang.String str)
Gets the settings associated with a set of characters specified by a
string and returns them in an array.
|
boolean |
getEolIsSignificant()
Returns true if end-of-line is treated as a token by this tokenizer.
|
boolean |
getLowerCaseMode()
Returns true if lower-case mode is enabled for this tokenizer.
|
java.lang.String |
getNumericExtensionChars()
Returns a String specifying all characters which are enabled as numeric
extensions.
|
boolean |
getParseNumbers()
Returns true if number parsing is enabled for this tokenizer.
|
static java.lang.String |
getQuotedString(java.lang.String str,
char quoteChar)
Creates a quoted string with the specified quote character that can
later be parsed by this tokenizer.
|
java.io.Reader |
getReader()
Returns the Reader which supplies the input for this tokenizer.
|
java.lang.String |
getResourceName()
Returns the name of the resource (e.g., File or URL) associated
with this ReaderTokenizer.
|
boolean |
getSlashSlashComments()
Returns true if C++-style slash-slash comments are enabled.
|
boolean |
getSlashStarComments()
Returns true if C-style slash-star comments are enabled.
|
boolean |
isCommentChar(int ch)
Returns true if the specified character is a comment character.
|
boolean |
isEOF()
Returns true if the current token marks the end of the file
|
boolean |
isNumericExtensionChar(int ch)
Returns true if the specified character is a numeric extension character.
|
boolean |
isOrdinaryChar(int ch)
Returns true if the specified character is an ordinary character.
|
boolean |
isQuoteChar(int ch)
Returns true if the specified character is a quote character.
|
boolean |
isWhitespaceChar(int ch)
Returns true if the specified character is an whitespace character.
|
boolean |
isWordChar(int ch)
Returns true if the specified character is an word character.
|
java.lang.String |
lastCommentLine()
Returns the last comment line (excluding the trailing newline) that was
read by this tokenizer, or null if no comments have been read yet.
|
int |
lineno()
Returns the current line number.
|
void |
lowerCaseMode(boolean enable)
Enables or disables lower-case mode.
|
int |
nextToken()
Parses the next token from the input and returns its type.
|
void |
numericExtensionChar(int ch)
Sets the specified character to be a numeric extension character.
|
void |
numericExtensionChars(int low,
int high)
Sets all characters in the range
low <= ch <= high to be
numeric extension characters. |
void |
numericExtensionChars(java.lang.String chars)
Sets some specified characters to be numeric extension characters.
|
void |
ordinaryChar(int ch)
Sets the specified character to be "ordinary", so that it indicates a
token whose type is given by the character itself.
|
void |
ordinaryChars(int low,
int high)
Sets all characters in the range
low <= ch <= high to be
"ordinary". |
void |
ordinaryChars(java.lang.String str)
Sets all characters specified by a string to be "ordinary".
|
void |
parseNumbers(boolean enable)
Enables parsing of numbers by this tokenizer.
|
void |
pushBack()
Pushes the current token back into the input, so that it may be read again
using
nextToken . |
void |
quoteChar(int ch)
Sets the specified character to be a "quote" character, so that it
delimits a quoted string.
|
java.lang.String |
readLine()
Reads the current input to the end of the current line, and returns the
read characters as a string (excluding the end-of-line characters).
|
void |
resetSyntax()
Sets all characters to be ordinary characters, so that they are treated as
individual tokens, as disabled number parsing.
|
boolean |
scanBoolean()
Reads the next token and checks that it represents a boolean.
|
void |
scanCharacter(int ch)
Reads the next token and verifies that it matches a specified character.
|
<T extends java.lang.Enum<T>> |
scanEnum(java.lang.Class<T> enumType)
Reads the next token, check that it represents a specified
enumerated type, and return the corrsponding type.
|
int |
scanInteger()
Reads the next token and checks that it is an integer.
|
int |
scanIntegers(int[] vals,
int max)
Reads a series of numeric tokens and returns their values.
|
long |
scanLong()
Reads the next token and checks that it is an integer.
|
double |
scanNumber()
Reads the next token and checks that it is a number.
|
int |
scanNumbers(double[] vals,
int max)
Reads a series of numeric tokens and returns their values.
|
java.lang.String |
scanQuotedString(char quoteChar)
Reads the next token and checks that it is a quoted string delimited by
the specified quote character.
|
short |
scanShort()
Reads the next token and checks that it is an integer.
|
void |
scanToken(int type)
Reads the next token and verifies that it is of the specified type.
|
java.lang.String |
scanWord()
Reads the next token and checks that it is a word.
|
java.lang.String |
scanWord(java.lang.String word)
Reads the next token and checks that it is a specific word.
|
java.lang.String |
scanWordOrQuotedString(char quoteChar)
Reads the next token and checks that it is either a word or a quoted
string delimited by the specified quote character.
|
void |
setCharSetting(int ch,
int setting)
Assigns the settings for a character.
|
void |
setCharSettings(int low,
int high,
int[] settings)
Assigns settings for a set of characters specified by the range
low <= ch <= high . |
void |
setCharSettings(java.lang.String str,
int[] settings)
Assigns settings for a set of characters specified by a string.
|
void |
setLineno(int num)
Sets the current line number.
|
void |
setReader(java.io.Reader reader)
Sets the Reader which supplies the input for this tokenizer.
|
void |
setResourceName(java.lang.String name)
Sets the name of the resource (e.g., File or URL) associated
with this ReaderTokenizer.
|
void |
slashSlashComments(boolean enable)
Enables the handling of C++-style slash-slash comments, commenting out all
characters between
// and the next line. |
void |
slashStarComments(boolean enable)
Enables the handling of C-style slash-star comments, commenting out all
characters, inclusing new lines, between
/* and
*/ . |
boolean |
tokenIsBoolean()
Returns true if the current token represents a boolean.
|
boolean |
tokenIsHexInteger() |
boolean |
tokenIsInteger()
Returns true if the current token is an integer.
|
boolean |
tokenIsNumber()
Returns true if the current token is a number.
|
boolean |
tokenIsQuotedString(char quoteChar)
Returns true if the current token is a quoted string delimited by the
specified quote character.
|
boolean |
tokenIsWord()
Returns true if the current token is a word.
|
boolean |
tokenIsWord(java.lang.String value)
Returns true if the current token is a word with a specified value.
|
boolean |
tokenIsWordOrQuotedString(char quoteChar)
Returns true if the current token is either a word or a quoted string
delimited by the specified quote character.
|
java.lang.String |
tokenName()
Returns a string identifying the current token.
|
java.lang.String |
toString()
Returns a string describing the type and value of the current token, as
well as the current line number.
|
void |
whitespaceChar(int ch)
Sets the specified character to be a "white space" character, so that it
delimits tokens and does not otherwise take part in their formation.
|
void |
whitespaceChars(int low,
int high)
Sets all characters in the range
low <= ch <= high to
"whitespace" characters. |
void |
wordChar(int ch)
Sets the specified character to be a "word" character, so that it can form
part of a work token.
|
void |
wordChars(int low,
int high)
Sets all characters in the range
low <= ch <= high to be
"word" characters. |
void |
wordChars(java.lang.String chars)
Sets some specified characters to be "word" characters, so that they can
form part of a work token.
|
public static final int TT_EOF
public static final int TT_EOL
public static final int TT_NUMBER
public static final int TT_WORD
public static final int TT_NOTHING
public int ttype
nextToken
.public double nval
public long lval
public java.lang.String sval
public ReaderTokenizer(java.io.Reader reader)
reader
- Reader that provides the input streampublic int lineno()
public void setLineno(int num)
num
- new line numberpublic void eolIsSignificant(boolean enable)
TT_EOL
.enable
- if true, then end-of-line is treated as a tokengetEolIsSignificant()
public boolean getEolIsSignificant()
eolIsSignificant(boolean)
public void lowerCaseMode(boolean enable)
sval
field are converted to
lower case.enable
- if true, enables lower case modepublic boolean getLowerCaseMode()
public void pushBack()
nextToken
. One token of push-back is supported.public int getCharSetting(int ch)
ordinary
,
word
, comment
,
quote
, or whitespace
), and
whether or not the character is a
numeric extension
. However, the information
is opaque to the user, and is intended mainly to allow the saving and
restoring of character settings within a parsing procedure.ch
- character for which setting is requiredsetCharSetting(int, int)
,
getCharSettings(String)
,
getCharSettings(int,int)
public int[] getCharSettings(java.lang.String str)
getCharSetting
.str
- characters for which setting are requiredsetCharSettings(String,int[])
,
getCharSetting(int)
,
getCharSettings(int,int)
public int[] getCharSettings(int low, int high)
low <= ch <= high
. For more
information on character settings, see getCharSetting
.low
- lowest character whose setting is desiredhigh
- highest character whose setting is desiredsetCharSettings(int,int,int[])
,
getCharSetting(int)
,
getCharSettings(String)
public void setCharSetting(int ch, int setting)
getCharSetting
.ch
- character to be setsetting
- setting for the charactergetCharSetting(int)
,
setCharSettings(String,int[])
,
setCharSettings(int,int,int[])
public void setCharSettings(java.lang.String str, int[] settings)
getCharSetting
.str
- characters to be setsettings
- setting for each charactergetCharSettings(String)
,
setCharSetting(int,int)
,
setCharSettings(int,int,int[])
public void setCharSettings(int low, int high, int[] settings)
low <= ch <= high
. The settings are provided in an
accompanying array. For more information on character settings, see
getCharSetting
.low
- lowest character to be sethigh
- highest character to be setsettings
- setting for each charactergetCharSettings(String)
,
setCharSetting(int,int)
,
setCharSettings(String,int[])
public void ordinaryChar(int ch)
Setting the end-of-line character to be ordinary may interfere with ability of this tokenizer to count lines. Setting numeric characters to be ordinary may interfere with the ability of this tokenizer to parse numbers, if numeric parsing is enabled.
ch
- character to be designated as ordinary.isOrdinaryChar(int)
,
ordinaryChars(int, int)
public void ordinaryChars(int low, int high)
low <= ch <= high
to be
"ordinary". See ordinaryChar
for more
information on ordinary characters.low
- lowest character to be designated as ordinary.high
- highest character to be designated as ordinary.isOrdinaryChar(int)
,
ordinaryChar(int)
public void ordinaryChars(java.lang.String str)
ordinaryChar
for more information on ordinary
characters.str
- string giving the ordinary charactersisOrdinaryChar(int)
,
ordinaryChar(int)
public final boolean isOrdinaryChar(int ch)
ch
- character to be queriedch
ch is an ordinary characterordinaryChar(int)
,
ordinaryChars(int, int)
public void wordChar(int ch)
Setting the end-of-line character to be word may interfere with ability of this tokenizer to count lines. Digits and other characters found in numbers may be specified as word characters, but if numeric parsing is enabled, the formation of numbers will take precedence over the formation of words.
ch
- character to be designated as a word characterisWordChar(int)
,
wordChars(int,int)
,
wordChars(String)
public void wordChars(java.lang.String chars)
wordChar
for more
details.chars
- characters to be designated as word charactersisWordChar(int)
,
wordChar(int)
public void wordChars(int low, int high)
low <= ch <= high
to be
"word" characters. See wordChar
for more information on
word characters.low
- lowest character to be designated as a word characterhigh
- highest character to be designated as a word characterisWordChar(int)
,
wordChar(int)
public final boolean isWordChar(int ch)
ch
- character to be queriedch
ch is an word characterwordChar(int)
,
wordChars(int,int)
,
wordChars(String)
public void numericExtensionChar(int ch)
100004L
,
10msec
, or 2.0f
. Any detected numeric
extension is placed in the sval
field.
Setting the end-of-line character to be word may interfere with ability of this tokenizer to count lines. Digits and other characters found in numbers may be specified as word characters, but if numeric parsing is enabled, the formation of numbers will take precedence over the formation of words.
ch
- character to be designated for numeric extensionisNumericExtensionChar(int)
,
numericExtensionChars(int,int)
,
numericExtensionChars(String)
public void numericExtensionChars(java.lang.String chars)
numericExtensionChar
.chars
- characters to be designated as numeric extensionsisNumericExtensionChar(int)
,
numericExtensionChar(int)
,
numericExtensionChars(int,int)
public void numericExtensionChars(int low, int high)
low <= ch <= high
to be
numeric extension characters. Other settings for the characters are
unaffected. For more information on numeric extensions, see numericExtensionChar
.low
- lowest character to be designated as a numeric extension characterhigh
- highest character to be designated as a numeric extension characterisNumericExtensionChar(int)
,
numericExtensionChar(int)
,
numericExtensionChars(String)
public final boolean isNumericExtensionChar(int ch)
numericExtensionChar
.ch
- character to be queriedch
ch is a numeric extension characternumericExtensionChar(int)
,
numericExtensionChars(String)
,
numericExtensionChars(int,int)
public java.lang.String getNumericExtensionChars()
numericExtensionChar
.isNumericExtensionChar(int)
,
numericExtensionChar(int)
,
numericExtensionChars(String)
public void clearNumericExtensionChars()
numericExtensionChar
.public void whitespaceChar(int ch)
ch
- character to be designated as whitespaceisWhitespaceChar(int)
,
whitespaceChars(int, int)
public void whitespaceChars(int low, int high)
low <= ch <= high
to
"whitespace" characters. See whitespaceChar
for
more information on whitespace characters.low
- lowest character to be designated as whitespacehigh
- highest character to be designated as whitespaceisWhitespaceChar(int)
,
whitespaceChar(int)
public final boolean isWhitespaceChar(int ch)
ch
- character to be queriedch
ch is an whitespace characterwhitespaceChar(int)
,
whitespaceChars(int, int)
public void quoteChar(int ch)
ch
- character to be designated as a quote characterisQuoteChar(int)
public final boolean isQuoteChar(int ch)
ch
- character to be queriedch
ch is a quote characterquoteChar(int)
public void resetSyntax()
parseNumbers(boolean)
public void parseNumbers(boolean enable)
0x
or
0X
-
sign which negates
their value. When a number token is parsed, its numeric value is placed
into the nval
field and ttype
is set to
TT_NUMBER
. If the number is also an integer, then it's
value is placed into the field lval
.enable
- if true, enables parsing of numbersgetParseNumbers()
public boolean getParseNumbers()
parseNumbers(boolean)
public void slashStarComments(boolean enable)
/*
and
*/
.enable
- if true, enables C-style commentsgetSlashStarComments()
public boolean getSlashStarComments()
slashStarComments(boolean)
public void slashSlashComments(boolean enable)
//
and the next line.enable
- if true, enables slash-slash commentsgetSlashSlashComments()
public boolean getSlashSlashComments()
slashSlashComments(boolean)
public void commentChar(int ch)
ch
- character to be designated as a comment character.isCommentChar(int)
public final boolean isCommentChar(int ch)
ch
- character to be queriedch
ch is a comment charactercommentChar(int)
public java.lang.String toString()
toString
in class java.lang.Object
public java.lang.String readLine() throws java.io.IOException
ttype
is set to either TT_EOL
or TT_EOF
, as appropriate. Use this method only if you
really know what you're doing!java.io.IOException
public int nextToken() throws java.io.IOException
ttype
. If the token is
numeric, then the associated numeric value is placed in the field
nval
. If the token is a word or quoted string, then the
associated string value is placed in the field sval
.java.io.IOException
public void setReader(java.io.Reader reader)
reader
- new Readerpublic java.io.Reader getReader()
public java.lang.String getResourceName()
setResourceName(java.lang.String)
. If a resource name has not been set, this
method returns null
.public void setResourceName(java.lang.String name)
name
- name opublic void close()
public java.lang.String tokenName()
public void scanCharacter(int ch) throws java.io.IOException
ttype
must either equal the character
directly, or must equal TT_WORD
with sval
containing a one-character string that matches the character.ch
- character to matchjava.io.IOException
- if the character is not matchedpublic void scanToken(int type) throws java.io.IOException
type
- type of the expected tokenjava.io.IOException
- if the token is not of the expected typepublic double scanNumber() throws java.io.IOException
java.io.IOException
- if the token is not a numberpublic int scanInteger() throws java.io.IOException
java.io.IOException
- if the token is not an integerpublic long scanLong() throws java.io.IOException
java.io.IOException
- if the token is not an integerpublic short scanShort() throws java.io.IOException
java.io.IOException
- if the token is not an integerpublic boolean scanBoolean() throws java.io.IOException
true
or false
. If the token
represents a boolean, its value is returned. Otherwise, an exception is
thrown.java.io.IOException
- if the token does not represent a booleantokenIsBoolean()
public <T extends java.lang.Enum<T>> T scanEnum(java.lang.Class<T> enumType) throws java.io.IOException
enumType
- type of the expected enumjava.io.IOException
- if the token does not represent the specified enumerated typepublic java.lang.String scanQuotedString(char quoteChar) throws java.io.IOException
quoteChar
- quote character that delimits the stringjava.io.IOException
- if the token does not represent a quoted string delimited by the specified
charactertokenIsQuotedString(char)
public java.lang.String scanWordOrQuotedString(char quoteChar) throws java.io.IOException
quoteChar
- quote character that delimits stringsjava.io.IOException
- if the token does not represent a word or quoted string delimited by the
specified charactertokenIsQuotedString(char)
public java.lang.String scanWord() throws java.io.IOException
java.io.IOException
- if the token does not represent a wordpublic java.lang.String scanWord(java.lang.String word) throws java.io.IOException
word
- expected value of the word to be scannedjava.io.IOException
- if the token is not a word with the specified valuepublic int scanNumbers(double[] vals, int max) throws java.io.IOException
max
numbers have been read. Note that this token will also be numeric if the
input contains more than max consecutive numeric tokens.vals
- used to return numeric valuesmax
- maximum number of numeric tokens to readjava.io.IOException
public int scanIntegers(int[] vals, int max) throws java.io.IOException
max
numbers have been read. Note that this token will also be numeric if the
input contains more than max consecutive integer tokens.vals
- used to return integer valuesmax
- maximum number of integer tokens to readjava.io.IOException
public boolean tokenIsNumber()
ttype
equals
TT_NUMBER
.public boolean isEOF()
public boolean tokenIsInteger()
scanInteger()
public boolean tokenIsHexInteger()
public boolean tokenIsWord()
ttype
equals TT_WORD
.public boolean tokenIsWord(java.lang.String value)
ttype
equals
TT_WORD
and that sval
equals the
specified word.value
- required word valuepublic boolean tokenIsBoolean()
true
or false
.scanBoolean()
public boolean tokenIsQuotedString(char quoteChar)
quoteChar
- quote character used to delimit the stringpublic boolean tokenIsWordOrQuotedString(char quoteChar)
quoteChar
- quote character used to delimit the stringpublic java.lang.String lastCommentLine()
public static java.lang.String getQuotedString(java.lang.String str, char quoteChar)
\\ \t \b \n \r \fplus the quote charater. Any other character
<=
0x1f
or >=
0x7f is written by a backslashed octal number.str
- string to add escape sequences toquoteChar
- quote character for the string