3 ms·
I've written CSV exports in C from scratch, no external dependencies required. It's "Comma Separated Variables", it doesn't really need anymore specification t
by johnea 3y ago
I've written CSV exports in C from scratch, no external dependencies required.
It's "Comma Separated Variables", it doesn't really need anymore specification than that.
These files have always imported into M$ and libre office suites without issue.
- nradov 3y agoIt needs more specification than that. Have you read RFC 4180?
- nmz 3y agooh boy. here's where it breaks - supporting "" (single) - Supporting newlines in "", oops, now you can't getline() and instead need to getdelim() - Supporting comments # (why is this even a thing) - Supporting multiple "" in a field - Escaping " with "" or \" - length based csv, so all fields are seekable. It's a mess, which one's your csv?
- outop 3y agoThe vast majority of CSVs do not have strings which include either quotes or newlines. No CSV I have ever encountered has comments.
- eviks 3y agoSo you're fine with a lot of bugs in the case of a vast minority?
- outop 3y agoWell, most code that loads CSVs is intended to work with certain files from certain sources, and not with all the CSVs that have ever existed. So yes, I am happy with code that works for a subset of files. There are thousands of applications which work with CSVs and they all do exactly this.
- nmz 3y agoGoogle contacts does.
- outop 3y agoIt seems that Google generally try and find ways of making exporting their data to use in other services as painful as possible.
- nmz 3y agoYou need newlines in fields, because contacts has addresses, and addresses have newlines. (And also Notes, but that's not as important) (Oh and I forgot about headers, headers should be mandatory but people are aloof about it)
- msla 3y agoComma Separated Values. Normally, I wouldn't nitpick (hold for laughter) but this is just a perfect example of how CSV is not CSV and how it's probably impossible to support everything people call CSV, simply because of the tiny (or not so tiny) differences between formats.