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)

This commit is contained in:
Geoff Leyland 2013-12-06 12:56:02 +13:00
parent 279ca0717d
commit ac033b3075
3 changed files with 7 additions and 1 deletions

View File

@ -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

View File

@ -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")

1
test-data/blank-line.csv Normal file
View File

@ -0,0 +1 @@
this,file,ends,with,a,blank,line
1 this file ends with a blank line