digitalmars.D - Row mismatch in CSV
- Jesse Phillips (25/25) Jan 09 2012 I'm adding output to the std.csv module that will be available in
- dennis luehring (4/29) Jan 09 2012 do not allow invalid input - maybe a helper function to detect, but no
- Andrej Mitrovic (3/3) Jan 10 2012 Maybe we could optionally pass a func/delegate to std.csv which gets
- Jesse Phillips (6/11) Jan 10 2012 That isn't going to happen. If for no other reason than it is
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?
Jan 09 2012
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
Jan 09 2012
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?
Jan 10 2012
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.
Jan 10 2012