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