Skip to content

Commit

Permalink
Merge pull request #5527 from som-snytt/fix/use-modern-replace
Browse files Browse the repository at this point in the history
String.replaceAllLiterally is String.replace
  • Loading branch information
lrytz committed Dec 12, 2016
2 parents d34e44e + f0d4e1e commit 2d90142
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions src/library/scala/collection/immutable/StringLike.scala
Original file line number Diff line number Diff line change
Expand Up @@ -165,20 +165,14 @@ self =>
if (toString.endsWith(suffix)) toString.substring(0, toString.length() - suffix.length)
else toString

/** Replace all literal occurrences of `literal` with the string `replacement`.
* This is equivalent to [[java.lang.String#replaceAll]] except that both arguments
* are appropriately quoted to avoid being interpreted as metacharacters.
/** Replace all literal occurrences of `literal` with the literal string `replacement`.
* This method is equivalent to [[java.lang.String#replace]].
*
* @param literal the string which should be replaced everywhere it occurs
* @param replacement the replacement string
* @return the resulting string
*/
def replaceAllLiterally(literal: String, replacement: String): String = {
val arg1 = Regex.quote(literal)
val arg2 = Regex.quoteReplacement(replacement)

toString.replaceAll(arg1, arg2)
}
def replaceAllLiterally(literal: String, replacement: String): String = toString.replace(literal, replacement)

/** For every line in this string:
*
Expand Down

0 comments on commit 2d90142

Please sign in to comment.