dacb3dca235ce7db859ca31f56b5da2bfeef7c03
[ocaml-csv.git] / csv.mli
1 (** csv.mli - comma separated values parser
2   *
3   * $Id: csv.mli,v 1.2 2004-12-06 17:40:50 rich Exp $
4   *)
5
6 type t = string list list
7 (** Representation of CSV files. *)
8
9 exception Bad_CSV_file of string
10 (** Badly formed CSV files throw this exception: *)
11
12 val lines : t -> int
13 (** Work out the number of lines in a CSV file. *)
14
15 val columns : t -> int
16 (** Work out the (maximum) number of columns in a CSV file. Note that each
17   * line may be a different length, so this finds the one with the most
18   * columns.
19   *)
20
21 val load_in : in_channel -> t
22 (** Load a CSV file.
23   * @param chan Input file stream
24   *)
25
26 val load : string -> t
27 (** Load a CSV file.
28   * @param filename CSV filename.
29   *)
30
31 val load_rows : (string list -> unit) -> in_channel -> unit
32 (** For very large CSV files which cannot be processed in memory at once,
33   * this function is appropriate. It parses the input one row at a time and
34   * calls your function once for each row.
35   *
36   * Note that if you CSV file contains cells which have embedded
37   * line feeds, then it is non-trivial to parse these lines and
38   * pass them correctly to [load_rows].
39   *
40   * @param f Callout function.
41   * @param chan Input file stream.
42   *)
43
44 val trim : ?top:bool -> ?left:bool -> ?right:bool -> ?bottom:bool -> t -> t
45 (** This takes a CSV file and trims empty cells.
46   *
47   * All four of the option arguments ([~top], [~left], [~right], [~bottom])
48   * default to [true].
49   *
50   * The exact behaviour is:
51   *
52   * [~right]: If true, remove any empty cells at the right hand end of
53   * any row.  The number of columns in the resulting CSV structure will
54   * not necessarily be the same for each row.
55   *
56   * [~top]: If true, remove any empty rows (no cells, or containing just empty
57   * cells) from the top of the CSV structure.
58   *
59   * [~bottom]: If true, remove any empty rows from the bottom of the
60   * CSV structure.
61   *
62   * [~left]: If true, remove any empty columns from the left of the
63   * CSV structure.  Note that [~left] and [~right] are quite different:
64   * [~left] considers the whole CSV structure, whereas [~right] considers
65   * each row in isolation.
66   *)
67
68 val print : t -> unit
69 (** Print string list list - same as [save_out stdout] *)
70
71 val save_out : out_channel -> t -> unit
72 (** Save string list list to a channel. *)
73
74 val save : string -> t -> unit
75 (** Save string list list to a file. *)