| Thread overview | ||||||
|---|---|---|---|---|---|---|
|
January 10, 2012 Row mismatch in CSV | ||||
|---|---|---|---|---|
| ||||
I'm adding output to the std.csv module that will be available in the next release and I'm hoping I can get an opinion on this. The last stated rule for CSV is: Each record should contain the same number of fields (not enforced) I didn't enforce this as I don't see it likely to be indicating an error. But I have found that not following this and parsing with a struct will cause incorrect results. one,two three four Will parse as one,two three,two four,two So I can easily fix this by setting my internal struct with .init. I like this. A goal I am going for with csvWriter is, what goes in comes out. But in this case your output would be one,two three, four, Which I like as it is correct, but it isn't the original input. So the only why to achieve these goals together is to not allow the initial invalid input... Thoughts? | ||||
January 10, 2012 Re: Row mismatch in CSV | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Jesse Phillips | Am 10.01.2012 06:08, schrieb Jesse Phillips:
> I'm adding output to the std.csv module that will be available in
> the next release and I'm hoping I can get an opinion on this.
>
> The last stated rule for CSV is:
>
> Each record should contain the same number of fields (not
> enforced)
>
> I didn't enforce this as I don't see it likely to be indicating
> an error. But I have found that not following this and parsing
> with a struct will cause incorrect results.
>
> one,two
> three
> four
>
> Will parse as
>
> one,two
> three,two
> four,two
>
> So I can easily fix this by setting my internal struct with
> .init. I like this.
>
> A goal I am going for with csvWriter is, what goes in comes out.
> But in this case your output would be
>
> one,two
> three,
> four,
>
> Which I like as it is correct, but it isn't the original input.
> So the only why to achieve these goals together is to not allow
> the initial invalid input... Thoughts?
do not allow invalid input - maybe a helper function to detect, but no
silent "repair" or internal "allow-invalid" stuff - i would get harder to get the lib right
| |||
January 10, 2012 Re: Row mismatch in CSV | ||||
|---|---|---|---|---|
| ||||
Posted in reply to dennis luehring | Maybe we could optionally pass a func/delegate to std.csv which gets invoked on these mismatches and figures out what to do? If no delegate was passed then std.csv would just throw by default? | |||
January 10, 2012 Re: Row mismatch in CSV | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Andrej Mitrovic | On Tuesday, 10 January 2012 at 15:05:22 UTC, Andrej Mitrovic wrote:
> Maybe we could optionally pass a func/delegate to std.csv which gets
> invoked on these mismatches and figures out what to do? If no delegate
> was passed then std.csv would just throw by default?
That isn't going to happen. If for no other reason than it is limited in scope. I think the best course for someone parsing invalid CSV is to either turn off exceptions, or write their own parser with csvNextToken.
| |||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply