Here you can find the source of indentText(String text, boolean indentFirstLine)
Parameter | Description |
---|---|
text | the possibly multi line text which is to be indented. This argument can be null , in which case the string "null" is used for this argument. |
indentFirstLine | true if the first line of the specified text must be indented, false if the first line must not be indented |
public static String indentText(String text, boolean indentFirstLine)
//package com.java2s; //License from project: Apache License public class Main { private static final String INDENTATION = " "; private static final String NULL_STR = "null"; /**/*from w ww. j a v a 2 s. c o m*/ * Adds an indentation before every line (optionally the first line can be * an exception) of the given string. The line separator is the {@code '\n'} * character (UNICODE: 000A). * <P> * The indentation is currently two space characters. * * @param text the possibly multi line text which is to be indented. This * argument can be {@code null}, in which case the string {@code "null"} * is used for this argument. * @param indentFirstLine {@code true} if the first line of the specified * text must be indented, {@code false} if the first line must not be * indented * @return the specified text after the applied indentation. This method * never returns {@code null} (not even if the specified text was * {@code null}). * * @see #toIndentedString(Object, boolean) */ public static String indentText(String text, boolean indentFirstLine) { String result = text != null ? text.replace("\n", "\n" + INDENTATION) : NULL_STR; return indentFirstLine ? (INDENTATION + result) : result; } }