Skip to content

Having a dump function within lua-csv itself would be nice. #6

@fcr--

Description

@fcr--

How about something like this?

function dump(row, parameters)
  local separator = (parameter or {}).separator or ','
  local res = {}

  for i, value in ipairs(row) do
    local value = tostring(value)
    if value:find(separator, 1, true) or value:find('"', 1, true) then
      res[i] = ('"%s"'):format(value:gsub('"', '""'))
    else
      res[i] = value
    end
  end
  return table.concat(res, separator)
end

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions