MCPcopy Create free account
hub / github.com/antlr/codebuff / replaceFrom

Method replaceFrom

corpus/java/training/guava/base/CharMatcher.java:753–767  ·  view source on GitHub ↗

Returns a string copy of the input character sequence, with each character that matches this matcher replaced by a given replacement character. For example: CharMatcher.is('a').replaceFrom("radar", 'o') ... returns "rodor". The default implementation uses {@link

(CharSequence sequence, char replacement)

Source from the content-addressed store, hash-verified

751 * @return the new string
752 */
753 public String replaceFrom(CharSequence sequence, char replacement) {
754 String string = sequence.toString();
755 int pos = indexIn(string);
756 if (pos == -1) {
757 return string;
758 }
759 char[] chars = string.toCharArray();
760 chars[pos] = replacement;
761 for (int i = pos + 1; i < chars.length; i++) {
762 if (matches(chars[i])) {
763 chars[i] = replacement;
764 }
765 }
766 return new String(chars);
767 }
768
769 /**
770 * Returns a string copy of the input character sequence, with each character that matches this

Callers 1

InternetDomainNameMethod · 0.45

Calls 7

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

Tested by

no test coverage detected