Here you can find the source of indentStringBuffer(StringBuffer sb, int indent)
Parameter | Description |
---|---|
sb | non-null StringBuffer |
indent | non-negative indent |
public static void indentStringBuffer(StringBuffer sb, int indent)
//package com.java2s; //License from project: Apache License public class Main { private static String[] gIndentStrings; /**/*from ww w.ja v a 2 s .c o m*/ * add indent to a StringBuffer * @param sb non-null StringBuffer * @param indent non-negative indent */ public static void indentStringBuffer(StringBuffer sb, int indent) { sb.append(indentString(indent)); } /** * build indent String * @param indent non-negative every level indents 4 spaces * @return string with indented CR */ public static String indentString(int indent) { if (gIndentStrings == null) { buildIndentStrings(); } if (indent < gIndentStrings.length) return (gIndentStrings[indent]); // too long so build StringBuffer sb = new StringBuffer(4 * indent); for (int i = 0; i < indent; i++) sb.append(" "); return (sb.toString()); } /** * build indent String * @return string with indented CR */ protected static synchronized void buildIndentStrings() { if (gIndentStrings != null) { return; } String[] TheStrings = new String[16]; String IndentString = ""; for (int i = 0; i < TheStrings.length; i++) { TheStrings[i] = IndentString; IndentString += " "; } gIndentStrings = TheStrings; } /**{ method @name toString @function convert a char to a string @param c the char @return the String }*/ public static String toString(char c) { StringBuffer s = new StringBuffer(); s.append(c); return (s.toString()); } }