Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>In pseudo-code, given:</p> <ul> <li><p><i>input</i>: A string, first character is <i>input</i>[0]; last character is <i>input</i>[<i>length</i>]. Further, assume one dummy character, <i>input</i>[<i>length</i>+1]. It can be anything except <code>;</code> and <code>"</code>. This string is one line of the "CSV" file.</p></li> <li><p><i>length</i>: positive integer, number of characters in <i>input</i></p></li> </ul> <p>Do this:</p> <ul> <li><p>set <i>start</i> = 0</p></li> <li><p>if <i>input</i>[0] = <code>';'</code>:</p> <ul> <li><p>you have a blank field in the beginning; do whatever with it</p></li> <li><p>set start = 2</p></li> </ul></li> <li><p>endif</p></li> <li><p>for each <i>c</i> between 1 and <i>length</i>:</p> <ul> <li><p>next iteration unless <i>string</i>[<i>c</i>] = <code>';'</code></p></li> <li><p>if input[c-1] ≠ <code>'"'</code> or input[c+1] ≠ <code>'"'</code>: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>// test for escape sequence <code>";"</code></strong></p> <ul> <li><p>found field consting of half-open range [start,c); do whatever with it. Note that in the case of empty fields, start≥c, leaving an empty range</p></li> <li><p>set start = c+1</p></li> </ul></li> <li><p>endif</p></li> </ul></li> <li><p>end foreach</p></li> </ul> <p>Untested, of course. Debugging code like this is always fun….</p> <p>The special case of <i>input</i>[0] is to make sure we don't ever look at <i>input[-1]</i>. If you can make <i>input[-1]</i> safe, then you can get rid of that special case. You can also put a dummy character in <i>input</i>[0] and then start your data—and your parsing—from <i>input</i>[1].</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload