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) |
|
| xw.csv.evalFileHeader(file) |
|
| xw.csv.evalLineHeader(line) |
|
| xw.csv.fileIterator(filename, options) |
|
| xw.csv.fromCSV(s, separ) |
|
| xw.csv.getWriter(strBuff, separ) |
|
| xw.csv.toCSV(tt) |
|
Type xwLuaStringBuffer
Type xw.csv
Field(s)
- xw.csv.append(theWriter, t)
-
String Buffer FeederParameters
#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 evalLineHeaderParameter
#string file: The file name whose first line that will be evaluated
Return values
- #string: The basic separator
- #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 evalLineHeaderParameter
#string line: The line that will be evaluated
Return values
- #string: The basic separator
- #string: The content of the first column found
- xw.csv.fileIterator(filename, options)
-
File iteratorParameters
#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 xwLuaStringBufferParameters
#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 stringParameter
#table tt: The table to convert
Return value
#string: