diff options
author | Aleksandar Pokopec <aleksandar.prokopec@epfl.ch> | 2010-02-09 15:31:11 +0000 |
---|---|---|
committer | Aleksandar Pokopec <aleksandar.prokopec@epfl.ch> | 2010-02-09 15:31:11 +0000 |
commit | 71e03e4aca90be26290ab222d2d5131c5b2d42db (patch) | |
tree | fd1da647346c01e7b0b447637d1502c74844a22b /src | |
parent | 1b99b4b148b04d0eafd6bd3fb55309c29f60eb2d (diff) | |
download | scala-71e03e4aca90be26290ab222d2d5131c5b2d42db.tar.gz scala-71e03e4aca90be26290ab222d2d5131c5b2d42db.tar.bz2 scala-71e03e4aca90be26290ab222d2d5131c5b2d42db.zip |
`replaceSomeIn` method added.
Diffstat (limited to 'src')
-rw-r--r-- | src/library/scala/util/matching/Regex.scala | 22 |
1 files changed, 8 insertions, 14 deletions
diff --git a/src/library/scala/util/matching/Regex.scala b/src/library/scala/util/matching/Regex.scala index 6f0e4d2a16..9e101eb0b8 100644 --- a/src/library/scala/util/matching/Regex.scala +++ b/src/library/scala/util/matching/Regex.scala @@ -111,30 +111,24 @@ class Regex(regex: String, groupNames: String*) { * Replaces all matches using a replacer function. * * @param target The string to match. - * @param replacer The function which maps a matched string to another string. + * @param replacer The function which maps a match to another string. * @return The target string after replacements. */ - def replaceAllIn(target: java.lang.CharSequence, replacer: String => String): String = { - val it = new Regex.MatchIterator(target, this, groupNames) with Replacement + def replaceAllIn(target: java.lang.CharSequence, replacer: Match => String): String = { + val it = new Regex.MatchIterator(target, this, groupNames).replacementData while (it.hasNext) { - val matchedString = it.next - it.replace(replacer(matchedString)) + val matchdata = it.next + it.replace(replacer(matchdata)) } it.replaced } - /** - * Replaces all matches using a replacer function. - * - * @param target The string to match. - * @param replacer The function which maps a match to another string. - * @return The target string after replacements. - */ - def replaceAllMatchesIn(target: java.lang.CharSequence, replacer: Match => String): String = { + def replaceSomeIn(target: java.lang.CharSequence, replacer: Match => Option[String]): String = { val it = new Regex.MatchIterator(target, this, groupNames).replacementData while (it.hasNext) { val matchdata = it.next - it.replace(replacer(matchdata)) + val replaceopt = replacer(matchdata) + if (replaceopt != None) it.replace(replaceopt.get) } it.replaced } |