diff --git a/Changes b/Changes index c6d48794e6a1..8117895edd9a 100644 --- a/Changes +++ b/Changes @@ -103,6 +103,9 @@ Working version for formatter geometry changes that are robust to new geometry fields. (Gabriel Scherer, review by Josh Berdine and ???) +- #7110: Added Printf.ikbprintf and Printf.ibprintf + (Muskan Garg, review by Gabriel Scherer and Florian Angeletti) + ### Other libraries: - #9106: Register printer for Unix_error in win32unix, as in unix. diff --git a/stdlib/printf.ml b/stdlib/printf.ml index 814e82d1961d..b15eb05b9172 100644 --- a/stdlib/printf.ml +++ b/stdlib/printf.ml @@ -22,10 +22,13 @@ let kbprintf k b (Format (fmt, _)) = make_printf (fun acc -> bufput_acc b acc; k b) End_of_acc fmt let ikfprintf k oc (Format (fmt, _)) = make_iprintf k oc fmt +let ikbprintf k bc (Format (fmt, _)) = + make_iprintf k bc fmt let fprintf oc fmt = kfprintf ignore oc fmt let bprintf b fmt = kbprintf ignore b fmt let ifprintf oc fmt = ikfprintf ignore oc fmt +let ibprintf b fmt = ikbprintf ignore b fmt let printf fmt = fprintf stdout fmt let eprintf fmt = fprintf stderr fmt diff --git a/stdlib/printf.mli b/stdlib/printf.mli index 8ecb819e9a64..29bc6851b9bd 100644 --- a/stdlib/printf.mli +++ b/stdlib/printf.mli @@ -147,6 +147,12 @@ val ifprintf : 'b -> ('a, 'b, 'c, unit) format4 -> 'a @since 3.10.0 *) +val ibprintf : Buffer.t -> ('a, Buffer.t, 'c, unit) format4 -> 'a +(** Same as {!Printf.bprintf}, but does not print anything. + Useful to ignore some material when conditionally printing. + @since 4.11.0 +*) + (** Formatted output functions with continuations. *) val kfprintf : (out_channel -> 'd) -> out_channel -> @@ -175,6 +181,12 @@ val kbprintf : (Buffer.t -> 'd) -> Buffer.t -> @since 3.10.0 *) +val ikbprintf : (Buffer.t -> 'd) -> Buffer.t -> ('a, Buffer.t, 'c, 'd) format4 -> 'a +(** Same as [kbprintf] above, but does not print anything. + Useful to ignore some material when conditionally printing. + @since 4.11.0 +*) + (** Deprecated *) val kprintf : (string -> 'b) -> ('a, unit, string, 'b) format4 -> 'a