MCPcopy Create free account
hub / github.com/google/re2j / quoteReplacement

Method quoteReplacement

java/com/google/re2j/Matcher.java:408–421  ·  view source on GitHub ↗

Quotes '\' and '$' in s, so that the returned string could be used in #appendReplacement as a literal replacement of s. @param s the string to be quoted @return the quoted string

(String s)

Source from the content-addressed store, hash-verified

406 * @return the quoted string
407 */
408 public static String quoteReplacement(String s) {
409 if (s.indexOf('\\') < 0 && s.indexOf('$') < 0) {
410 return s;
411 }
412 StringBuilder sb = new StringBuilder();
413 for (int i = 0; i < s.length(); ++i) {
414 char c = s.charAt(i);
415 if (c == '\\' || c == '$') {
416 sb.append('\\');
417 }
418 sb.append(c);
419 }
420 return sb.toString();
421 }
422
423 /**
424 * Appends to {@code sb} two strings: the text from the append position up to the beginning of the

Callers

nothing calls this directly

Calls 4

appendMethod · 0.80
indexOfMethod · 0.45
lengthMethod · 0.45
toStringMethod · 0.45

Tested by

no test coverage detected