git.annexia.org
/
ocaml-csv.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
602afc4
)
Fix to handle the crappy not-quite-CSV files sent by Nedstat.
author
rich
<rich>
Sat, 13 Aug 2005 10:10:31 +0000
(10:10 +0000)
committer
rich
<rich>
Sat, 13 Aug 2005 10:10:31 +0000
(10:10 +0000)
csv.ml
patch
|
blob
|
history
diff --git
a/csv.ml
b/csv.ml
index
a5207e7
..
1c0ae62
100644
(file)
--- a/
csv.ml
+++ b/
csv.ml
@@
-1,6
+1,6
@@
(* csv.ml - comma separated values parser
*
(* 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:
*)
(* The format of CSV files:
@@
-94,7
+94,7
@@
let load_rows ?(separator = ',') f chan =
if c != '\r' then ( (* Always ignore \r characters. *)
match !state with
StartField -> (* Expecting quote or other char. *)
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. *)
state := InQuotedField;
field := []
) else if c = separator then (* Empty field. *)
@@
-115,12
+115,12
@@
let load_rows ?(separator = ',') f chan =
) else
field := c :: !field
| InQuotedField -> (* Reading chars to end of 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 ->
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. *)
field := c :: !field;
state := InQuotedField
) else if c = '0' then ( (* Quote-0 is ASCII NUL. *)
@@
-131,6
+131,9
@@
let load_rows ?(separator = ',') f chan =
else if c = '\n' then ( (* End of field and end of row. *)
end_of_field ();
end_of_row ()
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 ()
)
); (* end of match *)
loop ()