From: rich Date: Fri, 24 Nov 2006 13:58:56 +0000 (+0000) Subject: Throw an error if the named column requested does not actually exist. X-Git-Url: http://git.annexia.org/?a=commitdiff_plain;h=1c81f6fe58496d4c6ed4088e11b075af66f90931;p=ocaml-csv.git Throw an error if the named column requested does not actually exist. --- diff --git a/Makefile.config b/Makefile.config index a3f90cc..e892686 100644 --- a/Makefile.config +++ b/Makefile.config @@ -1,4 +1,4 @@ -# $Id: Makefile.config,v 1.1 2006-11-24 09:43:15 rich Exp $ +# $Id: Makefile.config,v 1.2 2006-11-24 13:58:56 rich Exp $ PACKAGE := ocaml-csv -VERSION := 1.1.3 +VERSION := 1.1.4 diff --git a/csvtool.ml b/csvtool.ml index edfaedd..a046956 100644 --- a/csvtool.ml +++ b/csvtool.ml @@ -1,5 +1,5 @@ (* Handy tool for managing CSV files. - * $Id: csvtool.ml,v 1.6 2006-11-24 10:09:56 rich Exp $ + * $Id: csvtool.ml,v 1.7 2006-11-24 13:58:56 rich Exp $ *) open Printf @@ -153,6 +153,14 @@ let cmd_namedcols ~input_sep ~output_sep ~chan names files = match csv with | [] -> failwith "no rows in this CSV file" | h :: t -> h, t in + (* Do the headers requested exist in the CSV file? If not, + * throw an error. + *) + List.iter ( + fun name -> + if not (List.mem name header) then + failwith ("namedcol: requested header not in CSV file: " ^ name) + ) names; let data = associate header data in let data = List.map ( fun row -> List.map (fun name -> List.assoc name row) names