Allow '-' to mean read from stdin.
[ocaml-csv.git] / csv.ml
diff --git a/csv.ml b/csv.ml
index ee0623e..0b6e649 100644 (file)
--- a/csv.ml
+++ b/csv.ml
@@ -1,6 +1,6 @@
 (* csv.ml - comma separated values parser
  *
- * $Id: csv.ml,v 1.13 2006-11-24 09:43:15 rich Exp $
+ * $Id: csv.ml,v 1.14 2006-11-24 15:49:24 rich Exp $
  *)
 
 (* The format of CSV files:
@@ -178,10 +178,13 @@ let load_in ?separator chan =
   List.rev !csv
 
 let load ?separator filename =
-  let chan = open_in filename in
+  let chan, close =
+    match filename with
+    | "-" -> stdin, false
+    | filename -> open_in filename, true in
   let csv = load_in ?separator chan in
-  close_in chan;
-  csv 
+  if close then close_in chan;
+  csv
 
 let trim ?(top=true) ?(left=true) ?(right=true) ?(bottom=true) csv =
   let rec empty_row = function