List of utility methods to do String Indent Format
String | indent(String string, int indentSize, boolean initialLine) indent Indent a String with line-breaks. String indent; if (indentSize == 0) { indent = "\t"; } else { StringBuffer s = new StringBuffer(); for (int i = 0; i < indentSize; i++) { s.append(' '); indent = s.toString(); StringBuffer result = new StringBuffer(); if (initialLine) { result.append(indent); for (int i = 0; i < string.length(); i++) { char c = string.charAt(i); result.append(c); if (c == '\n') { result.append(indent); return result.toString(); |
String | indent(String string, int level, boolean indentFirst, int tabSize) Split the given string on each newline or line return, then indent all lines by tabSize for each level. String indention = indention(level, tabSize); String[] lines = string.split("\\r?\\n"); String answer = ""; for (int i = 0; i < lines.length; i++) { String l = lines[i]; if (i == 0) { if (indentFirst) { answer += indention + l; ... |
void | indent(String symbol, StringBuffer res, int indent, boolean comma) indent if (symbol.isEmpty()) { return; for (int i = 0; i < indent; i++) { res.append("\t"); res.append(symbol); if (comma) { ... |
String | indent(String text, String indentation, char indentationChar, int indentationLevel, int indentationSize, boolean requiresExtraIndentationOnFirstLine) indent String result = text; StringBuilder sb = new StringBuilder(); String[] lines = text.split("\n"); String theoricalIndentationText = lines[0].substring(0, indentationSize * indentationLevel); if (requiresExtraIndentationOnFirstLine) { for (int i = 0; i < indentationSize; i++) { sb.append(indentationChar); sb.append(lines[0].substring(indentationSize * indentationLevel)); for (int i = 1; i < lines.length; i++) { String line = lines[i]; if (indentation.length() > 0) { line = line.replaceFirst(theoricalIndentationText, indentation); sb.append('\n').append(line); if (text.endsWith("\n")) { sb.append('\n'); result = sb.toString(); return result; |
String | indent(String value, int spaces) Indents all lines of the argument string by the specified number of spaces. if (spaces < 0) spaces = 0; String indent = ""; for (int i = 0; i < spaces; i++) { indent += " "; String[] lines = value.split("\r\n|\r|\n"); String output = ""; ... |
StringBuffer | indent(StringBuffer buffer, int depth) indent if (depth <= 0) { return buffer; for (int i = 0; i < depth; i++) { buffer.append(" "); return buffer; |
void | indent(StringBuffer sb, int indentLevel) indent for (int i = 0; i < indentLevel; i++) { sb.append(INDENT_STRING); |
void | indent(StringBuilder b, int i) indent while (i-- > 0) b.append(" "); |
StringBuilder | indent(StringBuilder buffer, int d) Appends the specified number of space charcter to a string buffer and returns it. for (int i = 0; i < d; i++) { buffer.append(' '); return buffer; |
StringBuilder | indent(StringBuilder builder, int indent) Adds indent to builder. while (0 < indent) { builder.append(INDENT); indent--; return builder; |