fixes #13013, reverts previous changes to readLines() (#13036) [backport]

* Revert "remove default argument for readLines (#12807) [backport]"

This reverts commit c949b81efd.
This commit is contained in:
cooldome 2020-01-05 08:22:41 +00:00 • committed by Andreas Rumpf
commit a3df1b55f3
3 changed files with 7 additions and 5 deletions

View file

@ -147,7 +147,7 @@ proc registerAdditionalOps*(c: PCtx) =
wrap1s(fileExists, osop) wrap1s(fileExists, osop)
wrapDangerous(writeFile, ioop) wrapDangerous(writeFile, ioop)
wrap1s(readFile, ioop) wrap1s(readFile, ioop)
wrap2si(staticReadLines, ioop) wrap2si(readLines, ioop)
systemop getCurrentExceptionMsg systemop getCurrentExceptionMsg
systemop getCurrentException systemop getCurrentException
registerCallback c, "stdlib.*.staticWalkDir", proc (a: VmArgs) {.nimcall.} = registerCallback c, "stdlib.*.staticWalkDir", proc (a: VmArgs) {.nimcall.} =

View file

@ -696,10 +696,10 @@ proc writeFile*(filename: string, content: openArray[byte]) {.since: (1, 1).} =
else: else:
raise newException(IOError, "cannot open: " & filename) raise newException(IOError, "cannot open: " & filename)
proc staticReadLines*(filename: string, n: Natural): seq[TaintedString] = proc readLines*(filename: string, n: Natural): seq[TaintedString] =
## Compile time read `n` lines from the file named `filename`. Raises an IO exception ## read `n` lines from the file named `filename`. Raises an IO exception
## in case of an error. Raises EOF if file does not contain at least `n` lines. ## in case of an error. Raises EOF if file does not contain at least `n` lines.
## A line of text may be delimited by ``LF`` or ``CRLF``. ## Available at compile time. A line of text may be delimited by ``LF`` or ``CRLF``.
## The newline character(s) are not part of the returned strings. ## The newline character(s) are not part of the returned strings.
var f: File var f: File
if open(f, filename): if open(f, filename):
@ -713,6 +713,8 @@ proc staticReadLines*(filename: string, n: Natural): seq[TaintedString] =
else: else:
sysFatal(IOError, "cannot open: " & filename) sysFatal(IOError, "cannot open: " & filename)
proc readLines*(filename: string): seq[TaintedString] {.deprecated: "use readLines with two arguments".} =
readLines(filename, 1)
iterator lines*(filename: string): TaintedString {.tags: [ReadIOEffect].} = iterator lines*(filename: string): TaintedString {.tags: [ReadIOEffect].} =
## Iterates over any line in the file named `filename`. ## Iterates over any line in the file named `filename`.

View file

@ -13,7 +13,7 @@ static:
writeFile(filename, mytext) writeFile(filename, mytext)
const myfile_str = staticRead(filename) const myfile_str = staticRead(filename)
const myfile_str2 = readFile(filename) const myfile_str2 = readFile(filename)
const myfile_str_seq = staticReadLines(filename, 3) const myfile_str_seq = readLines(filename, 3)
static: static:
doAssert myfile_str == mytext doAssert myfile_str == mytext