re.nim: Make tests green and deprecate 'parallelReplace'; it should be 'multiReplace' for consistency with strutils.nim
This commit is contained in:
parent
06a4dcb17d
commit
d0d02c2fe3
1 changed files with 12 additions and 5 deletions
|
|
@ -470,8 +470,8 @@ proc replacef*(s: string, sub: Regex, by: string): string =
|
||||||
prev = match.last + 1
|
prev = match.last + 1
|
||||||
add(result, substr(s, prev))
|
add(result, substr(s, prev))
|
||||||
|
|
||||||
proc parallelReplace*(s: string, subs: openArray[
|
proc multiReplace*(s: string, subs: openArray[
|
||||||
tuple[pattern: Regex, repl: string]]): string =
|
tuple[pattern: Regex, repl: string]]): string =
|
||||||
## Returns a modified copy of ``s`` with the substitutions in ``subs``
|
## Returns a modified copy of ``s`` with the substitutions in ``subs``
|
||||||
## applied in parallel.
|
## applied in parallel.
|
||||||
result = ""
|
result = ""
|
||||||
|
|
@ -490,13 +490,20 @@ proc parallelReplace*(s: string, subs: openArray[
|
||||||
# copy the rest:
|
# copy the rest:
|
||||||
add(result, substr(s, i))
|
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,
|
proc transformFile*(infile, outfile: string,
|
||||||
subs: openArray[tuple[pattern: Regex, repl: string]]) =
|
subs: openArray[tuple[pattern: Regex, repl: string]]) =
|
||||||
## reads in the file ``infile``, performs a parallel replacement (calls
|
## reads in the file ``infile``, performs a parallel replacement (calls
|
||||||
## ``parallelReplace``) and writes back to ``outfile``. Raises ``IOError`` if an
|
## ``parallelReplace``) and writes back to ``outfile``. Raises ``IOError`` if an
|
||||||
## error occurs. This is supposed to be used for quick scripting.
|
## error occurs. This is supposed to be used for quick scripting.
|
||||||
var x = readFile(infile).string
|
var x = readFile(infile).string
|
||||||
writeFile(outfile, x.parallelReplace(subs))
|
writeFile(outfile, x.multiReplace(subs))
|
||||||
|
|
||||||
iterator split*(s: string, sep: Regex): string =
|
iterator split*(s: string, sep: Regex): string =
|
||||||
## Splits the string ``s`` into substrings.
|
## Splits the string ``s`` into substrings.
|
||||||
|
|
@ -579,12 +586,12 @@ const ## common regular expressions
|
||||||
## describes an URL
|
## describes an URL
|
||||||
|
|
||||||
when isMainModule:
|
when isMainModule:
|
||||||
doAssert match("(a b c)", re"\( .* \)")
|
doAssert match("(a b c)", rex"\( .* \)")
|
||||||
doAssert match("WHiLe", re("while", {reIgnoreCase}))
|
doAssert match("WHiLe", re("while", {reIgnoreCase}))
|
||||||
|
|
||||||
doAssert "0158787".match(re"\d+")
|
doAssert "0158787".match(re"\d+")
|
||||||
doAssert "ABC 0232".match(re"\w+\s+\d+")
|
doAssert "ABC 0232".match(re"\w+\s+\d+")
|
||||||
doAssert "ABC".match(re"\d+ | \w+")
|
doAssert "ABC".match(rex"\d+ | \w+")
|
||||||
|
|
||||||
{.push warnings:off.}
|
{.push warnings:off.}
|
||||||
doAssert matchLen("key", re(reIdentifier)) == 3
|
doAssert matchLen("key", re(reIdentifier)) == 3
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue