BUG-509: add missing copyright headers
[controller.git] / opendaylight / config / yang-jmx-generator-plugin / src / test / java / org / opendaylight / controller / config / yangjmxgenerator / plugin / util / FormattingUtil.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.controller.config.yangjmxgenerator.plugin.util;
9
10 import java.util.Scanner;
11
12 public class FormattingUtil {
13
14     public static String cleanUpEmptyLinesAndIndent(String input) {
15         StringBuffer output = new StringBuffer();
16         Scanner scanner = new Scanner(input);
17         while (scanner.hasNextLine()) {
18             String line = scanner.nextLine();
19             line = line.replaceAll("\t", " ");
20             while (line.contains("  ")) {
21                 line = line.replaceAll("  ", " ");
22             }
23             line = line.trim();
24             if (line.length() > 0) {
25                 output.append(line);
26                 output.append("\n");
27             }
28         }
29
30         return output.toString();
31     }
32 }