Here you can find the source of indent(CharSequence input)
Parameter | Description |
---|---|
input | the input String |
public static StringBuilder indent(CharSequence input)
//package com.java2s; // compliance with the InfoGrid license. The InfoGrid license and important public class Main { /**//from ww w .j a v a 2 s . c o m * Indent a String. * * @param input the input String * @return the indented String. This returns StringBuilder as that is usually more efficient. */ public static StringBuilder indent(CharSequence input) { return indent(input, " ", 1, 1); } /** * Indent a String. * * @param input the input String * @param indent the indent to use * @return the indented String. This returns StringBuilder as that is usually more efficient. */ public static StringBuilder indent(CharSequence input, String indent) { return indent(input, indent, 1, 1); } /** * Indent a String. * * @param input the input String * @param indent the indent to use * @param firstLineN the number of indents to use for the first line * @param sunsequentN the number of indents to use for subsequent lines * @return the indented String. This returns StringBuilder as that is usually more efficient. */ public static StringBuilder indent(CharSequence input, String indent, int firstLineN, int sunsequentN) { StringBuilder buf = new StringBuilder(input.length() + indent.length() * firstLineN); // one line is sure to fit for (int k = 0; k < firstLineN; ++k) { buf.append(indent); } for (int i = 0; i < input.length(); ++i) { char c = input.charAt(i); switch (c) { case '\n': buf.append(c); for (int k = 0; k < sunsequentN; ++k) { buf.append(indent); } break; default: buf.append(c); break; } } return buf; } }