cosmetic changes in Bencode

This commit is contained in:
Simon Cruanes 2013-06-27 16:13:10 +02:00
parent 171f12a322
commit e7e1d1bb6a
2 changed files with 10 additions and 1 deletions

View file

@ -88,7 +88,7 @@ let rec pretty fmt t = match t with
| S s -> Format.fprintf fmt "@[<h>\"%s\"@]" s
| L l ->
Format.fprintf fmt "@[<hov 2>[@,";
List.iter (fun t' -> Format.fprintf fmt "%a@ " pretty t') l;
List.iteri (fun i t' -> (if i > 0 then Format.pp_print_char fmt ' '); pretty fmt t') l;
Format.fprintf fmt "]@]";
| D d ->
Format.fprintf fmt "@[<hov 2>{@,";
@ -96,6 +96,12 @@ let rec pretty fmt t = match t with
(fun k t' -> Format.fprintf fmt "%a -> %a@ " pretty (S k) pretty t')
d;
Format.fprintf fmt "}@]";
()
let pretty_to_str t =
let b = Buffer.create 15 in
Format.fprintf (Format.formatter_of_buffer b) "%a@?" pretty t;
Buffer.contents b
(** {2 Deserialization (decoding)} *)

View file

@ -52,6 +52,9 @@ val fmt : Format.formatter -> t -> unit
val pretty : Format.formatter -> t -> unit
(** Print the tree itself, not its encoding *)
val pretty_to_str : t -> string
(** Print the tree into a string *)
(** {2 Deserialization (decoding)} *)
(** Deserialization is based on the {! decoder} type. Parsing can be