Format.kprintf

git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@4553 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
master
Damien Doligez 2002-03-21 17:13:02 +00:00
parent e5540bf196
commit 424fd989f5
2 changed files with 8 additions and 2 deletions

View File

@ -1065,10 +1065,12 @@ let string_out b ppf () =
let fprintf ppf = fprintf_out false unit_out ppf;;
let printf f = fprintf_out false unit_out std_formatter f;;
let eprintf f = fprintf_out false unit_out err_formatter f;;
let sprintf f =
let kprintf k f =
let b = Buffer.create 512 in
let ppf = formatter_of_buffer b in
fprintf_out true (string_out b ppf) ppf f;;
fprintf_out true (fun () -> k (string_out b ppf ())) ppf f
;;
let sprintf f = kprintf (fun x -> x) f;;
let bprintf b =
let ppf = formatter_of_buffer b in

View File

@ -593,3 +593,7 @@ val bprintf : Buffer.t -> ('a, formatter, unit) format -> 'a;;
[fprintf] with a formatter writing to the buffer [b] (as obtained
by [formatter_of_buffer b]), otherwise the repeated flushes of the
pretty-printer queue would result in badly formatted output. *)
val kprintf : (string -> string) -> ('a, unit, string) format -> 'a;;
(** Same as [sprintf] above, but instead of returning the string,
pass it to the first argument. *)