add functions in CCFormat

This commit is contained in:
Simon Cruanes 2015-10-13 15:07:12 +02:00
parent 6e99f1c8e8
commit 22c205f1d4
2 changed files with 19 additions and 2 deletions

View file

@ -37,11 +37,16 @@ let silent _fmt _ = ()
let unit fmt () = Format.pp_print_string fmt "()"
let int fmt i = Format.pp_print_string fmt (string_of_int i)
let string fmt s = Format.pp_print_string fmt s
let bool fmt b = Format.fprintf fmt "%B" b
let string = Format.pp_print_string
let bool = Format.pp_print_bool
let float3 fmt f = Format.fprintf fmt "%.3f" f
let float fmt f = Format.pp_print_string fmt (string_of_float f)
let char = Format.pp_print_char
let int32 fmt n = Format.fprintf fmt "%ld" n
let int64 fmt n = Format.fprintf fmt "%Ld" n
let nativeint fmt n = Format.fprintf fmt "%nd" n
let list ?(start="[") ?(stop="]") ?(sep=", ") pp fmt l =
let rec pp_list l = match l with
| x::((_::_) as l) ->
@ -125,6 +130,8 @@ let sprintf format =
fmt
format
let fprintf = Format.fprintf
let stdout = Format.std_formatter
let stderr = Format.err_formatter

View file

@ -44,6 +44,12 @@ val bool : bool printer
val float3 : float printer (* 3 digits after . *)
val float : float printer
val char : char printer (** @since NEXT_RELEASE *)
val int32 : int32 printer (** @since NEXT_RELEASE *)
val int64 : int64 printer (** @since NEXT_RELEASE *)
val nativeint : nativeint printer (** @since NEXT_RELEASE *)
val list : ?start:string -> ?stop:string -> ?sep:string -> 'a printer -> 'a list printer
val array : ?start:string -> ?stop:string -> ?sep:string -> 'a printer -> 'a array printer
val arrayi : ?start:string -> ?stop:string -> ?sep:string ->
@ -69,5 +75,9 @@ val stderr : t
val sprintf : ('a, t, unit, string) format4 -> 'a
(** print into a string *)
val fprintf : t -> ('a, t, unit ) format -> 'a
(** Alias to {!Format.fprintf}
@since NEXT_RELEASE *)
val to_file : string -> ('a, t, unit, unit) format4 -> 'a
(** Print to the given file *)