01: /*
02: * Created on May 28, 2006
03: */
04: package uk.org.ponder.stringutil;
05:
06: public class StringUtil {
07: /** Compares two Strings for equality, where either may be null **/
08: public static final boolean equals(String a, String b) {
09: if (a == null) {
10: return b == null;
11: } else
12: return a.equals(b);
13: }
14:
15: /** Returns a hashCode for a String, which may be null **/
16: public static final int hashCode(String a) {
17: return a == null ? 0 : a.hashCode();
18: }
19:
20: /** JDK String.split is EXTREMELY slow and also has somewhat unclear
21: * semantics.
22: */
23: public static String[] split(String tosplit, char delim,
24: boolean trim) {
25: StringList togo = new StringList();
26: CharWrap buffer = new CharWrap();
27: for (int i = 0; i < tosplit.length(); ++i) {
28: char c = tosplit.charAt(i);
29: if (c == delim) {
30: togo.add(trim ? buffer.toString().trim() : buffer
31: .toString());
32: buffer.clear();
33: } else
34: buffer.append(c);
35: }
36: togo.add(trim ? buffer.toString().trim() : buffer.toString());
37: return togo.toStringArray();
38: }
39:
40: public static String[] parseArray(String tosplit) {
41: return split(tosplit, ',', true);
42: }
43: }
|