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
FieldsModifier and TypeFieldDescriptionintPosition in buffer.static final booleanWhether parser is static. -
Constructor Summary
ConstructorsConstructorDescriptionCssCharStream(Reader dstream, int startline, int startcolumn) Constructor.CssCharStream(Reader dstream, int startline, int startcolumn, int buffersize) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoidadjustBeginLineColumn(int newLine, int newCol) Method to adjust line and column numbers for the start of a token.final voidbackup(int amount) Backs up the input stream by amount steps.final charStart.voiddone()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 intGet token beginning column number.final intGet token beginning line number.final intGet token end column number.final intGet token end line number.final StringgetImage()Get token literal value.final char[]getSuffix(int len) Get the suffix.intbooleanfinal charreadChar()Get the next character from the selected input.voidsetTabSize(int i) Set the tab size to use.voidsetTrackLineColumn(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:
beginTokenin 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:
readCharin 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:
getEndColumnin 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:
getEndLinein 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:
getBeginColumnin 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:
getBeginLinein 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:
backupin interfaceCharStream- Parameters:
amount- Number of chars to back up.
-
getImage
Get token literal value.- Specified by:
getImagein 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:
getSuffixin 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:
donein 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:
setTabSizein interfaceCharStream- Parameters:
i- spaces per tab
-
getTabSize
public int getTabSize()- Specified by:
getTabSizein interfaceCharStream- Returns:
- Current tab size.
-
isTrackLineColumn
public boolean isTrackLineColumn()- Specified by:
isTrackLineColumnin interfaceCharStream- Returns:
trueif 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:
setTrackLineColumnin interfaceCharStream- Parameters:
tlc-trueto track it,falseto not do it.
-