···442442 w (String.concat "," (Array.to_list fields));
443443 w "\n")
444444 rows
445445+446446+module Private = struct
447447+ type nonrec header = header
448448+ type nonrec 'a resolved = 'a resolved
449449+450450+ let resolve = resolve
451451+ let decode_row = decode_row
452452+ let decode_field = decode_field
453453+ let encode_field = encode_field
454454+ let encode_header = encode_header
455455+ let encode_row = encode_row
456456+end
+33-33
lib/csvt.mli
···8181 dec:(string -> ('a, string) result) -> enc:('a -> string) -> unit -> 'a t
8282(** [col_map ~dec ~enc ()] creates a custom field codec. *)
83838484-(** {1:decode Decode and Encode} *)
8585-8686-val decode_field : 'a t -> string -> ('a, string) result
8787-(** [decode_field t s] decodes string [s] using CSV type [t]. *)
8888-8989-val encode_field : 'a t -> 'a -> string
9090-(** [encode_field t v] encodes value [v] to a string using CSV type [t]. *)
9191-9284(** {1:introspect Introspection} *)
93859486val col_names : 'a t -> string list
···140132 (** [finish m] completes the row codec. *)
141133end
142134143143-(** {1:header Header Resolution} *)
144144-145145-type header = string array
146146-(** A CSV header: array of column names. *)
147147-148148-type 'a resolved
149149-(** A codec resolved against a specific header. Column name lookups are
150150- performed once, giving O(1) per-row decoding. *)
151151-152152-val resolve : 'a t -> header -> ('a resolved, error) result
153153-(** [resolve t header] resolves column names to indices. *)
154154-155155-val decode_row : 'a resolved -> int -> string array -> ('a, error) result
156156-(** [decode_row resolved row_num fields] decodes a single CSV row. *)
157157-158135(** {1:update Update} *)
159136160137val update_col :
161138 string ->
162139 'a t ->
163140 ('a -> 'a) ->
164164- header ->
141141+ string array ->
165142 string array ->
166143 (string array, error) result
167144(** [update_col name codec f header row] decodes column [name] from [row] using
168145 [codec], applies [f] to the typed value, re-encodes, and returns the updated
169146 row. Other columns are unchanged. *)
170147171171-val delete_col : string -> header -> string array -> header * string array
148148+val delete_col :
149149+ string -> string array -> string array -> string array * string array
172150(** [delete_col name header row] removes the column [name] from both the header
173151 and the row. Returns the new header and row. If [name] is not found, returns
174152 both unchanged. *)
175153176176-(** {1:encode Encoding} *)
177177-178178-val encode_header : 'a t -> header
179179-(** [encode_header t] returns the CSV header for encoding. *)
180180-181181-val encode_row : 'a t -> 'a -> string array
182182-(** [encode_row t v] encodes a value as a CSV row. *)
183183-184154(** {1:file File Operations} *)
185155186156val decode_channel : 'a t -> in_channel -> ('a list, error) result
···206176207177val encode : 'a t -> 'a list -> Bytesrw.Bytes.Writer.t -> unit
208178(** [encode t rows w] encodes [rows] as CSV and writes them to writer [w]. *)
179179+180180+(** {1:private_ Private}
181181+182182+ {b For internal use by sibling libraries only.} These functions operate on
183183+ raw string arrays and are not part of the public codec API. *)
184184+module Private : sig
185185+ type header = string array
186186+ (** A CSV header: array of column names. *)
187187+188188+ type 'a resolved
189189+ (** A codec resolved against a specific header. *)
190190+191191+ val resolve : 'a t -> header -> ('a resolved, error) result
192192+ (** [resolve t header] resolves column names to indices. *)
193193+194194+ val decode_row : 'a resolved -> int -> string array -> ('a, error) result
195195+ (** [decode_row resolved row_num fields] decodes a single CSV row. *)
196196+197197+ val decode_field : 'a t -> string -> ('a, string) result
198198+ (** [decode_field t s] decodes string [s] using CSV type [t]. *)
199199+200200+ val encode_field : 'a t -> 'a -> string
201201+ (** [encode_field t v] encodes value [v] to a string using CSV type [t]. *)
202202+203203+ val encode_header : 'a t -> header
204204+ (** [encode_header t] returns the CSV header for encoding. *)
205205+206206+ val encode_row : 'a t -> 'a -> string array
207207+ (** [encode_row t v] encodes a value as a CSV row. *)
208208+end