Coverage Report - org.jbehave.core.model.TableUtils
 
Classes in this File Line Coverage Branch Coverage Complexity
TableUtils
92%
12/13
91%
11/12
7
 
 1  
 package org.jbehave.core.model;
 2  
 
 3  
 import java.util.ArrayList;
 4  
 import java.util.List;
 5  
 
 6  
 import org.apache.commons.lang.StringUtils;
 7  
 
 8  0
 public class TableUtils {
 9  
 
 10  
     public static List<String> parseRow(String rowAsString, String separator, boolean trimValues) {
 11  2154
         StringBuffer regex = new StringBuffer();
 12  4310
         for (char c : separator.toCharArray()) {
 13  2156
             regex.append("\\").append(c);
 14  
         }
 15  2154
         List<String> values = new ArrayList<String>();
 16  26780
         for ( String value : rowAsString.split(regex.toString(),-1) ){
 17  24626
             values.add(trimValues ? value.trim() : value);
 18  
         }
 19  
         // ignore a leading and a trailing empty value
 20  2154
         if (StringUtils.isBlank(values.get(0))) {
 21  2148
             values.remove(0);
 22  
         }
 23  2154
         int lastIndex = values.size() - 1;
 24  2154
         if (lastIndex != -1 && StringUtils.isBlank(values.get(lastIndex))) {
 25  2148
             values.remove(lastIndex);
 26  
         }
 27  2154
         return values;
 28  
     }
 29  
 
 30  
 }