davidsantiago / clojure-csv

A library for reading and writing CSV files from Clojure
187 stars 35 forks source link

return-only files #13

Closed naylor127 closed 12 years ago

naylor127 commented 12 years ago

I was trying to parse a CSV file exported by Mac Excel 2011; it seems to be terminated only by the Return character, with no Newline. Would there be any way of making clojure-csv configurable for different end-of-line sequences? I guess this is not standard CSV, but if Excel is making it it must be a pretty common use-case.

davidsantiago commented 12 years ago

Wow, why would they... what in the...?

I don't even know what to make of this. This is so far from any other CSV perversion I've ever seen before, and as far as I can tell, only Mac Excel does this, as if they don't understand the line terminator that the Mac has used for all of time.

It would be fairly easy to add support for this, but this is the first thing I've seen where I've wanted not to, just to fight against it. Let me think about it a little more.

David

davidsantiago commented 12 years ago

Apparently CR-only was the line terminator on old-enough versions of Mac OS Classic. Kind of weird that Mac Excel 2011 is outputting it that way for Mac support, but I guess there is a chance there is some real use for it.

The problem is, the CSV spec specifies only LF or CR+LF line terminators, so technically, a stand-alone CR should be a valid field entry in a CSV that follows the standard, in my understanding. We could maybe add this support with some enable-ancient-mac-line-terminator option.

David

naylor127 commented 12 years ago

Maybe you could do that, or maybe you could just let the user specify end-of-line with the understanding (from a comment?) that this might break CSV files. Or maybe you could do a combination: enable-mac-excel, or enable-nonstandard-mode plus end-of-line=x. That would keep the user informed and discourage a habit of breaking CSV.

It does sound pretty crazy: a combination of Microsoft being Microsoft, and Mac being Mac. And I don't see any options in Save for "make compliant CSV", though maybe it's there in hiding.

davidsantiago commented 12 years ago

Hey, sorry it took me so long to get around to this. It required some bigger changes to the code, especially since I was already kind of midstream in a big rewrite, but I've released an alpha version as 2.0.0-alpha1. If you're still interested, have a look.

David

naylor127 commented 12 years ago

David,

No hurry at all! I was just playing around with it and thought you should be aware of the problem, glad you managed to fix it!