cl-csv

API Reference

cl-csv

Facilities for reading and writing CSV format files

CL-CSV

  • Variable *QUOTE*
    #\"
    Default quote character
  • Variable *SEPARATOR*
    #\,
    Default separator character
  • Variable *QUOTE-ESCAPE*
    (with-output-to-string (#:g2)
      (princ (progn cl-csv:*quote*) #:g2)
      (princ (progn cl-csv:*quote*) #:g2))
    Default setting for escaping quotes
  • Variable *ENABLE-SIGNALS*
    nil
    Should the reading and writing process enable filtering signals
  • Condition CSV-PARSE-ERROR  (ERROR)
  • Function CSV-PARSE-ERROR (msg &rest args)
  • Condition CSV-DATA-READ
  • Function CSV-DATA-READ (data)
  • Condition CSV-ROW-READ
  • Function CSV-ROW-READ (row)
  • Generic-Function FORMAT-CSV-VALUE (val)
    Print values in ways that are most cross compatible with the csv format
  • Method FORMAT-CSV-VALUE (val)
  • Method FORMAT-CSV-VALUE (val)
  • Method FORMAT-CSV-VALUE (val)
  • Generic-Function WRITE-CSV-VALUE (val csv-stream &key formatter quote separator escape always-quote)
    Writes val to csv-stream in a formatted fashion. Keywords formatter: used to format val. Defaults to format-csv-value. quote: quoting character. Defaults to *quote* escape: escaping character. Defaults to *quote-escape* newline: newline character. Defaults to *write-newline* always-quote: Defaults to *always-quote*
  • Method WRITE-CSV-VALUE (val csv-stream &key (formatter #'format-csv-value) (quote *quote*) (separator *separator*) (escape *quote-escape*) (always-quote *always-quote*) (newline *write-newline*) &aux (formatted-value (funcall formatter val)) (should-quote (or always-quote (chars-in (list quote separator newline) formatted-value))))
  • Method WRITE-CSV-VALUE (val csv-stream &key (formatter #'format-csv-value) (quote *quote*) (separator *separator*) (escape *quote-escape*) (always-quote *always-quote*) (newline *write-newline*) &aux (formatted-value (funcall formatter val)) (should-quote (or always-quote (chars-in (list quote separator newline) formatted-value))))
  • Method WRITE-CSV-VALUE (val csv-stream &key (formatter #'format-csv-value) (quote *quote*) (separator *separator*) (escape *quote-escape*) (always-quote *always-quote*) (newline *write-newline*) &aux (formatted-value (funcall formatter val)) (should-quote (or always-quote (chars-in (list quote separator newline) formatted-value))))
  • Function WRITE-CSV-ROW (items &key stream ((separator *separator*) *separator*) ((quote *quote*) *quote*) ((escape *quote-escape*) *quote-escape*) ((newline *write-newline*) *write-newline*) ((always-quote *always-quote*) *always-quote*))
    Writes a list items to stream rows-of-items: iterable Keywords: stream: stream to write to. Default: nil. quote: quoting character. Defaults to *quote* escape: escaping character. Defaults to *quote-escape* newline: newline character. Defaults to *write-newline* always-quote: Defaults to *always-quote*
  • Function WRITE-CSV (rows-of-items &key stream ((separator *separator*) *separator*) ((quote *quote*) *quote*) ((escape *quote-escape*) *quote-escape*) ((newline *write-newline*) *write-newline*) ((always-quote *always-quote*) *always-quote*))
    Writes a csv to the given stream. rows-of-items: iterable Keywords: stream: stream to write to. Default: nil. nil - writes the rows to a string and returns it an open stream a pathname (overwrites if the file exists) quote: quoting character. Defaults to *quote* escape: escaping character. Defaults to *quote-escape* newline: newline character. Defaults to *write-newline* always-quote: Defaults to *always-quote*
  • Variable *DEFAULT-EXTERNAL-FORMAT*
    :default
    the external format used for opening files
  • Function READ-CSV-ROW (stream-or-string &key ((separator *separator*) *separator*) ((quote *quote*) *quote*) ((escape *quote-escape*) *quote-escape*) ((unquoted-empty-string-is-nil *unquoted-empty-string-is-nil*) *unquoted-empty-string-is-nil*) ((quoted-empty-string-is-nil *quoted-empty-string-is-nil*) *quoted-empty-string-is-nil*) ((trim-outer-whitespace *trim-outer-whitespace*) *trim-outer-whitespace*) ((newline *read-newline*) *read-newline*) ((escape-mode *escape-mode*) *escape-mode*) &aux (*separator* (etypecase *separator* (string (if (= 1 (length *separator*)) (schar *separator* 0) (error "only single character *separator* are currently supported:~a" *separator*))) (character *separator*))) (*read-newline* (etypecase *read-newline* (string (if (= 1 (length *read-newline*)) (schar *read-newline* 0) *read-newline*)) (character *read-newline*))) (current (make-array 20 :element-type 'character :adjustable t :fill-pointer 0)) (state :waiting) (i -1) (c #\nul) (elen (etypecase *quote-escape* (string (length *quote-escape*)) (character 1))) items items-tail (nl-match -1) (nl-len (etypecase *read-newline* (string (length *read-newline*)) (character 1))) (nl-len-1 (- nl-len 1)) (use-read-line? (etypecase *read-newline* (character (char= *read-newline* #\newline)) (string nil))) newline-matched? (line (unless use-read-line? (make-array *buffer-size* :element-type 'character))) (llen -1) read-line-got-a-newline?)
    Read in a CSV by data-row (which due to quoted newlines may be more than one line from the stream)
  • Function READ-CSV-SAMPLE (stream-or-string sample-size &key row-fn map-fn skip-first-p ((separator *separator*) *separator*) ((quote *quote*) *quote*) ((escape *quote-escape*) *quote-escape*) ((unquoted-empty-string-is-nil *unquoted-empty-string-is-nil*) *unquoted-empty-string-is-nil*) ((quoted-empty-string-is-nil *quoted-empty-string-is-nil*) *quoted-empty-string-is-nil*) ((trim-outer-whitespace *trim-outer-whitespace*) *trim-outer-whitespace*) ((newline *read-newline*) *read-newline*))
  • Function READ-CSV (stream-or-string &key row-fn map-fn sample skip-first-p ((separator *separator*) *separator*) ((quote *quote*) *quote*) ((escape *quote-escape*) *quote-escape*) ((unquoted-empty-string-is-nil *unquoted-empty-string-is-nil*) *unquoted-empty-string-is-nil*) ((quoted-empty-string-is-nil *quoted-empty-string-is-nil*) *quoted-empty-string-is-nil*) ((trim-outer-whitespace *trim-outer-whitespace*) *trim-outer-whitespace*) ((newline *read-newline*) *read-newline*) ((escape-mode *escape-mode*) *escape-mode*))
    Read in a CSV by data-row (which due to quoted newlines may be more than one line from the stream) row-fn: passing this parameter will cause this read to be streaming and results will be discarded after the row-fn is called with data map-fn: used for manipulating the data by row during collection if specified; (funcall map-fn data) is collected instead of data sample: when a positive integer, only take that many samples from the input file skip-first-p: when true, skips the first line in the csv Keywords: separator: character separating between data cells. Defaults to *separator* quote: quoting character for text strings. Defaults to *quote* escape: escape character. Defaults to *quote-escape*
  • Macro DO-CSV ((row-var stream-or-pathname &rest read-csv-keys) &body body)
    row-var: a variable that is passed into _body_ stream-or-pathname: a stream or a pathname to read the CSV data from read-csv-keys: keys and values passed to the _read-csv_ function body: body of the macro

cl-csv-clsql

Facilities for reading and writing CSV format files (and importing and exporting csvs from databases)

No packages.

cl-csv-data-table

Facilities for converting CSV data to data-tables

No packages.