From 7c8e3a6c8f0bfe14399214d98e2351be71edd282 Mon Sep 17 00:00:00 2001 From: Federico Ceratto Date: Fri, 12 Oct 2018 23:12:57 +0100 Subject: [PATCH] Handle empty lines in parsecsv Closes #8365 --- lib/pure/parsecsv.nim | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/pure/parsecsv.nim b/lib/pure/parsecsv.nim index 796114d37dbf0..831aada15b2fe 100644 --- a/lib/pure/parsecsv.nim +++ b/lib/pure/parsecsv.nim @@ -170,6 +170,9 @@ proc readRow*(my: var CsvParser, columns = 0): bool = ## Blank lines are skipped. var col = 0 # current column let oldpos = my.bufpos + while my.buf[my.bufpos] == '\c' or my.buf[my.bufpos] == '\l': + # skip initial empty lines + inc(my.bufpos) while my.buf[my.bufpos] != '\0': let oldlen = my.row.len if oldlen < col+1: @@ -235,7 +238,7 @@ when isMainModule: import os import strutils block: # Tests for reading the header row - let content = "One,Two,Three,Four\n1,2,3,4\n10,20,30,40,\n100,200,300,400\n" + let content = "\nOne,Two,Three,Four\n1,2,3,4\n10,20,30,40,\n100,200,300,400\n" writeFile("temp.csv", content) var p: CsvParser