##### Coverage Report - org.jbehave.core.model.TableUtils

Classes in this File | Line Coverage | Branch Coverage | Complexity
TableUtils |
92% | 12/13
91% | 11/12
| 7.0;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 | 2156 |
             StringBuffer regex = new StringBuffer();
12 | 4314 |
             for (char c : separator.toCharArray()) {
13 | 2158 |
                 regex.append("\\").append(c);
14 |  |
             }
15 | 2156 |
             List<String> values = new ArrayList<String>();
16 | 26794 |
             for ( String value : rowAsString.split(regex.toString(),-1) ){
17 | 24638 |
                 values.add(trimValues ? value.trim() : value);
18 |  |
             }
19 |  |
             // ignore a leading and a trailing empty value
20 | 2156 |
             if (StringUtils.isBlank(values.get(0))) {
21 | 2150 |
                 values.remove(0);
22 |  |
             }
23 | 2156 |
             int lastIndex = values.size() - 1;
24 | 2156 |
             if (lastIndex != -1 && StringUtils.isBlank(values.get(lastIndex))) {
25 | 2150 |
                 values.remove(lastIndex);
26 |  |
             }
27 | 2156 |
             return values;
28 |  |
         }
29 |  |
30 |  |
     }