mirror of
https://github.com/corda/corda.git
synced 2025-01-23 12:58:35 +00:00
Implementation of String.replace(CharSequence, CharSequence)
This commit is contained in:
parent
97aec1691e
commit
76fa43548d
@ -495,6 +495,42 @@ public final class String
|
|||||||
return Pattern.compile(regex).matcher(this).replaceAll(replacement);
|
return Pattern.compile(regex).matcher(this).replaceAll(replacement);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String replace(CharSequence target, CharSequence replace) {
|
||||||
|
if (target.length() == 0) {
|
||||||
|
return this.infuse(replace.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
String targetString = target.toString();
|
||||||
|
String replaceString = replace.toString();
|
||||||
|
|
||||||
|
int targetSize = target.length();
|
||||||
|
|
||||||
|
StringBuilder returnValue = new StringBuilder();
|
||||||
|
String unhandled = this;
|
||||||
|
|
||||||
|
int index = -1;
|
||||||
|
while ((index = unhandled.indexOf(targetString)) != -1) {
|
||||||
|
returnValue.append(unhandled.substring(0, index)).append(replaceString);
|
||||||
|
unhandled = unhandled.substring(index + targetSize,
|
||||||
|
unhandled.length());
|
||||||
|
}
|
||||||
|
|
||||||
|
returnValue.append(unhandled);
|
||||||
|
return returnValue.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
private String infuse(String infuseWith) {
|
||||||
|
StringBuilder retVal = new StringBuilder();
|
||||||
|
|
||||||
|
String me = this;
|
||||||
|
for (int i = 0; i < me.length(); i++) {
|
||||||
|
retVal.append(infuseWith).append(me.substring(i, i + 1));
|
||||||
|
}
|
||||||
|
|
||||||
|
retVal.append(infuseWith);
|
||||||
|
return retVal.toString();
|
||||||
|
}
|
||||||
|
|
||||||
public native String intern();
|
public native String intern();
|
||||||
|
|
||||||
public static String valueOf(Object s) {
|
public static String valueOf(Object s) {
|
||||||
|
Loading…
Reference in New Issue
Block a user