Class CssCharStream

java.lang.Object
org.htmlunit.cssparser.parser.CssCharStream
All Implemented Interfaces:
CharStream

public final class CssCharStream extends Object implements 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

    Fields
    Modifier and Type
    Field
    Description
    int
    Position in buffer.
    static final boolean
    Whether parser is static.
  • Constructor Summary

    Constructors
    Constructor
    Description
    CssCharStream(Reader dstream, int startline, int startcolumn)
    Constructor.
    CssCharStream(Reader dstream, int startline, int startcolumn, int buffersize)
    Constructor.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    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
    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
    Get token literal value.
    final char[]
    getSuffix(int len)
    Get the suffix.
    int
    boolean
    final char
    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.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • staticFlag

      public static final boolean staticFlag
      Whether parser is static.
      See Also:
    • bufpos

      public int bufpos
      Position in buffer.
  • Constructor Details

    • CssCharStream

      public CssCharStream(Reader dstream, int startline, int startcolumn, int buffersize)
      Constructor.
      Parameters:
      dstream - the stream to read from
      startline - startline
      startcolumn - startcolumn
      buffersize - buffersize
    • CssCharStream

      public CssCharStream(Reader dstream, int startline, int startcolumn)
      Constructor.
      Parameters:
      dstream - the stream to read from
      startline - startline
      startcolumn - startcolumn
  • Method Details

    • beginToken

      public final char beginToken() throws IOException
      Start.
      Specified by:
      beginToken in interface CharStream
      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

      public final char readChar() throws IOException
      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 interface CharStream
      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 interface CharStream
      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 interface CharStream
      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 interface CharStream
      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 interface CharStream
      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 interface CharStream
      Parameters:
      amount - Number of chars to back up.
    • getImage

      public final String getImage()
      Get token literal value.
      Specified by:
      getImage in interface CharStream
      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 interface CharStream
      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 interface CharStream
    • 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 line
      newCol - the new column
    • setTabSize

      public void setTabSize(int i)
      Set the tab size to use.
      Specified by:
      setTabSize in interface CharStream
      Parameters:
      i - spaces per tab
    • getTabSize

      public int getTabSize()
      Specified by:
      getTabSize in interface CharStream
      Returns:
      Current tab size.
    • isTrackLineColumn

      public boolean isTrackLineColumn()
      Specified by:
      isTrackLineColumn in interface CharStream
      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 interface CharStream
      Parameters:
      tlc - true to track it, false to not do it.