1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.seasar.cubby.internal.util;
17
18
19
20
21
22
23 public class StringUtils {
24
25
26
27
28
29
30
31
32 public static final boolean isEmpty(final String text) {
33 return text == null || text.length() == 0;
34 }
35
36
37
38
39
40
41
42
43
44
45 public static boolean equalsIgnoreCase(final String target1,
46 final String target2) {
47 return (target1 == null) ? (target2 == null) : target1
48 .equalsIgnoreCase(target2);
49 }
50
51
52
53
54
55
56
57
58 public static boolean isBlank(final String str) {
59 if (str == null || str.length() == 0) {
60 return true;
61 }
62 for (int i = 0; i < str.length(); i++) {
63 if (!Character.isWhitespace(str.charAt(i))) {
64 return false;
65 }
66 }
67 return true;
68 }
69
70
71
72
73
74
75
76
77
78 public static boolean isNotBlank(final String str) {
79 return !isBlank(str);
80 }
81
82
83
84
85
86
87
88
89
90
91
92
93 public static final String replace(final String text,
94 final String fromText, final String toText) {
95
96 if (text == null || fromText == null || toText == null) {
97 return null;
98 }
99 final StringBuilder builder = new StringBuilder(100);
100 int pos = 0;
101 int pos2 = 0;
102 while (true) {
103 pos = text.indexOf(fromText, pos2);
104 if (pos == 0) {
105 builder.append(toText);
106 pos2 = fromText.length();
107 } else if (pos > 0) {
108 builder.append(text.substring(pos2, pos));
109 builder.append(toText);
110 pos2 = pos + fromText.length();
111 } else {
112 builder.append(text.substring(pos2));
113 break;
114 }
115 }
116 return builder.toString();
117 }
118
119 }