diff options
author | Grzegorz Adam Hankiewicz <gradha@imap.cc> | 2013-12-30 12:47:01 +0100 |
---|---|---|
committer | Grzegorz Adam Hankiewicz <gradha@imap.cc> | 2014-01-15 22:23:16 +0100 |
commit | 338a93f1197fe135e31b13865ab0ef6aa9ee9864 (patch) | |
tree | 78094e12e7d6a3e33fae243bb04a9994acf1f0d2 /lib/system.nim | |
parent | db7d0e6a66f1c9fe45d4e584403f450a22fd90a3 (diff) | |
download | Nim-338a93f1197fe135e31b13865ab0ef6aa9ee9864.tar.gz |
Adds docstrings to lines() iterators.
Diffstat (limited to 'lib/system.nim')
-rw-r--r-- | lib/system.nim | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/lib/system.nim b/lib/system.nim index 56bb6fe75..0257670f4 100644 --- a/lib/system.nim +++ b/lib/system.nim @@ -2236,8 +2236,19 @@ when not defined(JS): #and not defined(NimrodVM): when hostOS != "standalone": iterator lines*(filename: string): TaintedString {.tags: [FReadIO].} = - ## Iterate over any line in the file named `filename`. - ## If the file does not exist `EIO` is raised. + ## Iterates over any line in the file named `filename`. + ## + ## If the file does not exist `EIO` is raised. The iterated lines will be + ## stripped off the trailing newline character(s). Example: + ## + ## .. code-block:: nimrod + ## import strutils + ## + ## proc transformLetters(filename: string) = + ## var buffer = "" + ## for line in filename.lines: + ## buffer.add(line.replace("a", "0") & '\x0A') + ## writeFile(filename, buffer) var f = open(filename) var res = TaintedString(newStringOfCap(80)) while f.readLine(res): yield res @@ -2245,6 +2256,17 @@ when not defined(JS): #and not defined(NimrodVM): iterator lines*(f: TFile): TaintedString {.tags: [FReadIO].} = ## Iterate over any line in the file `f`. + ## + ## The iterated lines will be stripped off the trailing newline + ## character(s). Example: + ## + ## .. code-block:: nimrod + ## proc countZeros(filename: TFile): tuple[lines, zeros: int] = + ## for line in filename.lines: + ## for letter in line: + ## if letter == '0': + ## result.zeros += 1 + ## result.lines += 1 var res = TaintedString(newStringOfCap(80)) while f.readLine(res): yield res |