Skip to content

Commit

Permalink
quick checkin of what i got
Browse files Browse the repository at this point in the history
  • Loading branch information
FourierTransformer committed May 31, 2023
1 parent 527620a commit e1d58df
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions ftcsv.lua
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,22 @@ local function initializeInputFromStringOrFile(inputFile, options, amount)
return inputString, file
end

local function determineArgumentOrder(delimiter, options)
-- backwards compatibile layer
if type(delimiter) == "string" then
return delimiter, options

-- the new format for parseLine
elseif type(delimiter) == "table" then
local realDelimiter = delimiter.delimiter or ","
return realDelimiter, delimiter

-- if nothing is specified, assume "," delimited and call it a day!
else
return ",", nil
end
end

local function parseOptions(delimiter, options, fromParseLine)
-- delimiter MUST be one character
assert(#delimiter == 1 and type(delimiter) == "string", "the delimiter must be of string type and exactly one character")
Expand Down Expand Up @@ -539,11 +555,13 @@ end

-- runs the show!
function ftcsv.parse(inputFile, delimiter, options)
local options, fieldsToKeep = parseOptions(delimiter, options, false)
local realDelimiter, realOptions = determineArgumentOrder(delimiter, options)

local parsedOptions, fieldsToKeep = parseOptions(realDelimiter, realOptions, false)

local inputString = initializeInputFromStringOrFile(inputFile, options, "*all")
local inputString = initializeInputFromStringOrFile(inputFile, parsedOptions, "*all")

local endOfHeaders, parserArgs, finalHeaders = parseHeadersAndSetupArgs(inputString, delimiter, options, fieldsToKeep, true)
local endOfHeaders, parserArgs, finalHeaders = parseHeadersAndSetupArgs(inputString, realDelimiter, parsedOptions, fieldsToKeep, true)

local output = parseString(inputString, endOfHeaders, parserArgs)

Expand Down

0 comments on commit e1d58df

Please sign in to comment.