mirror of
https://github.com/geoffleyland/lua-csv.git
synced 2024-11-23 01:34:19 +00:00
csv.lua: rename anchor_pos to field_start
This commit is contained in:
parent
0daa2ae5d7
commit
e2ea3d2f1a
22
lua/csv.lua
22
lua/csv.lua
@ -151,7 +151,7 @@ end
|
|||||||
local function separated_values_iterator(file, parameters)
|
local function separated_values_iterator(file, parameters)
|
||||||
local buffer_size = parameters.buffer_size or DEFAULT_BUFFER_SIZE
|
local buffer_size = parameters.buffer_size or DEFAULT_BUFFER_SIZE
|
||||||
local buffer = ""
|
local buffer = ""
|
||||||
local anchor_pos = 1
|
local field_start = 1
|
||||||
local line_start = 1
|
local line_start = 1
|
||||||
|
|
||||||
|
|
||||||
@ -160,7 +160,7 @@ local function separated_values_iterator(file, parameters)
|
|||||||
if p > buffer_size then
|
if p > buffer_size then
|
||||||
local remove = math.floor((p-1) / buffer_size) * buffer_size
|
local remove = math.floor((p-1) / buffer_size) * buffer_size
|
||||||
buffer = buffer:sub(remove + 1)
|
buffer = buffer:sub(remove + 1)
|
||||||
anchor_pos = anchor_pos - remove
|
field_start = field_start - remove
|
||||||
line_start = line_start - remove
|
line_start = line_start - remove
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -215,21 +215,21 @@ local function separated_values_iterator(file, parameters)
|
|||||||
|
|
||||||
|
|
||||||
local function advance(n)
|
local function advance(n)
|
||||||
anchor_pos = anchor_pos + n
|
field_start = field_start + n
|
||||||
truncate(anchor_pos)
|
truncate(field_start)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
local function field_sub(a, b)
|
local function field_sub(a, b)
|
||||||
b = b == -1 and b or b + anchor_pos - 1
|
b = b == -1 and b or b + field_start - 1
|
||||||
return sub(a + anchor_pos - 1, b)
|
return sub(a + field_start - 1, b)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
local function field_find(pattern, init)
|
local function field_find(pattern, init)
|
||||||
local f, l, c = find(pattern, init + anchor_pos - 1)
|
local f, l, c = find(pattern, init + field_start - 1)
|
||||||
if not f then return end
|
if not f then return end
|
||||||
return f - anchor_pos + 1, l - anchor_pos + 1, c
|
return f - field_start + 1, l - field_start + 1, c
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
@ -248,7 +248,7 @@ local function separated_values_iterator(file, parameters)
|
|||||||
|
|
||||||
while true do
|
while true do
|
||||||
local field_start_line = line
|
local field_start_line = line
|
||||||
local field_start_column = anchor_pos - line_start + 1
|
local field_start_column = field_start - line_start + 1
|
||||||
local field_end, sep_end, this_sep
|
local field_end, sep_end, this_sep
|
||||||
local tidy
|
local tidy
|
||||||
|
|
||||||
@ -284,7 +284,7 @@ local function separated_values_iterator(file, parameters)
|
|||||||
value = value:gsub("\r\n", "\n"):gsub("\r", "\n")
|
value = value:gsub("\r\n", "\n"):gsub("\r", "\n")
|
||||||
for nl in value:gmatch("\n()") do
|
for nl in value:gmatch("\n()") do
|
||||||
line = line + 1
|
line = line + 1
|
||||||
line_start = nl + anchor_pos
|
line_start = nl + field_start
|
||||||
end
|
end
|
||||||
|
|
||||||
value = tidy(value)
|
value = tidy(value)
|
||||||
@ -329,7 +329,7 @@ local function separated_values_iterator(file, parameters)
|
|||||||
sep_end = sep_end + 1
|
sep_end = sep_end + 1
|
||||||
end
|
end
|
||||||
line = line + 1
|
line = line + 1
|
||||||
line_start = anchor_pos + sep_end
|
line_start = field_start + sep_end
|
||||||
end
|
end
|
||||||
|
|
||||||
advance(sep_end)
|
advance(sep_end)
|
||||||
|
Loading…
Reference in New Issue
Block a user