From ac033b30757f92f533ce6cec6b7c128dad2d6ad1 Mon Sep 17 00:00:00 2001 From: Geoff Leyland Date: Fri, 6 Dec 2013 12:56:02 +1300 Subject: [PATCH] ignore blank lines (I'm not sure this is a good thing *in* the file, but ignoring blank lines at the end is a good idea) --- lua/csv.lua | 4 +++- lua/test.lua | 3 +++ test-data/blank-line.csv | 1 + 3 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 test-data/blank-line.csv diff --git a/lua/csv.lua b/lua/csv.lua index 53916d8..79a5d16 100644 --- a/lua/csv.lua +++ b/lua/csv.lua @@ -285,7 +285,9 @@ local function separated_values_iterator(file, parameters) elseif parameters.header and not header then header = fields else - coroutine.yield(fields, starts) + if fields[1] ~= "" or fields[2] then -- ignore blank lines + coroutine.yield(fields, starts) + end end field_count, fields, starts = 0, {}, {} end diff --git a/lua/test.lua b/lua/test.lua index 327fab3..fc0eac2 100644 --- a/lua/test.lua +++ b/lua/test.lua @@ -50,6 +50,9 @@ apple:four,charlie:60]], apple = { name = "ALPHA", transform = string.lower }, charlie = { transform = function(x) return tonumber(x) * 10 end }}}) +test("../test-data/blank-line.csv", [[ +this,file,ends,with,a,blank,line]]) + if errors == 0 then io.stdout:write("Passed\n") diff --git a/test-data/blank-line.csv b/test-data/blank-line.csv new file mode 100644 index 0000000..d04ca0d --- /dev/null +++ b/test-data/blank-line.csv @@ -0,0 +1 @@ +this,file,ends,with,a,blank,line