# `rcsv` API

With this mod you can parse and write CSV from and to strings.
This mod is compliant with RFC 4180.

This mod provides functions to parse and write CSV from and
to Lua strings. Loading and writing to files need to be
done separately.

## Function reference

### `rcsv.parse_csv(text)`

Parses the string `text` which must be in a valid
CSV format according to RFC 4180 and returns a CSV table (see below).
`text` must be UTF-8 encoded.

All rows/records must have the same number of entries.

If the input is determined to be invalid, the function will
return `nil, <error message>` where `<error message>` is a
string (in English) that explains the kind of error, to be
shown in a log file, debug mode, etc.

Note: If you load the CSV string from a file with `io.open`,
you *MUST* open it in binary mode. This is required
to make it portable across operating systems.

## `rcsv.write_csv(rows)`

Given a CSV table named `rows` as input (see below),
will return a string that is valid CSV syntax.

Note: If you want to write this string to a file,
the file *MUST* be opened in binary mode to ensure
a correctly-formatted CSV file is written.

## CSV tables

A CSV table is the primary data structure representing the
data from a CSV-formatted file.

A CSV table is a table of tables.

The outer tables represent the rows.
The inner tables represent the values in each row and contain strings.

The length of each row *must* be equal.

For example, this table:

    {
    	{"value1", "value2", "value3"}, -- row 1
    	{"value4", "value5", "value6"}, -- row 2
    },

Is equivalent to the following CSV file:

    value1,value2,value3
    value4,value5,value6
