Coverage Report - net.sf.jmatchparser.template.engine.formatter.TrimFormatter
 
Classes in this File Line Coverage Branch Coverage Complexity
TrimFormatter
100%
12/12
100%
10/10
2,667
 
 1  
 /*
 2  
  * Copyright (c) 2006 - 2011 Michael Schierl
 3  
  * All rights reserved.
 4  
  * 
 5  
  * This program is free software: you can redistribute it and/or modify
 6  
  * it under the terms of the GNU General Public License as published by
 7  
  * the Free Software Foundation, either version 2 of the License, or
 8  
  * (at your option) any later version.
 9  
  * 
 10  
  * This program is distributed in the hope that it will be useful,
 11  
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 12  
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 13  
  * GNU General Public License for more details.
 14  
  * 
 15  
  * You should have received a copy of the GNU General Public License
 16  
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 17  
  */
 18  
 package net.sf.jmatchparser.template.engine.formatter;
 19  
 
 20  
 import java.io.PrintStream;
 21  
 
 22  
 import net.sf.jmatchparser.template.Formatter;
 23  
 
 24  
 public class TrimFormatter implements Formatter {
 25  
 
 26  
         private final boolean trimAll;
 27  
 
 28  406
         public TrimFormatter(boolean trimAll) {
 29  406
                 this.trimAll = trimAll;
 30  406
         }
 31  
 
 32  
         @Override
 33  
         public String getName() {
 34  406
                 return trimAll ? "trimall" : "trimlines";
 35  
         }
 36  
 
 37  
         @Override
 38  
         public String format(String content, PrintStream debugStream) {
 39  2
                 StringBuilder result = new StringBuilder();
 40  21
                 for (String line : content.split("\n")) {
 41  19
                         line = line.trim();
 42  19
                         if (trimAll)
 43  11
                                 line = line.replace('\t', ' ').replaceAll("  +", " ");
 44  19
                         if (line.length() > 0 || !trimAll) {
 45  12
                                 result.append(line).append('\n');
 46  
                         }
 47  
                 }
 48  2
                 return result.toString();
 49  
         }
 50  
 
 51  
 }