add more printers

This commit is contained in:
Simon Cruanes 2015-08-12 00:10:27 +02:00
parent b3a527055f
commit a8c8561a83
8 changed files with 64 additions and 0 deletions

View file

@ -179,6 +179,7 @@ let blit_of_string a i b j len =
type 'a gen = unit -> 'a option
type 'a sequence = ('a -> unit) -> unit
type 'a printer = Format.formatter -> 'a -> unit
let to_seq a k = iter k a
@ -203,6 +204,17 @@ let to_seq_slice a i len =
let to_gen_slice a i len =
to_gen (sub a i len)
let print out s =
Format.pp_print_string out "bigstring \"";
iter
(function
| '\n' -> Format.pp_print_string out "\\n"
| '\t' -> Format.pp_print_string out "\\t"
| '\\' -> Format.pp_print_string out "\\\\"
| c -> Format.pp_print_char out c
) s;
Format.pp_print_char out '"'
(** {2 Memory-map} *)
let map_file_descr ?pos ?(shared=false) fd len =

View file

@ -99,6 +99,7 @@ val blit_of_string : string -> int -> t -> int -> int -> unit
type 'a gen = unit -> 'a option
type 'a sequence = ('a -> unit) -> unit
type 'a printer = Format.formatter -> 'a -> unit
val to_seq : t -> char sequence
@ -108,6 +109,9 @@ val to_seq_slice : t -> int -> int -> char sequence
val to_gen_slice : t -> int -> int -> char gen
val print : t printer
(** @since NEXT_RELEASE *)
(** {2 Memory-map} *)
val with_map_file :

View file

@ -28,6 +28,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
type 'a sequence = ('a -> unit) -> unit
type 'a klist = unit -> [`Nil | `Cons of 'a * 'a klist]
type 'a equal = 'a -> 'a -> bool
type 'a printer = Format.formatter -> 'a -> unit
(** {2 Basics} *)
@ -465,3 +466,13 @@ let (--) a b =
0 -- 0 |> to_list = [0]
*)
let print pp_x out d =
let first = ref true in
Format.fprintf out "@[<hov2>queue {";
iter
(fun x ->
if !first then first:= false else Format.fprintf out ";@ ";
pp_x out x
) d;
Format.fprintf out "}@]"

View file

@ -28,6 +28,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
type 'a sequence = ('a -> unit) -> unit
type 'a klist = unit -> [`Nil | `Cons of 'a * 'a klist]
type 'a equal = 'a -> 'a -> bool
type 'a printer = Format.formatter -> 'a -> unit
(** {2 Basics} *)
@ -148,3 +149,5 @@ val (--) : int -> int -> int t
(** [a -- b] is the integer range from [a] to [b], both included.
@since 0.10 *)
val print : 'a printer -> 'a t printer
(** @since NEXT_RELEASE *)

View file

@ -274,3 +274,17 @@ let rec as_tree t () = match t with
| L (k, v) -> `Node (`Leaf (k, v), [])
| N (prefix, switch, l, r) ->
`Node (`Node (prefix, switch), [as_tree l; as_tree r])
type 'a printer = Format.formatter -> 'a -> unit
let print pp_x out m =
Format.fprintf out "@[<hov2>intmap {@,";
let first = ref true in
iter
(fun k v ->
if !first then first := false else Format.pp_print_string out ", ";
Format.fprintf out "%d -> " k;
pp_x out v;
Format.pp_print_cut out ()
) m;
Format.fprintf out "}@]"

View file

@ -94,3 +94,9 @@ val highest_bit : int -> int
type 'a tree = unit -> [`Nil | `Node of 'a * 'a tree list]
val as_tree : 'a t -> [`Node of int * int | `Leaf of int * 'a ] tree
type 'a printer = Format.formatter -> 'a -> unit
val print : 'a printer -> 'a t printer
(** @since NEXT_RELEASE *)

View file

@ -89,4 +89,14 @@ let of_seq seq =
seq (fun x -> l := x :: !l);
of_list (List.rev !l)
type 'a printer = Format.formatter -> 'a -> unit
let print pp_item out v =
Format.fprintf out "[|";
iteri
(fun i x ->
if i > 0 then Format.fprintf out ";@ ";
pp_item out x
) v;
Format.fprintf out "|]"

View file

@ -102,4 +102,8 @@ val to_seq : 'a t -> 'a sequence
val of_seq : 'a sequence -> 'a t
type 'a printer = Format.formatter -> 'a -> unit
val print : 'a printer -> 'a t printer
(** @since NEXT_RELEASE *)