From 22c205f1d45637533a4ef5ae3c175c16a4368a5c Mon Sep 17 00:00:00 2001 From: Simon Cruanes Date: Tue, 13 Oct 2015 15:07:12 +0200 Subject: [PATCH] add functions in `CCFormat` --- src/core/CCFormat.ml | 11 +++++++++-- src/core/CCFormat.mli | 10 ++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/core/CCFormat.ml b/src/core/CCFormat.ml index f20ae774..419569ce 100644 --- a/src/core/CCFormat.ml +++ b/src/core/CCFormat.ml @@ -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 diff --git a/src/core/CCFormat.mli b/src/core/CCFormat.mli index 818ed3c2..a53185e8 100644 --- a/src/core/CCFormat.mli +++ b/src/core/CCFormat.mli @@ -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 *)