Rules for writing CSV files are pretty simple:
value contains separator character or new line character or begins with a quote
– enclose the value in quotes,
value is enclosed in quotes – any quote character contained in the value should
be followed by additional quote character.
These two simple rules enable us to write CSV writers
easily, in just few minutes. Implementing CSV reader is much more problematic
because CSV stream has to be parsed sequentially, character by character and
additional state storage has to be provided – which effectively makes CSV
reader a state machine. There are a lot of CSV readers out there that have
wrong implementation because they do not follow the rules stated above.