~ubuntu-branches/ubuntu/vivid/cl-csv/vivid-proposed

« back to all changes in this revision

Viewing changes to README.md

  • Committer: Package Import Robot
  • Author(s): Dimitri Fontaine
  • Date: 2014-08-04 19:57:54 UTC
  • mfrom: (1.1.2)
  • Revision ID: package-import@ubuntu.com-20140804195754-vo64b5r1daxwg8ld
Tags: 20140211-1
Quicklisp release update.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# cl-csv
 
2
 
 
3
This library aims to simplify working with csvs to the bare minimum of tedium
 
4
 
 
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
 
10
* A test suite
 
11
 
 
12
## Rationale 
 
13
 
 
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.
 
19
 
 
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.
 
24
 
 
25
### Other Available CSV libs
 
26
 * http://members.optusnet.com.au/apicard/csv-parser.lisp
 
27
 * http://www.cliki.net/fare-csv
 
28
 
 
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
 
34
   they are not enabled.
 
35
 * `in-csv` iterate clause and `read-csv` support `continue` and `filter`
 
36
   restarts for errors occuring during read-csv-row
 
37
 
 
38
 
 
39
## Library Integration
 
40
 
 
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)`
 
43
    * import-from-csv
 
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
 
47
 
 
48
## Examples
 
49
 
 
50
```lisp
 
51
;; read a file into a list of lists
 
52
(cl-csv:read-csv #P"file.csv")
 
53
=> (("1" "2" "3") ("4" "5" "6"))
 
54
 
 
55
;; read a file that's tab delimited
 
56
(cl-csv:read-csv #P"file.tab" :separator #\Tab)
 
57
 
 
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
 
62
                                            :foo (nth 0 row)
 
63
                                            :baz (nth 2 row))))
 
64
;; read csv from a string (streams also supported)
 
65
(cl-csv:read-csv "1,2,3
 
66
4,5,6")
 
67
=> (("1" "2" "3") ("4" "5" "6"))
 
68
 
 
69
;; loop over a CSV for effect
 
70
(let ((sum 0))
 
71
  (cl-csv:do-csv (row #P"file.csv")
 
72
    (incf sum (parse-integer (nth 0 row))))
 
73
  sum)
 
74
  
 
75
  
 
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)))
 
79
```
 
80
 
 
81
## Authors
 
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)
 
86
 
 
87
```
 
88
;; Copyright (c) 2011 Russ Tyndall , Acceleration.net http://www.acceleration.net
 
89
;; Copyright (c) 2002-2006, Edward Marco Baringer
 
90
;; All rights reserved.
 
91
;;
 
92
;; Redistribution and use in source and binary forms, with or without
 
93
;; modification, are permitted provided that the following conditions are
 
94
;; met:
 
95
;;
 
96
;;  - Redistributions of source code must retain the above copyright
 
97
;;    notice, this list of conditions and the following disclaimer.
 
98
;;
 
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.
 
102
;;
 
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.
 
106
;;
 
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.
 
118
```