> On 29 Jun 2016, at 09:45, Joachim Tuchel <[email protected]> wrote:
>
> Ben,
>
> > Ben Coman <[email protected]> hat am 29. Juni 2016 um 09:40 geschrieben:
> > Your questions are significant. The standard library should not be
> > complicated by trying to handle undefined missing fields from a row.
> > Such a file is simply invalid.
> > cheers -ben
>
> I fully agree, I just wanted to give an example of questions that are way
> more difficult to answer than it might seem in the first place. I wanted to
> make an argument for not blaming NeoCSV for being unable to parse a file like
> that. I am surely not asking for NeoCSV to do some magic on invalid CSV
> files. It would be wrong in at least 50% of the cases anyways, no matter what
> kind of assumptions it would make.
>
> Joachim
So yes, CSV is only defined for records that are all the same size.
NeoCSVReader can however deal with shorter records. The first record (or
header, or convertors) define the number of fields for the whole file.
Obviously, only empty fields at the end are supported.
Here is an example:
(NeoCSVReader on: '1,2,3\5\3,2,1' withCRs readStream) emptyFieldValue: #empty;
upToEnd.
=> #(#('1' '2' '3') #('5' #empty #empty) #('3' '2' '1'))
The second line/record contains only one value, empty ones are added
automatically. The #emptyFieldValue is optional and defaults to nil.
Sven