public class Tokenizer
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
protected boolean |
_currentCharIsEscaped
True if the current char is escaped
|
protected int |
blankCharacters
The characters to skip to create the string which represents the
current token.
|
protected char[] |
buffer
The recording buffer.
|
protected int |
column
The current column.
|
protected boolean |
completeToken
like:
"this is string"
url("myurl")
For: url("myurl")
if completeToken == true: start = 0, end = 12
if completeToken == false: start = 5, end = 10
|
protected int |
current
The current char.
|
protected int |
currentEscapedCharacters
Number of escaped characters in the last token.
|
protected int |
end
The end offset of the last lexical unit.
|
protected static int |
ERROR |
protected java.lang.String |
errorMessage |
protected int |
escapedCharacters
Total number of escaped characters.
|
protected int |
line
The current line.
|
protected int |
position
The current position in the buffer.
|
protected char[] |
readBuffer
The reading buffer.
|
protected int |
readCount
The current read buffer count.
|
protected java.io.Reader |
reader
The reader.
|
protected int |
readPosition
The current position in the read buffer.
|
protected boolean |
replaceEscapedCharacters
Whether escaped characters should be replaced.
|
protected boolean |
returnErrorToken
Whether to return an error tokwn insted of throwing a ParserException.
|
protected int |
start
The start offset of the last lexical unit.
|
protected int |
type
The type of the current lexical unit.
|
Constructor and Description |
---|
Tokenizer(java.io.Reader r)
Creates a new Tokenizer object.
|
Tokenizer(java.lang.String s)
Creates a new Tokenizer object.
|
Modifier and Type | Method and Description |
---|---|
void |
clearBuffer()
Clears the buffer.
|
void |
completeToken(boolean complete)
Whether to return complete tokens.
|
int |
currentChar() |
protected int |
dotNumber()
Scans the decimal part of a number.
|
protected int |
endGap()
Returns the end gap of the current lexical unit.
|
protected void |
escape() |
protected void |
escape(boolean moveToNextChar)
Scans an escape sequence, if one.
|
char[] |
getBuffer()
Returns the buffer used to store the chars.
|
int |
getColumn()
Returns the current column.
|
protected int |
getCurrentChar() |
int |
getEnd()
Returns the end offset of the last lexical unit.
|
java.lang.String |
getErrorMessage()
In case the tokenizer is setup to return error tokens instead of throwing
exceptions, this method will return the message describing the last error token.
|
int |
getLine()
Returns the current line.
|
int |
getStart()
Returns the start offset of the last lexical unit.
|
java.lang.String |
getStringValue()
Returns the string representation of the current lexical unit.
|
java.lang.String |
getStringValue(int endOffset) |
int |
getType()
The current lexical unit type like defined in LexicalUnits.
|
protected boolean |
isCurrentCharEscaped() |
protected static boolean |
isEqualIgnoreCase(int i,
char c)
Compares the given int with the given character, ignoring case.
|
boolean |
isNextEOF()
Returns true of the next char is EOF.
|
void |
moveForwardOneChar() |
int |
next()
Returns the next token.
|
protected int |
nextChar()
Sets the value of the current char to the next character or -1 if the
end of stream has been reached.
|
protected void |
nextToken()
Returns the next token.
|
protected int |
number()
Scans a number.
|
protected int |
numberUnit(boolean integer)
Scans the unit of a number.
|
void |
replaceEscaped(boolean replace) |
protected void |
replaceEscapeSequance(int escStart,
int escEnd)
current is positioned after first character
|
void |
reset()
Puts Tokenizer in the same state as it was after creation.
|
boolean |
returnCompleteToken() |
protected boolean |
returnErrorToken() |
void |
returnErrorToken(boolean useToken) |
void |
scanAtRule()
Scans a @rule value.
|
int |
scanTillOneOf(char char1,
char char2)
Skips chars still one of char1 or char2 is found.
|
protected void |
setCurrentChar(int current) |
protected void |
setCurrentChar(int current,
boolean escaped) |
protected void |
setCurrentCharEscaped(boolean currentCharIsEscaped) |
void |
setPosition(int newPosition,
int newLine,
int newColumn)
Puts Tokenizer in the same state as it was after scanning up to new position.
|
void |
setStartStringToCurrent() |
protected int |
string1()
Scans a single quoted string.
|
protected int |
string2()
Scans a double quoted string.
|
protected java.io.Reader reader
protected char[] readBuffer
protected int readPosition
protected int readCount
protected char[] buffer
protected boolean replaceEscapedCharacters
protected boolean completeToken
protected int escapedCharacters
protected int currentEscapedCharacters
protected boolean returnErrorToken
protected static final int ERROR
protected int line
protected int column
protected int current
protected boolean _currentCharIsEscaped
protected int position
protected int type
protected int start
protected int end
protected int blankCharacters
protected java.lang.String errorMessage
public Tokenizer(java.io.Reader r) throws ParseException
r
- The reader to scan.ParseException
public Tokenizer(java.lang.String s) throws ParseException
s
- The reader to scan.ParseException
public void returnErrorToken(boolean useToken)
public void replaceEscaped(boolean replace)
public void completeToken(boolean complete)
public final boolean isNextEOF()
public void reset()
public void setPosition(int newPosition, int newLine, int newColumn)
java.lang.IllegalStateException
public char[] getBuffer()
public int getStart()
public int getEnd()
public void clearBuffer()
public java.lang.String getStringValue(int endOffset)
public java.lang.String getStringValue()
public int next() throws ParseException
ParseException
public int currentChar()
protected void replaceEscapeSequance(int escStart, int escEnd)
escStart
- offset of first character after '\'protected static boolean isEqualIgnoreCase(int i, char c)
protected int nextChar() throws java.io.IOException
java.io.IOException
public boolean returnCompleteToken()
protected boolean returnErrorToken()
public int getLine()
public int getColumn()
public int getType()
public java.lang.String getErrorMessage()
public void scanAtRule() throws ParseException
ParseException
public int scanTillOneOf(char char1, char char2) throws ParseException
ParseException
public void moveForwardOneChar() throws ParseException
ParseException
public void setStartStringToCurrent()
protected int endGap()
protected final void setCurrentChar(int current, boolean escaped)
protected final void setCurrentChar(int current)
protected final boolean isCurrentCharEscaped()
protected final void setCurrentCharEscaped(boolean currentCharIsEscaped)
protected int getCurrentChar()
protected void nextToken() throws ParseException
ParseException
protected int string1() throws java.io.IOException
java.io.IOException
protected int string2() throws java.io.IOException
java.io.IOException
protected int number() throws java.io.IOException
java.io.IOException
protected int dotNumber() throws java.io.IOException
java.io.IOException
protected int numberUnit(boolean integer) throws java.io.IOException
java.io.IOException
protected final void escape() throws java.io.IOException
java.io.IOException
protected void escape(boolean moveToNextChar) throws java.io.IOException
moveToNextChar
- If true, the method is allowed to move to the next char after
processing the escaped charjava.io.IOException