MCPcopy Create free account
hub / github.com/ReadyTalk/avian / replace

Method replace

classpath/java/lang/String.java:346–371  ·  view source on GitHub ↗
(char oldChar, char newChar)

Source from the content-addressed store, hash-verified

344 }
345
346 public String replace(char oldChar, char newChar) {
347 if (data instanceof char[]) {
348 char[] buf = new char[length];
349 for (int i=0; i < length; i++) {
350 if (charAt(i) == oldChar) {
351 buf[i] = newChar;
352 } else {
353 buf[i] = charAt(i);
354 }
355 }
356 return new String(buf, 0, length, false);
357 } else {
358 byte[] buf = new byte[length];
359 byte[] orig = (byte[])data;
360 byte oldByte = (byte)oldChar;
361 byte newByte = (byte)newChar;
362 for (int i=0; i < length; i++) {
363 if (orig[i+offset] == oldByte) {
364 buf[i] = newByte;
365 } else {
366 buf[i] = orig[i+offset];
367 }
368 }
369 return new String(buf, 0, length, false);
370 }
371 }
372
373 public String substring(int start) {
374 return substring(start, length);

Callers

nothing calls this directly

Calls 10

charAtMethod · 0.95
infuseMethod · 0.95
indexOfMethod · 0.95
appendMethod · 0.95
substringMethod · 0.95
lengthMethod · 0.95
toStringMethod · 0.95
lengthMethod · 0.65
toStringMethod · 0.65
appendMethod · 0.65

Tested by

no test coverage detected