Class StringCharStream
java.lang.Object
com.google.common.css.compiler.ast.StringCharStream
- All Implemented Interfaces:
CharStream
Efficient
String based CharStream implementation.-
Constructor Summary
ConstructorsConstructorDescriptionStringCharStream(String inputString) Creates a character stream for a given string. -
Method Summary
Modifier and TypeMethodDescriptionvoidbackup(int amount) Backs up the input stream by amount steps.charReturns the next character that marks the beginning of the next token.intconvertToCharacterIndex(int lineNumber, int indexInLine) Returns an absolute character location for given line and column location.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.intReturns the column number of the first character for current token (being matched after the last call to beginToken).intReturns the line number of the first character for current token (being matched after the last call to beginToken).intintReturns the column number of the last character for current token (being matched after the last call to beginToken).intReturns the line number of the last character for current token (being matched after the last call to beginToken).getImage()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.intbooleancharreadChar()Returns the next character from the selected input.voidsetTabSize(int tabSize) voidsetTrackLineColumn(boolean trackLineColumn)
-
Constructor Details
-
StringCharStream
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
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:
readCharin interfaceCharStream- 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:
getEndColumnin interfaceCharStream
-
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:
getEndLinein interfaceCharStream
-
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:
getBeginColumnin interfaceCharStream
-
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:
getBeginLinein interfaceCharStream
-
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:
backupin interfaceCharStream- Parameters:
amount- amount
-
beginToken
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:
beginTokenin interfaceCharStream- Returns:
- next character
- Throws:
IOException
-
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:
getImagein interfaceCharStream
-
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:
getSuffixin interfaceCharStream
-
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:
donein interfaceCharStream
-
setTabSize
public void setTabSize(int tabSize) - Specified by:
setTabSizein interfaceCharStream
-
getTabSize
public int getTabSize()- Specified by:
getTabSizein interfaceCharStream
-
getTrackLineColumn
public boolean getTrackLineColumn()- Specified by:
getTrackLineColumnin interfaceCharStream
-
setTrackLineColumn
public void setTrackLineColumn(boolean trackLineColumn) - Specified by:
setTrackLineColumnin interfaceCharStream
-