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