diff options
author | Araq <rumpf_a@web.de> | 2017-11-28 01:38:46 +0100 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2017-11-28 01:57:44 +0100 |
commit | d0d02c2fe32afacad7201a8159152ec60fd5f107 (patch) | |
tree | 77425171692b0c32332cbb0d33c844fbae89f021 /lib/impure/re.nim | |
parent | 06a4dcb17d9b4aef5b98bdac0b512055cc885f08 (diff) | |
download | Nim-d0d02c2fe32afacad7201a8159152ec60fd5f107.tar.gz |
re.nim: Make tests green and deprecate 'parallelReplace'; it should be 'multiReplace' for consistency with strutils.nim
Diffstat (limited to 'lib/impure/re.nim')
-rw-r--r-- | lib/impure/re.nim | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/lib/impure/re.nim b/lib/impure/re.nim index 24fc83366..2fbed2479 100644 --- a/lib/impure/re.nim +++ b/lib/impure/re.nim @@ -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 |