View Javadoc

1   package org.starobjects.tested.fitnesse.internal.util;
2   
3   import fit.Fixture;
4   
5   public final class StringUtil {
6   
7       private StringUtil() {}
8   
9       /**
10       * Simply forces first char to be lower case.
11       */
12      public static String lowerLeading(final String str) {
13          if (StringUtil.emptyString(str)) {
14              return str;
15          }
16          return str.substring(0, 1).toLowerCase()
17                  + (str.length() > 1 ? str.substring(1) : "");
18      }
19  
20      public static boolean emptyString(final String str) {
21          return str == null || str.length() == 0;
22      }
23  
24      public static boolean nullSafeEquals(final String str1, final String str2) {
25          if (str1 == null || str2 == null) {
26              return false;
27          }
28          return str1.equals(str2);
29      }
30  
31      public static String memberIdFor(final String member) {
32          return StringUtil.lowerLeading(Fixture.camel(member));
33      }
34  
35      public static String simpleName(final String str) {
36          final int lastDot = str.lastIndexOf('.');
37          if (lastDot == -1) {
38              return str;
39          }
40          if (lastDot == str.length() - 1) {
41              throw new IllegalArgumentException("Name cannot end in '.'");
42          }
43          return str.substring(lastDot + 1);
44      }
45  
46      public static String[] splitOnCommas(final String commaSeparatedList) {
47          if (commaSeparatedList == null) {
48              return null;
49          }
50          final String removeLeadingWhiteSpace = StringUtil
51                  .removeLeadingWhiteSpace(commaSeparatedList);
52          // special handling
53          if (removeLeadingWhiteSpace.length() == 0) {
54              return new String[0];
55          }
56          return removeLeadingWhiteSpace.split("\\W*,\\W*");
57      }
58  
59      public static String removeLeadingWhiteSpace(final String str) {
60          if (str == null) {
61              return null;
62          }
63          return str.replaceAll("^\\W*", "");
64      }
65  
66  }