Module xw.csv

CSV encoder/decoder
Part of this code is from lua-users.org


Usage:

local csv = require 'xw.csv'

Type xw.csv

xw.csv.append(theWriter, t)
String Buffer Feeder

xw.csv.evalFileHeader(file)
Scan the header line of a fiel and evaluates the first column name and the first separator
See evalLineHeader

xw.csv.evalLineHeader(line)
Scan a line evaluates the first column name and the first separator
See evalLineHeader

xw.csv.fileIterator(filename, options)
File iterator

xw.csv.fromCSV(s, separ)
Convert from CSV string to table (converts a single line of a CSV file)

xw.csv.getWriter(strBuff, separ)
Returns a table that represent a CSV writer based upon a xwLuaStringBuffer

xw.csv.toCSV(tt)
Convert from table to CSV string

Type xwLuaStringBuffer

Type xw.csv

Field(s)

xw.csv.append(theWriter, t)
String Buffer Feeder

Parameters

  • #table theWriter : The table containing details about the CVS buffer to append data in
  • #table t : The Data to be dumped on strBuff

Return value

#boolean: True or false (success or failure)

xw.csv.evalFileHeader(file)
Scan the header line of a fiel and evaluates the first column name and the first separator
See evalLineHeader

Parameter

  • #string file : The file name whose first line that will be evaluated

Return values

  1. #string: The basic separator
  2. #string: The content of the first column found
xw.csv.evalLineHeader(line)
Scan a line evaluates the first column name and the first separator
See evalLineHeader

Parameter

  • #string line : The line that will be evaluated

Return values

  1. #string: The basic separator
  2. #string: The content of the first column found
xw.csv.fileIterator(filename, options)
File iterator

Parameters

  • #string filename : The file to iterate on
  • #table options :

    Options table. Assumes values as: 'useHead' (true, false) to produce named output according to file first line,

                         'skipHead' (true, false) to produce unnamed output skipping file first line (unnamed output in any other case), 
                         'separ' (string) to define what char should be used as separator (default ',')
    

Return value

function

xw.csv.fromCSV(s, separ)
Convert from CSV string to table (converts a single line of a CSV file)

Parameters

  • #string s : The line to convert
  • #string separ : The separator char to match

Return value

#table: The converted table.

xw.csv.getWriter(strBuff, separ)
Returns a table that represent a CSV writer based upon a xwLuaStringBuffer

Parameters

  • #xwLuaStringBuffer strBuff : The string buffer to append data in
  • #string separ : The separator char

Return value

#table: The CSV Writer Unit.

xw.csv.toCSV(tt)
Convert from table to CSV string

Parameter

  • #table tt : The table to convert

Return value

#string:

Type xwLuaStringBuffer