printing functions

This commit is contained in:
Simon Cruanes 2013-11-18 15:17:22 +01:00
parent 61a4f64e75
commit b1e5176177
2 changed files with 20 additions and 0 deletions

View file

@ -713,3 +713,16 @@ let pp_seq ?(sep=", ") pp_elt formatter seq =
end);
pp_elt formatter x)
seq
let pp_buf ?(sep=", ") pp_elt buf seq =
let first = ref true in
iter
(fun x ->
if !first then first := false else Buffer.add_string buf sep;
pp_elt buf x)
seq
let to_string ?sep pp_elt seq =
let buf = Buffer.create 25 in
pp_buf ?sep (fun buf x -> Buffer.add_string buf (pp_elt x)) buf seq;
Buffer.contents buf

View file

@ -442,3 +442,10 @@ val pp_seq : ?sep:string -> (Format.formatter -> 'a -> unit) ->
Format.formatter -> 'a t -> unit
(** Pretty print a sequence of ['a], using the given pretty printer
to print each elements. An optional separator string can be provided. *)
val pp_buf : ?sep:string -> (Buffer.t -> 'a -> unit) ->
Buffer.t -> 'a t -> unit
(** Print into a buffer *)
val to_string : ?sep:string -> ('a -> string) -> 'a t -> string
(** Print into a string *)