public class StrTok
extends java.lang.Object
The major difference from StreamTokenizer is that all tokens are returned as strings. EOF returns a null, EOL returns an empty string. A delimiter is returned as a one-character string. Words and numbers are returned as strings. Quoted strings are also returned as strings including their quote characters (so they can easily be differentiated from words and numbers).
Other differences are:
Modifier and Type | Class and Description |
---|---|
static class |
StrTok.ErrorHandler
Default class for error handling.
|
Modifier and Type | Field and Description |
---|---|
java.io.StreamTokenizer |
stok
The StreamTokenizer to which all work is delegated.
|
Constructor and Description |
---|
StrTok(java.lang.String s)
Creates a tokenizer for the specified string.
|
StrTok(java.lang.String s,
StrTok.ErrorHandler e)
Creates a tokenizer for the specified string with the specified error handler.
|
Modifier and Type | Method and Description |
---|---|
void |
commentChar(int ch)
Specifies the single line comment character.
|
boolean |
isQString()
Returns true if the current token is a quoted string.
|
boolean |
isWord()
Returns true if the current token is a word (identifier).
|
java.lang.String |
need_word()
Reads the next token and checks to make sure that it is a word (id).
|
void |
need(java.lang.String tok)
Reads the next token and checks that it matches tok.
|
java.lang.String |
nextToken()
Returns the next token as a string.
|
void |
pushBack()
Causes the next call to nextToken() to return the current token.
|
void |
quoteChar(int ch)
Specifies that matching pairs of this character delimit string constants.
|
void |
set_error_handler(StrTok.ErrorHandler errorHandler)
Sets the error handler.
|
java.lang.String |
token()
Return the current token.
|
int |
ttype()
Return the type of the current token.
|
public java.io.StreamTokenizer stok
public StrTok(java.lang.String s)
s
- string to tokenizepublic StrTok(java.lang.String s, StrTok.ErrorHandler e)
s
- string to tokenizee
- error handlerpublic java.lang.String nextToken()
public void pushBack()
public java.lang.String token()
nextToken()
public void commentChar(int ch)
ch
- the comment characterStreamTokenizer.commentChar(int)
public void quoteChar(int ch)
ch
- the quoting characterStreamTokenizer.quoteChar(int)
public int ttype()
StreamTokenizer.ttype
public boolean isWord()
public boolean isQString()
public void set_error_handler(StrTok.ErrorHandler errorHandler)
errorHandler
- the new error handlerStrTok.ErrorHandler
public void need(java.lang.String tok)
set_error_handler()
). If it does match, just returns.tok
- string to check next token againstpublic java.lang.String need_word()