(text csv) - Comma separated values parser library

Library (text csv)

This library provides comma separated values parser and write procedures. The implementation conforms RFC 4180.

High level APIs

The high level APIs are implemented as object oriented style. So we have CSV object and its accessors.

Function csv? object

Returns #t if object is csv object, otherwise #f.

Retrieves CSV header from given CSV object csv if it has, otherwise '().

Retrieves CSV records from given CSV object csv if it has, otherwise '().

Reads CSV data from given port and returns csv object.

If the second form is called, the procedure opens string input port from given string and passes it to the first form.

The option will be passed to csv->list described below.

Writes given CSV object csv to the output port port.

Middle level APIs

Reads CSV data from given input port port and returns alist representing CSV data.

If optional argument first-line-is-header? is #t, then the procedure reads the first line as header line.

The returning alist is following format;

alist  := (header{0,1} record*)
header := (:header value*)
record := (:record value*)
value  := string

Note: the value returning from csv-records or csv-header do not have meta values :record and :header.

Low level APIs

Class <csv>

The class representing CSV. If you need to create empty CSV object, you can do like following code;

(make <csv>)

.

Make sure, you import (clos user) library.

Adds a CSV representing record list to given CSV object csv.

The record must have :record keyword in the first element of the list.

Sets a CSV header list to given CSV object csv.

If the second form is called, then first parse the string to CSV header and calls the first form with parsed CSV header.

The list must have :header keyword in the first element of the list.

Convenient procedures.

Adds given CSV records list to given CSV object csv.

If the second form is called, then first parse the given string to CSV representing list and call the first form.