From fc6682b1c175fd5e13e1102663d83c25c1e4d270 Mon Sep 17 00:00:00 2001 From: Simon Cruanes Date: Tue, 18 Apr 2017 21:19:37 +0200 Subject: [PATCH] add `CCFormat.{newline,substring}` --- src/core/CCFormat.ml | 5 +++++ src/core/CCFormat.mli | 11 +++++++++++ 2 files changed, 16 insertions(+) diff --git a/src/core/CCFormat.ml b/src/core/CCFormat.ml index da23915e..f82cbebe 100644 --- a/src/core/CCFormat.ml +++ b/src/core/CCFormat.ml @@ -39,6 +39,11 @@ let nativeint fmt n = Format.fprintf fmt "%nd" n let string_quoted fmt s = Format.fprintf fmt "\"%s\"" s let flush = Format.pp_print_flush +let newline = Format.pp_force_newline + +let substring out (s,i,len): unit = + string out (String.sub s i len) + let list ?(sep=return ",@ ") pp fmt l = let rec pp_list l = match l with | x::((_::_) as l) -> diff --git a/src/core/CCFormat.mli b/src/core/CCFormat.mli index 0687d90b..a40e20a2 100644 --- a/src/core/CCFormat.mli +++ b/src/core/CCFormat.mli @@ -23,6 +23,17 @@ val bool : bool printer val float3 : float printer (* 3 digits after . *) val float : float printer +val newline : unit printer +(** Force newline (see {!Format.pp_force_newline}) + @since NEXT_RELEASE *) + +val substring : (string * int * int) printer +(** Print the substring [(s,i,len)], where [i] is the offset + in [s] and [len] the number of bytes in the substring. + @raise Invalid_argument if the triple [(s,i,len)] does not + describe a proper substring. + @since NEXT_RELEASE *) + val char : char printer (** @since 0.14 *) val int32 : int32 printer (** @since 0.14 *) val int64 : int64 printer (** @since 0.14 *)