Here you can find the source of indent(String string, int indentSize, boolean initialLine)
Parameter | Description |
---|---|
string | String to indent. |
indentSize | Number of spaces to indent by. 0 will indent using a tab. |
initialLine | Whether to indent initial line. |
public final static String indent(String string, int indentSize, boolean initialLine)
//package com.java2s; /*/* w ww. j a v a 2 s. co m*/ * @(#)TextUtility.java * * Copyright (c) 2003 DCIVision Ltd * All rights reserved. * * This software is the confidential and proprietary information of DCIVision * Ltd ("Confidential Information"). You shall not disclose such Confidential * Information and shall use it only in accordance with the terms of the license * agreement you entered into with DCIVision Ltd. */ public class Main { /** * indent * * Indent a String with line-breaks. * * @param string String to indent. * @param indentSize Number of spaces to indent by. 0 will indent using a tab. * @param initialLine Whether to indent initial line. * @return Indented string. */ public final static String indent(String string, int indentSize, boolean initialLine) { // Create indent String String indent; if (indentSize == 0) { indent = "\t"; } else { StringBuffer s = new StringBuffer(); for (int i = 0; i < indentSize; i++) { s.append(' '); } indent = s.toString(); } // Apply indent to input 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(); } }