deprecated endOfFile and readLine
This commit is contained in:
parent
02e8e9c3ea
commit
4b39ac5cbe
6 changed files with 59 additions and 29 deletions
|
|
@ -1670,8 +1670,10 @@ when not defined(EcmaScript) and not defined(NimrodVM):
|
|||
proc Close*(f: TFile) {.importc: "fclose", nodecl.}
|
||||
## Closes the file.
|
||||
|
||||
proc EndOfFile*(f: TFile): Bool
|
||||
proc EndOfFile*(f: TFile): Bool {.deprecated.}
|
||||
## Returns true iff `f` is at the end.
|
||||
## **Deprecated since version 0.8.14**: Because Posix supports it poorly.
|
||||
|
||||
proc readChar*(f: TFile): char {.importc: "fgetc", nodecl.}
|
||||
## Reads a single character from the stream `f`. If the stream
|
||||
## has no more characters, `EEndOfFile` is raised.
|
||||
|
|
@ -1700,10 +1702,21 @@ when not defined(EcmaScript) and not defined(NimrodVM):
|
|||
proc write*(f: TFile, a: openArray[string])
|
||||
## Writes a value to the file `f`. May throw an IO exception.
|
||||
|
||||
proc readLine*(f: TFile): TaintedString
|
||||
proc readLine*(f: TFile): TaintedString {.deprecated.}
|
||||
## reads a line of text from the file `f`. May throw an IO exception.
|
||||
## A line of text may be delimited by ``CR``, ``LF`` or
|
||||
## ``CRLF``. The newline character(s) are not part of the returned string.
|
||||
##
|
||||
## **Deprecated since 0.8.14**: Use the `readLine` that takes a ``var``
|
||||
## parameter instead.
|
||||
|
||||
proc readLine*(f: TFile, line: var TaintedString): bool
|
||||
## reads a line of text from the file `f` into `line`. `line` must not be
|
||||
## ``nil``! May throw an IO exception.
|
||||
## A line of text may be delimited by ``CR``, ``LF`` or
|
||||
## ``CRLF``. The newline character(s) are not part of the returned string.
|
||||
## Returns ``false`` if the end of the file has been reached, ``true``
|
||||
## otherwise. If ``false`` is returned `line` contains no new data.
|
||||
|
||||
proc writeln*[Ty](f: TFile, x: Ty) {.inline.}
|
||||
## writes a value `x` to `f` and then writes "\n".
|
||||
|
|
@ -1843,18 +1856,14 @@ when not defined(EcmaScript) and not defined(NimrodVM):
|
|||
## Iterate over any line in the file named `filename`.
|
||||
## If the file does not exist `EIO` is raised.
|
||||
var f = open(filename)
|
||||
var res = ""
|
||||
while not endOfFile(f):
|
||||
rawReadLine(f, res)
|
||||
yield TaintedString(res)
|
||||
Close(f)
|
||||
var res = TaintedString(newStringOfCap(80))
|
||||
while f.readLine(res): yield res
|
||||
close(f)
|
||||
|
||||
iterator lines*(f: TFile): TaintedString =
|
||||
## Iterate over any line in the file `f`.
|
||||
var res = ""
|
||||
while not endOfFile(f):
|
||||
rawReadLine(f, res)
|
||||
yield TaintedString(res)
|
||||
var res = TaintedString(newStringOfCap(80))
|
||||
while f.readLine(res): yield TaintedString(res)
|
||||
|
||||
include "system/assign"
|
||||
include "system/repr"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue