M
Martin Gregorie
Mine is a clone of a C version I'd written first. I have a configurableThere are many implementation out there. You don't have to roll your own
unless you find writing finite state automata and parsers fun.
My own has configurable magic letters for comment intro, separator,
quote char and a few other variations.
separator, choice of every field quoted or 'lazy quoting (only fields
containing the separator or the quote mark get quoted). The quote char
isn't configurable. I use '"', but gets duplicated if its inside a
field. I don't allow newlines inside a field.
The main objective was to be compatible with most RDBMs and spreadsheets
and to have each function/method execute a single action. I've never
personally seen newlines in fields consumed or produced by either, so I
disallowed them.
The line must be read with Getline() before the it is parsed, so spotting
comment lines, etc is trivial. Fields can be ignored or read out of
sequence: parsing a line and extracting field values are separate
operations.
Needless to say, both library and class can read and write CSV files.