Class CodeBuffer
- java.lang.Object
-
- com.google.common.css.compiler.passes.CodeBuffer
-
public class CodeBuffer extends java.lang.ObjectClass to write/delete characters used byCodePrintersubclasses 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 Constructor Description CodeBuffer()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description CodeBufferappend(char c)Appendscto the buffer and updatenextCharIndex.CodeBufferappend(java.lang.Object o)Appends thetoStringrepresentation ofoto the buffer.CodeBufferappend(java.lang.String str)Appendsstrto the buffer.voiddeleteEndingIfEndingIs(java.lang.String s)Deletes the end of the buffer if it exactly equalss.CodeBufferdeleteLastChar()Deletes 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.CodeBufferdeleteLastChars(int n)Deletes lastncharacters in the buffer.intgetCurrentLength()Returns the current length of the buffer.chargetLastChar()Returns the last character in the buffer.intgetLastCharIndex()ReturnslastCharIndex.intgetLastLineIndex()Returns the index of the line which contains the last character at lastCharIndex.intgetNextCharIndex()ReturnsnextCharIndex.intgetNextLineIndex()ReturnsnextLineIndex.java.lang.StringgetOutput()Returns buffer as String.CodeBufferreset()Clears the contents of the buffer and resetsnextCharIndexandnextLineIndex.CodeBufferstartNewLine()Appends a newline to buffer, resettingnextCharIndexand incrementingnextLineIndex.
-
-
-
Method Detail
-
getOutput
public final java.lang.String 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
public final CodeBuffer append(@Nullable java.lang.String str)
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
public final CodeBuffer append(char c)
Appendscto the buffer and updatenextCharIndex.
-
append
public final CodeBuffer append(java.lang.Object o)
Appends thetoStringrepresentation ofoto the buffer.
-
startNewLine
public final CodeBuffer startNewLine()
Appends a newline to buffer, resettingnextCharIndexand incrementingnextLineIndex.
-
deleteLastChar
public final CodeBuffer deleteLastChar()
Deletes the last character in the buffer and updates thenextCharIndexandnextLineIndex.
-
deleteLastChars
public final CodeBuffer deleteLastChars(int n)
Deletes lastncharacters in the buffer.
-
reset
public final CodeBuffer 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
public void deleteEndingIfEndingIs(java.lang.String s)
Deletes the end of the buffer if it exactly equalss.
-
-