re.nim: Make tests green and deprecate 'parallelReplace'; it should be 'multiReplace' for consistency with strutils.nim

This commit is contained in:
Araq
2017-11-28 01:38:46 +01:00
parent 06a4dcb17d
commit d0d02c2fe3

View File

@@ -470,8 +470,8 @@ proc replacef*(s: string, sub: Regex, by: string): string =
prev = match.last + 1
add(result, substr(s, prev))
proc parallelReplace*(s: string, subs: openArray[
tuple[pattern: Regex, repl: string]]): string =
proc multiReplace*(s: string, subs: openArray[
tuple[pattern: Regex, repl: string]]): string =
## Returns a modified copy of ``s`` with the substitutions in ``subs``
## applied in parallel.
result = ""
@@ -490,13 +490,20 @@ proc parallelReplace*(s: string, subs: openArray[
# copy the rest:
add(result, substr(s, i))
proc parallelReplace*(s: string, subs: openArray[
tuple[pattern: Regex, repl: string]]): string {.deprecated.} =
## Returns a modified copy of ``s`` with the substitutions in ``subs``
## applied in parallel.
## **Deprecated since version 0.18.0**: Use ``multiReplace`` instead.
result = multiReplace(s, subs)
proc transformFile*(infile, outfile: string,
subs: openArray[tuple[pattern: Regex, repl: string]]) =
## reads in the file ``infile``, performs a parallel replacement (calls
## ``parallelReplace``) and writes back to ``outfile``. Raises ``IOError`` if an
## error occurs. This is supposed to be used for quick scripting.
var x = readFile(infile).string
writeFile(outfile, x.parallelReplace(subs))
writeFile(outfile, x.multiReplace(subs))
iterator split*(s: string, sep: Regex): string =
## Splits the string ``s`` into substrings.
@@ -579,12 +586,12 @@ const ## common regular expressions
## describes an URL
when isMainModule:
doAssert match("(a b c)", re"\( .* \)")
doAssert match("(a b c)", rex"\( .* \)")
doAssert match("WHiLe", re("while", {reIgnoreCase}))
doAssert "0158787".match(re"\d+")
doAssert "ABC 0232".match(re"\w+\s+\d+")
doAssert "ABC".match(re"\d+ | \w+")
doAssert "ABC".match(rex"\d+ | \w+")
{.push warnings:off.}
doAssert matchLen("key", re(reIdentifier)) == 3