001/* 002 * Copyright (c) 2012-2018 Institut National des Sciences Appliquées de Lyon (INSA Lyon) and others 003 * 004 * This program and the accompanying materials are made available under the 005 * terms of the Eclipse Public License 2.0 which is available at 006 * http://www.eclipse.org/legal/epl-2.0. 007 * 008 * SPDX-License-Identifier: EPL-2.0 009 */ 010 011package org.eclipse.golo.compiler.utils; 012 013public final class StringBlockIndenter { 014 015 private StringBlockIndenter() { 016 // utility class 017 } 018 019 public static String unindent(String block, int columns) { 020 assert columns >= 0; 021 String[] lines = block.split("\\n"); 022 StringBuilder result = new StringBuilder(); 023 for (String line : lines) { 024 if (line.length() > columns) { 025 result.append(line.substring(columns)); 026 } else { 027 result.append(line); 028 } 029 result.append("\n"); 030 } 031 return result.toString(); 032 } 033}