stdcsv - anssihalmeaho/funl GitHub Wiki
stdcsv
Implements conversion to/from CSV formatted data (RFC 4180).
Functions
read-all
Converts CSV formatted data given as argument (opaque bytearray) to list of lines. Each line is list which contains fields (strings) in order. Optionally options map can be given as 2nd argument.
Option map may contain following options:
| Key | Value |
|---|---|
| 'comma' | field delimiter string (by default ',') |
| 'comment' | lines beginning with the comment character (string) without preceding whitespace are ignored |
| 'lazyquotes' | if true, a quote may appear in an unquoted field and a non-doubled quote may appear in a quoted field |
| 'trim-leading-space' | if true, leading white space in a field is ignored. This is done even if the field delimiter is white space. |
type: function
Format:
call(stdcsv.read-all opaque:bytearray) -> list(is-ok error-description list:lines)
call(stdcsv.read-all opaque:bytearray options:map) -> list(is-ok error-description list:lines)
Return value: list
Returned list contains
- bool: true if succeeded, false otherwise
- error description (string), '' if succeeded
- list of lines
write-all
Converts list of lines given as argument to CSV formatted bytearray. Each line is list which contains fields (strings) in order. Optionally options map can be given as 2nd argument.
Option map may contain following options:
| Key | Value |
|---|---|
| 'comma' | field delimiter string (by default ',') |
| 'useCRLF' | if true, ends each output line with \r\n instead of \n |
type: function
Format:
call(stdcsv.write-all list:lines) -> list(is-ok error-description opaque:bytearray)
call(stdcsv.write-all list:lines options:map) -> list(is-ok error-description opaque:bytearray)
Return value: list
Returned list contains
- bool: true if succeeded, false otherwise
- error description (string), '' if succeeded
- bytearray in CSV format