Class StringCharStream

java.lang.Object
com.google.common.css.compiler.ast.StringCharStream
All Implemented Interfaces:
CharStream

public class StringCharStream extends Object implements CharStream
Efficient String based CharStream implementation.
  • Constructor Summary

    Constructors
    Constructor
    Description
    StringCharStream(String inputString)
    Creates a character stream for a given string.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    backup(int amount)
    Backs up the input stream by amount steps.
    char
    Returns the next character that marks the beginning of the next token.
    int
    convertToCharacterIndex(int lineNumber, int indexInLine)
    Returns an absolute character location for given line and column location.
    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.
    int
    Returns the column number of the first character for current token (being matched after the last call to beginToken).
    int
    Returns the line number of the first character for current token (being matched after the last call to beginToken).
    int
     
    int
    Returns the column number of the last character for current token (being matched after the last call to beginToken).
    int
    Returns the line number of the last character for current token (being matched after the last call to beginToken).
    Returns a string made up of characters from the marked token beginning to the current buffer position.
    char[]
    getSuffix(int len)
    Returns an array of characters that make up the suffix of length 'len' for the currently matched token.
    int
     
    boolean
     
    char
    Returns the next character from the selected input.
    void
    setTabSize(int tabSize)
     
    void
    setTrackLineColumn(boolean trackLineColumn)
     

    Methods inherited from class java.lang.Object

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

    • StringCharStream

      public StringCharStream(String inputString)
      Creates a character stream for a given string.
      Parameters:
      inputString - input string for this stream
  • Method Details

    • convertToCharacterIndex

      public int convertToCharacterIndex(int lineNumber, int indexInLine)
      Returns an absolute character location for given line and column location.
      Parameters:
      lineNumber - line number (1 based)
      indexInLine - column number (1 based)
      Returns:
      0 based absolute character index in the input string
    • getCharIndex

      public int getCharIndex()
      Returns:
      index of last read character
    • readChar

      public char readChar() throws IOException
      Returns the next character from the selected input. The method of selecting the input is the responsibility of the class implementing this interface. Can throw any java.io.IOException.
      Specified by:
      readChar in interface CharStream
      Throws:
      IOException
    • getEndColumn

      public int getEndColumn()
      Returns the column number of the last character for current token (being matched after the last call to beginToken).
      Specified by:
      getEndColumn in interface CharStream
    • getEndLine

      public int getEndLine()
      Returns the line number of the last character for current token (being matched after the last call to beginToken).
      Specified by:
      getEndLine in interface CharStream
    • getBeginColumn

      public int getBeginColumn()
      Returns the column number of the first character for current token (being matched after the last call to beginToken).
      Specified by:
      getBeginColumn in interface CharStream
    • getBeginLine

      public int getBeginLine()
      Returns the line number of the first character for current token (being matched after the last call to beginToken).
      Specified by:
      getBeginLine in interface CharStream
    • backup

      public 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.
      Specified by:
      backup in interface CharStream
      Parameters:
      amount - amount
    • beginToken

      public char beginToken() throws IOException
      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.
      Specified by:
      beginToken in interface CharStream
      Returns:
      next character
      Throws:
      IOException
    • getImage

      public String getImage()
      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.
      Specified by:
      getImage in interface CharStream
    • getSuffix

      public char[] getSuffix(int len)
      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(); }

      Specified by:
      getSuffix in interface CharStream
    • 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.
      Specified by:
      done in interface CharStream
    • setTabSize

      public void setTabSize(int tabSize)
      Specified by:
      setTabSize in interface CharStream
    • getTabSize

      public int getTabSize()
      Specified by:
      getTabSize in interface CharStream
    • getTrackLineColumn

      public boolean getTrackLineColumn()
      Specified by:
      getTrackLineColumn in interface CharStream
    • setTrackLineColumn

      public void setTrackLineColumn(boolean trackLineColumn)
      Specified by:
      setTrackLineColumn in interface CharStream