/*
 * Copyright (C) 2010 BloatIt.
 * 
 * This file is part of BloatIt.
 * 
 * BloatIt is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * BloatIt is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Affero General Public License for more details.
 * 
 * You should have received a copy of the GNU Affero General Public License
 * along with BloatIt. If not, see <http://www.gnu.org/licenses/>.
 */

package com.bloatit.web.htmlrenderer;

class IndentedText {
    private int indentCount;
    private String text;
    private final String indentSeparator;
    private final String lineSeparator;

    public IndentedText() {
        this("  ", "\n");
    }

    private IndentedText(String indentSeparator, String lineSeparator) {
        this.indentSeparator = indentSeparator;
        this.lineSeparator = lineSeparator;
        this.indentCount = 0;
        this.text = "";
    }

    public void write(String newText) {
        for (int i = 0; i < this.indentCount; i++) {
            this.text += this.indentSeparator;
        }
        this.text += newText;
        this.text += this.lineSeparator;
    }

    public void indent() {
        this.indentCount += 1;
    }

    public void unindent() {
        this.indentCount -= 1;
    }

    public String getText() {
        return text;
    }

    public boolean hasContent() {
        return !text.isEmpty();
    }
}

@@ -832,16 +832,23 @@
 e String
+Builder
  text;%0A 
@@ -1209,10 +1209,27 @@
 t = 
-%22%22
+new StringBuilder()
 ;%0A  
@@ -1343,28 +1343,32 @@
    this.text
- += 
+.append(
 this.indentS
@@ -1367,32 +1367,33 @@
 .indentSeparator
+)
 ;%0A        %7D%0A    
@@ -1409,19 +1409,24 @@
 text
- += 
+.append(
 newText
+)
 ;%0A  
@@ -1440,20 +1440,24 @@
 his.text
- += 
+.append(
 this.lin
@@ -1462,24 +1462,25 @@
 ineSeparator
+)
 ;%0A    %7D%0A%0A   
@@ -1653,24 +1653,35 @@
  return text
+.toString()
 ;%0A    %7D%0A%0A   
@@ -1730,23 +1730,26 @@
 urn 
-!
 text.
-isEmpty()
+length() != 0
 ;%0A  

optimize IndentedText using a StringBuilder