Here you can find the source of cleanWhitespaceAndIndentation(String s, String indent)
public static String cleanWhitespaceAndIndentation(String s, String indent)
//package com.java2s; /******************************************************************************* * Copyright (c) 2012 - 2017 Signal Iduna Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors:// w w w. ja va2s .c o m * itemis AG *******************************************************************************/ public class Main { public static String cleanWhitespaceAndIndentation(String s, String indent) { String res = s.replaceAll("[\r\n]", "\n") //normalize line feeds .replaceAll("\n\\s*", "\n") //trim front .replaceAll("\\s*\n", "\n") //trim back .replaceAll("[\r\n]", "\n" + indent) //indent new lines .replaceAll("\n\\s*\n", "\n") //remove empty lines .replaceAll("}\n", "}\n\n"); //insert empty lines after '}' if (indent.length() >= 2) { res = res.replaceAll("\n\\s*}$", "\n" + indent.substring(2) + "}"); //un-indent if a line contains a '}' } return res; } }