mirror of
https://github.com/geoffleyland/lua-csv.git
synced 2024-11-23 01:34:19 +00:00
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:
parent
70c5dd6f9b
commit
ec99b22fae
11
lua/csv.lua
11
lua/csv.lua
@ -263,12 +263,23 @@ local function separated_values_iterator(buffer, parameters)
|
||||
|
||||
|
||||
local function field_find(pattern, init)
|
||||
init = init or 1
|
||||
local f, l, c = buffer:find(pattern, init + field_start - 1)
|
||||
if not f then return end
|
||||
return f - field_start + 1, l - field_start + 1, c
|
||||
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
|
||||
local sep = guess_separator(buffer, parameters)
|
||||
local line_start = 1
|
||||
|
Loading…
Reference in New Issue
Block a user