MCPcopy Create free account
hub / github.com/PCGen/pcgen / replaceAll

Method replaceAll

PCGen-base/code/src/java/pcgen/base/lang/StringUtil.java:149–183  ·  view source on GitHub ↗

Replaces all of the instances of the find String with newStr in the (first) given String. @param original The input String in which the String replacement should take place @param find The String to find within the input String, and which will be replaced

(String original, String find, String replace)

Source from the content-addressed store, hash-verified

147 * replacement String
148 */
149 public static String replaceAll(String original, String find, String replace)
150 {
151 int startindex = original.indexOf(find);
152
153 if (startindex < 0)
154 {
155 return original;
156 }
157
158 char[] working = original.toCharArray();
159 StringBuilder sb =
160 new StringBuilder(original.length() + replace.length());
161
162 int currindex = 0;
163
164 while (startindex > -1)
165 {
166 for (int i = currindex; i < startindex; ++i)
167 {
168 sb.append(working[i]);
169 }
170
171 currindex = startindex;
172 sb.append(replace);
173 currindex += find.length();
174 startindex = original.indexOf(find, currindex);
175 }
176
177 for (int i = currindex; i < working.length; ++i)
178 {
179 sb.append(working[i]);
180 }
181
182 return sb.toString();
183 }
184
185 /**
186 * Tests to see if the given String has balanced parenthesis. Balanced means

Callers 15

testReplaceAllMethod · 0.95
unparseMethod · 0.95
unparseMethod · 0.95
checkFacetsDefinedMethod · 0.45
dataMethod · 0.45
unparseMethod · 0.45
unparseMethod · 0.45
parseTokenMethod · 0.45
parseNonEmptyTokenMethod · 0.45

Calls 3

indexOfMethod · 0.65
toStringMethod · 0.65
appendMethod · 0.45

Tested by 4

testReplaceAllMethod · 0.76
checkFacetsDefinedMethod · 0.36
dataMethod · 0.36