3
This library aims to simplify working with csvs to the bare minimum of tedium
5
* reads/writes csvs from/to strings, streams and files
6
* support streaming reads (allowing processing very large csvs, through read-csv's row-fn paramter)
7
* supports custom data formating
8
* settable quote, separator and quote-escapes
9
* supports multiline quoted data
14
I had many scattered, not well tested, not easily runable pieces of
15
csv code. I was unhappy with this situation then decided to refactor
16
all of this into a single location. I wrote tests for it and had a
17
library so I thought I might release it. This project started as
18
extensions and bugfixes on arnesi's CSV.
20
I then looked around and saw there are other csv libs out there that
21
probably mostly accomplished what I had set out to do. However, I
22
already had code that was tested and had an easier license (BSD) so, I
23
figured why not just release it anyway.
25
### Other Available CSV libs
26
* http://members.optusnet.com.au/apicard/csv-parser.lisp
27
* http://www.cliki.net/fare-csv
29
## Signals and Restarts
30
* `*enable-signals*` will cause a csv-data-read or csv-row-read to be
31
signaled for each piece of data and row read. There is a `filter`
32
restart available which will cause the filter value to be used
33
instead. Enabling signals is ~2xs as slow as not, so by default
35
* `in-csv` iterate clause and `read-csv` support `continue` and `filter`
36
restarts for errors occuring during read-csv-row
39
## Library Integration
41
* [data-table](https://github.com/AccelerationNet/data-table) - functions for building data-tables from csv's, must `(asdf:load-system :cl-csv-data-table)`
42
* [clsql](http://clsql.b9.com/) must `(asdf:load-system :cl-csv-clsql)`
44
* serial-import-from-csv
45
* [iterate](http://common-lisp.net/project/iterate) - provides an
46
`in-csv` driver clause for iterating over a CSV
51
;; read a file into a list of lists
52
(cl-csv:read-csv #P"file.csv")
53
=> (("1" "2" "3") ("4" "5" "6"))
55
;; read a file that's tab delimited
56
(cl-csv:read-csv #P"file.tab" :separator #\Tab)
58
;; read a file and return a list of objects created from each row
59
(cl-csv:read-csv #P"file.csv"
60
:map-fn #'(lambda (row)
61
(make-instance 'object
64
;; read csv from a string (streams also supported)
65
(cl-csv:read-csv "1,2,3
67
=> (("1" "2" "3") ("4" "5" "6"))
69
;; loop over a CSV for effect
71
(cl-csv:do-csv (row #P"file.csv")
72
(incf sum (parse-integer (nth 0 row))))
76
;; loop over a CSV using iterate
77
(iter (for (foo bar baz) in-csv #P"file.csv")
78
(collect (make-instance 'object :foo foo :baz baz)))
82
* [Acceleration.net](http://www.acceleration.net/)
83
* [Russ Tyndall](http://russ.unwashedmeme.com/blog)
84
* [Nathan Bird](http://the.unwashedmeme.com/blog)
85
* [Ryan Davis](http://ryepup.unwashedmeme.com/blog)
88
;; Copyright (c) 2011 Russ Tyndall , Acceleration.net http://www.acceleration.net
89
;; Copyright (c) 2002-2006, Edward Marco Baringer
90
;; All rights reserved.
92
;; Redistribution and use in source and binary forms, with or without
93
;; modification, are permitted provided that the following conditions are
96
;; - Redistributions of source code must retain the above copyright
97
;; notice, this list of conditions and the following disclaimer.
99
;; - Redistributions in binary form must reproduce the above copyright
100
;; notice, this list of conditions and the following disclaimer in the
101
;; documentation and/or other materials provided with the distribution.
103
;; - Neither the name of Edward Marco Baringer, nor BESE, nor the names
104
;; of its contributors may be used to endorse or promote products
105
;; derived from this software without specific prior written permission.
107
;; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
108
;; "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
109
;; LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
110
;; A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
111
;; OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
112
;; SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
113
;; LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
114
;; DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
115
;; THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
116
;; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
117
;; OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.