summary refs log tree commit diff stats
path: root/lib/pure
diff options
context:
space:
mode:
authorAndreas Rumpf <rumpf_a@web.de>2016-05-28 19:53:13 +0200
committerAndreas Rumpf <rumpf_a@web.de>2016-05-28 19:53:43 +0200
commiteba3355393b2d2ac9b2880dcc039751aaef5643d (patch)
tree761df1a8a3add9314b2d50eeb0d2e7cf7a3723e4 /lib/pure
parent48f30544041aa1cb1cff956da2380b477daf42bd (diff)
downloadNim-eba3355393b2d2ac9b2880dcc039751aaef5643d.tar.gz
adds another 'open' to parsecsv; refs #3695
Diffstat (limited to 'lib/pure')
-rw-r--r--lib/pure/parsecsv.nim11
1 files changed, 11 insertions, 0 deletions
diff --git a/lib/pure/parsecsv.nim b/lib/pure/parsecsv.nim
index af51e1201..bb291bcbc 100644
--- a/lib/pure/parsecsv.nim
+++ b/lib/pure/parsecsv.nim
@@ -77,6 +77,15 @@ proc open*(my: var CsvParser, input: Stream, filename: string,
   my.row = @[]
   my.currRow = 0
 
+proc open*(my: var CsvParser, filename: string,
+           separator = ',', quote = '"', escape = '\0',
+           skipInitialSpace = false) =
+  ## same as the other `open` but creates the file stream for you.
+  var s = newFileStream(filename, fmRead)
+  if s == nil: my.error(0, "cannot open: " & filename)
+  open(my, s, filename, separator,
+       quote, escape, skipInitialSpace)
+
 proc parseField(my: var CsvParser, a: var string) =
   var pos = my.bufpos
   var buf = my.buf
@@ -131,6 +140,8 @@ proc readRow*(my: var CsvParser, columns = 0): bool =
   ## reads the next row; if `columns` > 0, it expects the row to have
   ## exactly this many columns. Returns false if the end of the file
   ## has been encountered else true.
+  ##
+  ## Blank lines are skipped.
   var col = 0 # current column
   var oldpos = my.bufpos
   while my.buf[my.bufpos] != '\0':