Skip to content

Commit

Permalink
Correctly detect empty fields in a record
Browse files Browse the repository at this point in the history
  • Loading branch information
mattunderscorechampion committed Jul 10, 2014
1 parent 9a81d31 commit 25b010d
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions dpt.parse.lua
Original file line number Diff line number Diff line change
Expand Up @@ -223,16 +223,27 @@ local function parseRecordFields( recordRange )
local fieldBase = 0
local rangeString = recordRange:string()
local fields = rangeString:split( string.char( FD ) )
local fs = { num = #fields }
local fs = {}

local idx = 1
-- Break open into records & then fields
-- There is some duplication going on to get the field ranges
for i, field in ipairs(fields) do

local fieldRange = recordRange:range( fieldBase, #field )
fs[i] = { range = fieldRange, string = fieldRange:string() }
fs[idx] = { range = fieldRange, string = fieldRange:string() }
idx = idx + 1

-- Find any empty fields and the starting point of the next non-empty field
fieldBase = fieldBase + #field + 1
while recordRange:len() > fieldBase and recordRange:range( fieldBase, 1 ):int() == FD do
fs[idx] = { range = recordRange:range( fieldBase, 0 ), string = "" }
idx = idx + 1
fieldBase = fieldBase + 1
end

fieldBase = fieldBase + #field + 1 -- +1 for the delimiter
end
fs.num = idx - 1
return fs
end

Expand Down

0 comments on commit 25b010d

Please sign in to comment.