MCPcopy
hub / github.com/google/guava / replaceFrom

Method replaceFrom

guava/src/com/google/common/base/CharMatcher.java:680–694  ·  view source on GitHub ↗

Returns a string copy of the input character sequence, with each matching BMP character replaced by a given replacement character. For example: {@snippet : CharMatcher.is('a').replaceFrom("radar", 'o') } ... returns {@code "rodor"}. <p>The default implementation uses {@link #indexIn(CharSequence)

(CharSequence sequence, char replacement)

Source from the content-addressed store, hash-verified

678 * @return the new string
679 */
680 public String replaceFrom(CharSequence sequence, char replacement) {
681 String string = sequence.toString();
682 int pos = indexIn(string);
683 if (pos == -1) {
684 return string;
685 }
686 char[] chars = string.toCharArray();
687 chars[pos] = replacement;
688 for (int i = pos + 1; i < chars.length; i++) {
689 if (matches(chars[i])) {
690 chars[i] = replacement;
691 }
692 }
693 return new String(chars);
694 }
695
696 /**
697 * Returns a string copy of the input character sequence, with each matching BMP character

Callers 9

InternetDomainNameMethod · 0.45
reallyTestEmptyMethod · 0.45
reallyTestNoMatchesMethod · 0.45
reallyTestAllMatchesMethod · 0.45
testReplaceFromMethod · 0.45

Calls 8

indexInMethod · 0.95
matchesMethod · 0.95
removeFromMethod · 0.95
toStringMethod · 0.65
toCharArrayMethod · 0.45
lengthMethod · 0.45
charAtMethod · 0.45
appendMethod · 0.45

Tested by 8

reallyTestEmptyMethod · 0.36
reallyTestNoMatchesMethod · 0.36
reallyTestAllMatchesMethod · 0.36
testReplaceFromMethod · 0.36