(* csv.ml - comma separated values parser
*
- * $Id: csv.ml,v 1.5 2005-02-17 15:51:47 rich Exp $
+ * $Id: csv.ml,v 1.6 2005-08-13 10:10:31 rich Exp $
*)
(* The format of CSV files:
if c != '\r' then ( (* Always ignore \r characters. *)
match !state with
StartField -> (* Expecting quote or other char. *)
- if c = '\"' then (
+ if c = '"' then (
state := InQuotedField;
field := []
) else if c = separator then (* Empty field. *)
) else
field := c :: !field
| InQuotedField -> (* Reading chars to end of field. *)
- if c = '\"' then
+ if c = '"' then
state := InQuotedFieldAfterQuote
else
field := c :: !field
| InQuotedFieldAfterQuote ->
- if c = '\"' then ( (* Doubled quote. *)
+ if c = '"' then ( (* Doubled quote. *)
field := c :: !field;
state := InQuotedField
) else if c = '0' then ( (* Quote-0 is ASCII NUL. *)
else if c = '\n' then ( (* End of field and end of row. *)
end_of_field ();
end_of_row ()
+ ) else ( (* Bad single quote in field. *)
+ field := c :: '"' :: !field;
+ state := InQuotedField
)
); (* end of match *)
loop ()