summaryrefslogtreecommitdiff
path: root/lib/common/format.ml
diff options
context:
space:
mode:
Diffstat (limited to 'lib/common/format.ml')
-rw-r--r--lib/common/format.ml10
1 files changed, 10 insertions, 0 deletions
diff --git a/lib/common/format.ml b/lib/common/format.ml
new file mode 100644
index 0000000..5245dd0
--- /dev/null
+++ b/lib/common/format.ml
@@ -0,0 +1,10 @@
+(** [format_string f] call the function [f] with a fresh formatter and return
+ the content as a string *)
+let format_string : (Stdlib.Format.formatter -> unit) -> string =
+ fun f ->
+ let buff = Buffer.create 16 in
+ let format = Stdlib.Format.formatter_of_buffer buff in
+ let () = f format in
+
+ Stdlib.Format.pp_print_flush format ();
+ Buffer.contents buff