Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
...
Checking mergeability… Don't worry, you can still create the pull request.
  • 6 commits
  • 2 files changed
  • 0 commit comments
  • 2 contributors
Commits on Jan 20, 2012
@pnathan pnathan Filled in do-csv, added block for read-csv
4a943c9
@pnathan pnathan Adding some spaces between rows
0e8b518
Commits on Jan 31, 2012
@pnathan pnathan added some more information, not well formatted
f676ba8
Commits on Feb 06, 2012
@pnathan pnathan Merge commit 'a22a61a6bdaed36ee2e04dc705cf77ce6d9dc9d4' into pn-docs-1
7f5ce1c
Commits on Feb 11, 2012
@pnathan pnathan Documented csv.lisp and added documentation as a html file.
* Removed markdown
* Used Edi Weitz's template generation
377e201
Commits on Apr 12, 2012
@bobbysmith007 bobbysmith007 Merge pull request #5 from pnathan/master
Documention in HTML file; added function documentation for most of the CSV
47459b2
Showing with 413 additions and 12 deletions.
  1. +339 −0 DOCUMENTATION.html
  2. +74 −12 csv.lisp
View
339 DOCUMENTATION.html
@@ -0,0 +1,339 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
+<html>
+
+<head>
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
+ <title>A common lisp library providing easy csv reading and writing.</title>
+ <style type="text/css">
+ pre { padding:5px; background-color:#e0e0e0 }
+ h3, h4 { text-decoration: underline; }
+ a { text-decoration: none; padding: 1px 2px 1px 2px; }
+ a:visited { text-decoration: none; padding: 1px 2px 1px 2px; }
+ a:hover { text-decoration: none; padding: 1px 1px 1px 1px; border: 1px solid #000000; }
+ a:focus { text-decoration: none; padding: 1px 2px 1px 2px; border: none; }
+ a.none { text-decoration: none; padding: 0; }
+ a.none:visited { text-decoration: none; padding: 0; }
+ a.none:hover { text-decoration: none; border: none; padding: 0; }
+ a.none:focus { text-decoration: none; border: none; padding: 0; }
+ a.noborder { text-decoration: none; padding: 0; }
+ a.noborder:visited { text-decoration: none; padding: 0; }
+ a.noborder:hover { text-decoration: none; border: none; padding: 0; }
+ a.noborder:focus { text-decoration: none; border: none; padding: 0; }
+ pre.none { padding:5px; background-color:#ffffff }
+ </style>
+</head>
+
+<body bgcolor=white>
+
+<h2> CL-CSV - a Common Lisp library for csv reading and writing</h2>
+
+<blockquote>
+<br>&nbsp;<br><h3><a name=abstract class=none>Abstract</a></h3>
+
+<p>
+A common lisp library providing easy csv reading and writing.
+<p>
+The code license is found <a href="https://github.com/AccelerationNet/cl-csv/blob/master/LICENSE"> here</a>.
+
+
+
+<br>&nbsp;<br><h3><a class=none name="contents">Contents</a></h3>
+<ol>
+ <li><a href="#download">Download</a>
+ <li><a href="#dictionary">The CL-CSV dictionary</a>
+ <ol>
+ <li><a href="#*default-external-format*"><code>*default-external-format*</code></a>
+ <li><a href="#*newline*"><code>*newline*</code></a>
+ <li><a href="#*quote*"><code>*quote*</code></a>
+ <li><a href="#*quote-escape*"><code>*quote-escape*</code></a>
+ <li><a href="#*separator*"><code>*separator*</code></a>
+ <li><a href="#csv-parse-error"><code>csv-parse-error</code></a>
+ <li><a href="#csv-parse-error"><code>csv-parse-error</code></a>
+ <li><a href="#do-csv"><code>do-csv</code></a>
+ <li><a href="#format-csv-value"><code>format-csv-value</code></a>
+ <li><a href="#read-csv"><code>read-csv</code></a>
+ <li><a href="#read-csv-row"><code>read-csv-row</code></a>
+ <li><a href="#write-csv"><code>write-csv</code></a>
+ <li><a href="#write-csv-row"><code>write-csv-row</code></a>
+ <li><a href="#write-csv-value"><code>write-csv-value</code></a>
+ </ol>
+ <li><a href="#ack">Acknowledgements</a>
+</ol>
+
+<br>&nbsp;<br><h3><a class=none name="download">Download</a></h3>
+
+CL-CSV together with this documentation can be downloaded from <a
+href="https://github.com/AccelerationNet/cl-csv">https://github.com/AccelerationNet/cl-csv</a>.
+
+<br>&nbsp;<br><h3><a class=none name="dictionary">The CL-CSV dictionary</a></h3>
+
+
+
+<!-- Entry for *DEFAULT-EXTERNAL-FORMAT* -->
+
+<p><br>[Special variable]<br><a class=none name='*default-external-format*'><b>*default-external-format*</b></a>
+<blockquote><br>
+
+the external format used for opening files
+
+</blockquote>
+
+<!-- End of entry for *DEFAULT-EXTERNAL-FORMAT* -->
+
+
+<!-- Entry for *NEWLINE* -->
+
+<p><br>[Special variable]<br><a class=none name='*newline*'><b>*newline*</b></a>
+<blockquote><br>
+
+Default newline string
+
+</blockquote>
+
+<!-- End of entry for *NEWLINE* -->
+
+
+<!-- Entry for *QUOTE* -->
+
+<p><br>[Special variable]<br><a class=none name='*quote*'><b>*quote*</b></a>
+<blockquote><br>
+
+Default quote character
+
+</blockquote>
+
+<!-- End of entry for *QUOTE* -->
+
+
+<!-- Entry for *QUOTE-ESCAPE* -->
+
+<p><br>[Special variable]<br><a class=none name='*quote-escape*'><b>*quote-escape*</b></a>
+<blockquote><br>
+
+Default setting for escaping quotes
+
+</blockquote>
+
+<!-- End of entry for *QUOTE-ESCAPE* -->
+
+
+<!-- Entry for *SEPARATOR* -->
+
+<p><br>[Special variable]<br><a class=none name='*separator*'><b>*separator*</b></a>
+<blockquote><br>
+
+Default separator character
+
+</blockquote>
+
+<!-- End of entry for *SEPARATOR* -->
+
+
+<!-- Entry for CSV-PARSE-ERROR -->
+
+<p><br>[Condition type]<br><a class=none name='csv-parse-error'><b>csv-parse-error</b></a>
+<blockquote><br>
+
+
+
+</blockquote>
+
+<!-- End of entry for CSV-PARSE-ERROR -->
+
+
+<!-- Entry for CSV-PARSE-ERROR -->
+
+<p><br>[Function]<br><a class=none name='csv-parse-error'><b>csv-parse-error</b> <i>msg <tt>&amp;rest</tt> args</i> =&gt; <i>result</i></a>
+<blockquote><br>
+
+
+
+</blockquote>
+
+<!-- End of entry for CSV-PARSE-ERROR -->
+
+
+<!-- Entry for DO-CSV -->
+
+<p><br>[Macro]<br><a class=none name='do-csv'><b>do-csv</b> <i>(row-var stream-or-pathname <tt>&amp;rest</tt> read-csv-keys) declaration* statement*</i> =&gt; <i>result</i></a>
+<blockquote><br>
+
+<p>row-var: a variable that is passed into _body_
+
+<p>stream-or-pathname: a stream or a pathname to read the CSV data from
+
+<p>read-csv-keys: keys and values passed to the _read-csv_ function
+
+<p>body: body of the macro
+
+</blockquote>
+
+<!-- End of entry for DO-CSV -->
+
+
+<!-- Entry for FORMAT-CSV-VALUE -->
+
+<p><br>[Generic function]<br><a class=none name='format-csv-value'><b>format-csv-value</b> <i>val</i> =&gt; <i>result</i></a>
+<blockquote><br>
+
+
+
+</blockquote>
+
+<!-- End of entry for FORMAT-CSV-VALUE -->
+
+
+<!-- Entry for FORMAT-CSV-VALUE -->
+
+<p><br>[Method]<br><a class=none><b>format-csv-value</b> <i>val</i> =&gt; <i>result</i></a>
+<blockquote><br>
+
+Print values in ways that are most cross compatible with the csv format
+
+</blockquote>
+
+<!-- End of entry for FORMAT-CSV-VALUE -->
+
+
+<!-- Entry for READ-CSV -->
+
+<p><br>[Function]<br><a class=none name='read-csv'><b>read-csv</b> <i>stream-or-string <tt>&amp;key</tt> row-fn map-fn sample skip-first-p (separator *separator*) (quote *quote*) (escape *quote-escape*)</i> =&gt; <i>result</i></a>
+<blockquote><br>
+
+<P>Read in a CSV by data-row (which due to quoted newlines may be more
+ than one line from the stream)
+
+<p>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
+
+<p>map-fn: used for manipulating the data by row during collection if
+specified; (funcall map-fn data) is collected instead of data
+
+<p>sample: when a positive integer, only take that many samples from the input file
+
+<p>skip-first-p: when true, skips the first line in the csv
+
+<P>Keywords:
+
+<p>separator: character separating between data cells. Defaults to *separator*
+
+<p>quote: quoting character for text strings. Defaults to *quote*
+
+<p>escape: escape character. Defaults to *quote-escape*
+
+</blockquote>
+
+<!-- End of entry for READ-CSV -->
+
+
+<!-- Entry for READ-CSV-ROW -->
+
+<p><br>[Function]<br><a class=none name='read-csv-row'><b>read-csv-row</b> <i>stream-or-string <tt>&amp;key</tt> (separator *separator*) (quote *quote*) (escape *quote-escape*) <tt>&amp;aux</tt> current state line llen c elen</i> =&gt; <i>result</i></a>
+<blockquote><br>
+
+Read in a CSV by data-row (which due to quoted newlines may be more than one
+ line from the stream)
+
+
+</blockquote>
+
+<!-- End of entry for READ-CSV-ROW -->
+
+
+<!-- Entry for WRITE-CSV -->
+
+<p><br>[Function]<br><a class=none name='write-csv'><b>write-csv</b> <i>rows-of-items <tt>&amp;key</tt> stream (separator *separator*) (quote *quote*) (escape *quote-escape*) (newline *newline*) (always-quote *always-quote*)</i> =&gt; <i>result</i></a>
+<blockquote><br>
+
+<P>Writes a CSV
+
+<p>rows-of-items: iterable
+
+<P>Keywords:
+
+<p>stream: stream to write to. Default: nil.
+
+<p>quote: quoting character. Defaults to *quote*
+
+<p>escape: escaping character. Defaults to *quote-escape*
+
+<p>newline: newline character. Defaults to *newline*
+
+<p>always-quote: Defaults to *always-quote*
+
+</blockquote>
+
+<!-- End of entry for WRITE-CSV -->
+
+
+<!-- Entry for WRITE-CSV-ROW -->
+
+<p><br>[Function]<br><a class=none name='write-csv-row'><b>write-csv-row</b> <i>items <tt>&amp;key</tt> stream (separator *separator*) (quote *quote*) (escape *quote-escape*) (newline *newline*) (always-quote *always-quote*)</i> =&gt; <i>result</i></a>
+<blockquote><br>
+
+<p>Writes a list items to stream
+
+<p>rows-of-items: iterable
+
+<p>Keywords:
+
+<p>stream: stream to write to. Default: nil.
+
+<p>quote: quoting character. Defaults to *quote*
+
+<p>escape: escaping character. Defaults to *quote-escape*
+
+<p>newline: newline character. Defaults to *newline*
+
+<p>always-quote: Defaults to *always-quote*
+
+</blockquote>
+
+<!-- End of entry for WRITE-CSV-ROW -->
+
+
+<!-- Entry for WRITE-CSV-VALUE -->
+
+<p><br>[Generic function]<br><a class=none name='write-csv-value'><b>write-csv-value</b> <i>val csv-stream <tt>&amp;key</tt> formatter quote separator escape always-quote</i> =&gt; <i>result</i></a>
+<blockquote><br>
+
+
+
+</blockquote>
+
+<!-- End of entry for WRITE-CSV-VALUE -->
+
+
+<!-- Entry for WRITE-CSV-VALUE -->
+
+<p><br>[Method]<br><a class=none><b>write-csv-value</b> <i>val csv-stream <tt>&amp;key</tt> formatter quote separator escape always-quote</i> =&gt; <i>result</i></a>
+<blockquote><br>
+
+<p>Writes val to csv-stream in a formatted fashion.
+
+<p>Keywords:
+
+<p>formatter: used to format val. Defaults to format-csv-value.
+
+<p>quote: quoting character. Defaults to *quote*
+
+<p>escape: escaping character. Defaults to *quote-escape*
+
+<p>newline: newline character. Defaults to *newline*
+
+<p>always-quote: Defaults to *always-quote*
+
+</blockquote>
+
+<!-- End of entry for WRITE-CSV-VALUE -->
+
+
+<br>&nbsp;<br><h3><a class=none name="ack">Acknowledgements</a></h3>
+
+<p>
+This documentation was prepared with <a href="http://weitz.de/documentation-template/">DOCUMENTATION-TEMPLATE</a>.
+</p>
+
+</body>
+</html>
View
86 csv.lisp
@@ -19,11 +19,11 @@
;;;; Generating CSV files from lisp data
-(defvar *quote* #\")
-(defvar *separator* #\,)
-(defvar *newline* #?"\r\n")
-(defvar *always-quote* nil)
-(defvar *quote-escape* #?"${ *quote* }${ *quote* }")
+(defvar *quote* #\" "Default quote character")
+(defvar *separator* #\, "Default separator character")
+(defvar *newline* #?"\r\n" "Default newline string")
+(defvar *always-quote* nil "Default setting for always quoting")
+(defvar *quote-escape* #?"${ *quote* }${ *quote* }" "Default setting for escaping quotes")
(defun white-space? (c)
(member c '(#\newline #\tab #\space #\return)))
@@ -71,6 +71,19 @@
(iter (for char in-sequence formatted-value)
(thereis (or (char= quote char)
(char= separator char)))))))
+ "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 *newline
+
+always-quote: Defaults to *always-quote*"
(when should-quote
(write-char quote csv-stream))
(iter
@@ -97,7 +110,22 @@
((:escape *quote-escape*) *quote-escape*)
((:newline *newline*) *newline*)
((:always-quote *always-quote*) *always-quote*))
- "Write the list ITEMS to stream."
+"
+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 *newline
+
+always-quote: Defaults to *always-quote*"
(with-csv-output-stream (csv-stream stream)
(iter (for item in items)
(unless (first-iteration-p)
@@ -115,6 +143,21 @@
((:escape *quote-escape*) *quote-escape*)
((:newline *newline*) *newline*)
((:always-quote *always-quote*) *always-quote*))
+ "Writes a CSV
+
+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 *newline
+
+always-quote: Defaults to *always-quote*"
(with-csv-output-stream (csv-stream stream)
(iter (for row in rows-of-items)
(write-csv-row row :stream csv-stream))
@@ -301,13 +344,25 @@
"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
+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
- "
+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*"
(with-csv-input-stream (in-stream stream-or-string)
(when skip-first-p (read-line in-stream))
@@ -325,6 +380,13 @@
(defmacro 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"
`(read-csv ,stream-or-pathname ,@read-csv-keys
:row-fn #'(lambda (,row-var) ,@body)
)

No commit comments for this range

Something went wrong with that request. Please try again.