Class CodeBuffer
java.lang.Object
com.google.common.css.compiler.passes.CodeBuffer
Class to write/delete characters used by
CodePrinter subclasses to print out code.
It has finalized core public APIs to endure correct update of character index and line index
while operating on the buffer.
This class can be extended and with helper methods if necessary.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal CodeBufferappend(char c) Appendscto the buffer and updatenextCharIndex.final CodeBufferAppends thetoStringrepresentation ofoto the buffer.final CodeBufferAppendsstrto the buffer.voidDeletes the end of the buffer if it exactly equalss.final CodeBufferDeletes the last character in the buffer and updates thenextCharIndexandnextLineIndex.voiddeleteLastCharIfCharIs(char ch) Deletes the last character from the string builder if the character is as given.final CodeBufferdeleteLastChars(int n) Deletes lastncharacters in the buffer.final intReturns the current length of the buffer.final charReturns the last character in the buffer.final intReturnslastCharIndex.final intReturns the index of the line which contains the last character at lastCharIndex.final intReturnsnextCharIndex.final intReturnsnextLineIndex.final StringReturns buffer as String.final CodeBufferreset()Clears the contents of the buffer and resetsnextCharIndexandnextLineIndex.final CodeBufferAppends a newline to buffer, resettingnextCharIndexand incrementingnextLineIndex.
-
Constructor Details
-
CodeBuffer
public CodeBuffer()
-
-
Method Details
-
getOutput
Returns buffer as String. -
getCurrentLength
public final int getCurrentLength()Returns the current length of the buffer. -
getLastChar
public final char getLastChar()Returns the last character in the buffer. -
getNextCharIndex
public final int getNextCharIndex()ReturnsnextCharIndex. -
getNextLineIndex
public final int getNextLineIndex()ReturnsnextLineIndex. -
getLastCharIndex
public final int getLastCharIndex()ReturnslastCharIndex. -
getLastLineIndex
public final int getLastLineIndex()Returns the index of the line which contains the last character at lastCharIndex. It is always the same or 1 index behindnextLineIndex. -
append
Appendsstrto the buffer. The string is safe to contain newlines.nextCharIndexandnextLineIndexwill be updated accordingly.Prefer to use append(char c) API to append characters for efficiency.
-
append
Appendscto the buffer and updatenextCharIndex. -
append
Appends thetoStringrepresentation ofoto the buffer. -
startNewLine
Appends a newline to buffer, resettingnextCharIndexand incrementingnextLineIndex. -
deleteLastChar
Deletes the last character in the buffer and updates thenextCharIndexandnextLineIndex. -
deleteLastChars
Deletes lastncharacters in the buffer. -
reset
Clears the contents of the buffer and resetsnextCharIndexandnextLineIndex. -
deleteLastCharIfCharIs
public void deleteLastCharIfCharIs(char ch) Deletes the last character from the string builder if the character is as given.Subclasses can modify this method in order to delete more in cases where they've added extra delimiters.
- Parameters:
ch- the character to delete
-
deleteEndingIfEndingIs
Deletes the end of the buffer if it exactly equalss.
-