Skip to content

Commit

Permalink
Implement support for \' as the CSV separator.
Browse files Browse the repository at this point in the history
The option "fields optionally enclosed by" was missing a way to easily
specify a single quote as the quoting character. Add '\'' to the existing
solution '0x27' which isn't as friendly.

See #705.
  • Loading branch information
dimitri committed Dec 26, 2017
1 parent 07cdf3e commit 81be9ae
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 14 deletions.
Binary file modified docs/_build/doctrees/environment.pickle
Binary file not shown.
Binary file modified docs/_build/doctrees/ref/csv.doctree
Binary file not shown.
14 changes: 10 additions & 4 deletions docs/_build/html/_sources/ref/csv.rst.txt
Expand Up @@ -184,10 +184,16 @@ When loading from a `CSV` file, the following options are supported:

- *fields optionally enclosed by*

Takes a single character as argument, which must be found inside
single quotes, and might be given as the printable character itself,
the special value \t to denote a tabulation character, or `0x` then
an hexadecimal value read as the ASCII code for the character.
Takes a single character as argument, which must be found inside single
quotes, and might be given as the printable character itself, the
special value \t to denote a tabulation character, the special value \'
to denote a single-quote, or `0x` then an hexadecimal value read as the
ASCII code for the character.

The following options specify the same enclosing character, a single quote::

fields optionally enclosed by '\''
fields optionally enclosed by '0x27'

This character is used as the quoting character in the `CSV` file,
and defaults to double-quote.
Expand Down
14 changes: 10 additions & 4 deletions docs/_build/html/ref/csv.html
Expand Up @@ -215,10 +215,16 @@ <h2>CSV Loading Options: WITH<a class="headerlink" href="#csv-loading-options-wi
between the separator and the value.</p>
</li>
<li><p class="first"><em>fields optionally enclosed by</em></p>
<p>Takes a single character as argument, which must be found inside
single quotes, and might be given as the printable character itself,
the special value t to denote a tabulation character, or <cite>0x</cite> then
an hexadecimal value read as the ASCII code for the character.</p>
<p>Takes a single character as argument, which must be found inside single
quotes, and might be given as the printable character itself, the
special value t to denote a tabulation character, the special value ‘
to denote a single-quote, or <cite>0x</cite> then an hexadecimal value read as the
ASCII code for the character.</p>
<p>The following options specify the same enclosing character, a single quote:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">fields</span> <span class="n">optionally</span> <span class="n">enclosed</span> <span class="n">by</span> <span class="s1">&#39;</span><span class="se">\&#39;</span><span class="s1">&#39;</span>
<span class="n">fields</span> <span class="n">optionally</span> <span class="n">enclosed</span> <span class="n">by</span> <span class="s1">&#39;0x27&#39;</span>
</pre></div>
</div>
<p>This character is used as the quoting character in the <cite>CSV</cite> file,
and defaults to double-quote.</p>
</li>
Expand Down
2 changes: 1 addition & 1 deletion docs/_build/html/searchindex.js

Large diffs are not rendered by default.

14 changes: 10 additions & 4 deletions docs/ref/csv.rst
Expand Up @@ -184,10 +184,16 @@ When loading from a `CSV` file, the following options are supported:

- *fields optionally enclosed by*

Takes a single character as argument, which must be found inside
single quotes, and might be given as the printable character itself,
the special value \t to denote a tabulation character, or `0x` then
an hexadecimal value read as the ASCII code for the character.
Takes a single character as argument, which must be found inside single
quotes, and might be given as the printable character itself, the
special value \t to denote a tabulation character, the special value \'
to denote a single-quote, or `0x` then an hexadecimal value read as the
ASCII code for the character.

The following options specify the same enclosing character, a single quote::

fields optionally enclosed by '\''
fields optionally enclosed by '0x27'

This character is used as the quoting character in the `CSV` file,
and defaults to double-quote.
Expand Down
4 changes: 3 additions & 1 deletion src/parsers/command-csv.lisp
Expand Up @@ -36,7 +36,9 @@

(defrule tab (and #\\ #\t) (:constant #\Tab))

(defrule separator (and #\' (or hex-char-code tab character ) #\')
(defrule single-quote (and #\\ #\') (:constant #\'))

(defrule separator (and #\' (or hex-char-code tab single-quote character) #\')
(:lambda (sep)
(bind (((_ char _) sep)) char)))

Expand Down

0 comments on commit 81be9ae

Please sign in to comment.