[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

11.16 text.csv - CSV tables

Module: text.csv
Provides a function to parse/generate CSV (comma separated value) tables. Actually, the separater is not limited to comma; you can customize it.

CSV format is widely used to exchange table-type data in plain text, although there are apparently no "formal" specification.

CSV table is consisted by a series of records, separated by a newline. Each record contains number of fields, separated by a separator character (by default, a comma). A field can contain comma or newline if quoted, i.e. surrounded by double-quote characters. To include double-quote character in a quoted field, use two consecutive double-quote character. Usually, the whitespaces around the field are ignored.

Right now, the following two low-level procedures are exported. A plan is to provide higher features, such as labelling fields and automatic conversions.

Function: make-csv-reader separator
Returns a procedure with one argument, input port. When the procedure is called, it reads one record from the port, and returns a list of fields. If input reaches EOF, it returns EOF.

Function: make-csv-writer separator &optional newline
Returns a procedure with two arguments, output port and a list of fields. When the procedure is called, it outputs a separater-separated fields with proper escapes, to the output port. You can also specify the record delimiter string by newline; for example, you can pass "\r\n" to prepare a file to be read by Windows programs.

This document was generated by Ken Dickey on November, 28 2002 using texi2html