skip UTF-8 or 16 BOMs if you find one. There's other BOMs but this should do for now

This commit is contained in:
Geoff Leyland 2014-06-09 17:58:38 +12:00
parent 70c5dd6f9b
commit ec99b22fae

View File

@ -263,12 +263,23 @@ local function separated_values_iterator(buffer, parameters)
local function field_find(pattern, init) local function field_find(pattern, init)
init = init or 1
local f, l, c = buffer:find(pattern, init + field_start - 1) local f, l, c = buffer:find(pattern, init + field_start - 1)
if not f then return end if not f then return end
return f - field_start + 1, l - field_start + 1, c return f - field_start + 1, l - field_start + 1, c
end end
-- Is there some kind of Unicode BOM here?
if field_find("^\239\187\191") then -- UTF-8
advance(3)
elseif field_find("^\254\255") then -- UTF-16 big-endian
advance(2)
elseif field_find("^\255\254") then -- UTF-16 little-endian
advance(2)
end
-- Start reading the file -- Start reading the file
local sep = guess_separator(buffer, parameters) local sep = guess_separator(buffer, parameters)
local line_start = 1 local line_start = 1