Package org.htmlunit.cssparser.parser
Class CssCharStream
java.lang.Object
org.htmlunit.cssparser.parser.CssCharStream
- All Implemented Interfaces:
CharStream
An implementation of interface CharStream.
There is no processing of escaping in this class because the escaping is
part of the parser. CSS has some strange rules about that, so processing
unicode escapes in this class is too early.
-
Field Summary
Modifier and TypeFieldDescriptionint
Position in buffer.static final boolean
Whether parser is static. -
Constructor Summary
ConstructorDescriptionCssCharStream
(Reader dstream, int startline, int startcolumn) Constructor.CssCharStream
(Reader dstream, int startline, int startcolumn, int buffersize) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoid
adjustBeginLineColumn
(int newLine, int newCol) Method to adjust line and column numbers for the start of a token.final void
backup
(int amount) Backs up the input stream by amount steps.final char
Start.void
done()
The lexer calls this function to indicate that it is done with the stream and hence implementations can free any resources held by this class.final int
Get token beginning column number.final int
Get token beginning line number.final int
Get token end column number.final int
Get token end line number.final String
getImage()
Get token literal value.final char[]
getSuffix
(int len) Get the suffix.int
boolean
final char
readChar()
Get the next character from the selected input.void
setTabSize
(int i) Set the tab size to use.void
setTrackLineColumn
(boolean tlc) Enable or disable line number and column number tracking.
-
Field Details
-
staticFlag
public static final boolean staticFlagWhether parser is static.- See Also:
-
bufpos
public int bufposPosition in buffer.
-
-
Constructor Details
-
CssCharStream
Constructor.- Parameters:
dstream
- the stream to read fromstartline
- startlinestartcolumn
- startcolumnbuffersize
- buffersize
-
CssCharStream
Constructor.- Parameters:
dstream
- the stream to read fromstartline
- startlinestartcolumn
- startcolumn
-
-
Method Details
-
beginToken
Start.- Specified by:
beginToken
in interfaceCharStream
- Returns:
- the next character that marks the beginning of the next token. All characters must remain in the buffer between two successive calls to this method to implement backup correctly.
- Throws:
IOException
-
readChar
Get the next character from the selected input. The method of selecting the input is the responsibility of the class implementing this interface. Read a character.- Specified by:
readChar
in interfaceCharStream
- Returns:
- the next character from the selected input
- Throws:
IOException
- on IO error
-
getEndColumn
public final int getEndColumn()Get token end column number.- Specified by:
getEndColumn
in interfaceCharStream
- Returns:
- the column number of the last character for current token (being matched after the last call to BeginToken).
-
getEndLine
public final int getEndLine()Get token end line number.- Specified by:
getEndLine
in interfaceCharStream
- Returns:
- the line number of the last character for current token (being matched after the last call to BeginToken).
-
getBeginColumn
public final int getBeginColumn()Get token beginning column number.- Specified by:
getBeginColumn
in interfaceCharStream
- Returns:
- the column number of the first character for current token (being matched after the last call to beginToken).
-
getBeginLine
public final int getBeginLine()Get token beginning line number.- Specified by:
getBeginLine
in interfaceCharStream
- Returns:
- the line number of the first character for current token (being matched after the last call to BeginToken).
-
backup
public final void backup(int amount) Backs up the input stream by amount steps. Lexer calls this method if it had already read some characters, but could not use them to match a (longer) token. So, they will be used again as the prefix of the next token and it is the implemetation's responsibility to do this right. Backup a number of characters.- Specified by:
backup
in interfaceCharStream
- Parameters:
amount
- Number of chars to back up.
-
getImage
Get token literal value.- Specified by:
getImage
in interfaceCharStream
- Returns:
- a string made up of characters from the marked token beginning to the current buffer position. Implementations have the choice of returning anything that they want to. For example, for efficiency, one might decide to just return null, which is a valid implementation.
-
getSuffix
public final char[] getSuffix(int len) Get the suffix.- Specified by:
getSuffix
in interfaceCharStream
- Returns:
- an array of characters that make up the suffix of length 'len' for
the currently matched token. This is used to build up the matched string
for use in actions in the case of MORE. A simple and inefficient
implementation of this is as follows:
{ String t = getImage(); return t.substring(t.length() - len, t.length()).toCharArray(); }
-
done
public void done()The lexer calls this function to indicate that it is done with the stream and hence implementations can free any resources held by this class. Again, the body of this function can be just empty and it will not affect the lexer's operation. Reset buffer when finished.- Specified by:
done
in interfaceCharStream
-
adjustBeginLineColumn
public void adjustBeginLineColumn(int newLine, int newCol) Method to adjust line and column numbers for the start of a token.- Parameters:
newLine
- the new linenewCol
- the new column
-
setTabSize
public void setTabSize(int i) Set the tab size to use.- Specified by:
setTabSize
in interfaceCharStream
- Parameters:
i
- spaces per tab
-
getTabSize
public int getTabSize()- Specified by:
getTabSize
in interfaceCharStream
- Returns:
- Current tab size.
-
isTrackLineColumn
public boolean isTrackLineColumn()- Specified by:
isTrackLineColumn
in interfaceCharStream
- Returns:
true
if line number and column numbers should be tracked.
-
setTrackLineColumn
public void setTrackLineColumn(boolean tlc) Enable or disable line number and column number tracking.- Specified by:
setTrackLineColumn
in interfaceCharStream
- Parameters:
tlc
-true
to track it,false
to not do it.
-