readFile raises EIO instead of returning nil; added system.writeFile
This commit is contained in:
parent
de659eba65
commit
04f9c2585a
6 changed files with 40 additions and 48 deletions
|
|
@ -947,18 +947,10 @@ proc transformFile*(infile, outfile: string,
|
|||
subs: openArray[tuple[pattern: TPeg, repl: string]]) {.
|
||||
rtl, extern: "npegs$1".} =
|
||||
## reads in the file `infile`, performs a parallel replacement (calls
|
||||
## `parallelReplace`) and writes back to `outfile`. Calls ``quit`` if an
|
||||
## `parallelReplace`) and writes back to `outfile`. Raises ``EIO`` if an
|
||||
## error occurs. This is supposed to be used for quick scripting.
|
||||
var x = readFile(infile)
|
||||
if not isNil(x):
|
||||
var f: TFile
|
||||
if open(f, outfile, fmWrite):
|
||||
write(f, x.parallelReplace(subs))
|
||||
close(f)
|
||||
else:
|
||||
quit("cannot open for writing: " & outfile)
|
||||
else:
|
||||
quit("cannot open for reading: " & infile)
|
||||
writeFile(outfile, x.parallelReplace(subs))
|
||||
|
||||
iterator split*(s: string, sep: TPeg): string =
|
||||
## Splits the string `s` into substrings.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue