~quanrong/chez-csv

Chez Scheme CSV library

ff1be4b Improve formatting

1 year, 5 months ago

3c7cf92 Untabify...

1 year, 5 months ago

#Chez Scheme CSV library

Read and write CSV files (and other tabular delimited text formats) in Chez Scheme.

It intends to be more flexible, faster and robust than the delimited text procedures provided by chez-stats.

It can handle different CSV dialects (see make-dialect below). By default, it expects a dialect with #\, as field delimiter, #\" as quotation character, Unix line termination style and non-significant initial whitespace in every field.

#Installation

#Akku

$ akku install chez-csv

#Manually

Copy chez-csv.sls into your project's directory.

#Usage

Once installed, import it into your Scheme file:

(import (chez-csv))

#Provided procedures

#csv-read
(csv-read input-port [dialect-record]) -> vector-of-#(vector-of-strings)

Dialect-record is optional. If provided, it must be a record constructed with make-dialect.

Returns the read CSV as a vector of vectors of strings, where every vector of strings corresponds to a row, and every string to a field.

#csv-write
(csv-write output-port vector-of-#(vector-of-strings) [dialect-record]) ->
{side effect}

Dialect-record is optional. If provided, it must be a record constructed with make-dialect.

Writes the provided vector of vectors of strings as a CSV in the specified dialect (when provided) or in the default one. Every vector of strings will be written as a CSV row, where every string is a field.

#make-dialect
(make-dialect delimiter quotechar line-termination skip-initial-space)
-> dialect-record
  • delimiter: Character. Field delimiter.
  • quotechar: Character. Field quotation character.
  • line-termination: Symbol, either unix or dos. Line-termination style.
  • skip-initial-space: Boolean. Indicates whether to skip all spaces at the beginning of every field.

Returns a record representing the specified CSV dialect.