Implement support for \' as the CSV separator.

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.
This commit is contained in:
Dimitri Fontaine 2017-12-26 21:04:06 +01:00
parent 07cdf3e7e5
commit 81be9ae60e
7 changed files with 34 additions and 14 deletions

Binary file not shown.

Binary file not shown.

View File

@ -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.

View File

@ -215,10 +215,16 @@ default.</p>
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>

File diff suppressed because one or more lines are too long

View File

@ -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.

View File

@ -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)))