Revision: 424
Author: ygrekheretix
Date: Tue Nov 12 16:01:16 2013 UTC
Log: add IO.scanf (Closes issue 8)
http://code.google.com/p/ocaml-extlib/source/detail?r=424
Modified:
/trunk/extlib/IO.ml
/trunk/extlib/IO.mli
=======================================
--- /trunk/extlib/IO.ml Tue Nov 12 15:48:23 2013 UTC
+++ /trunk/extlib/IO.ml Tue Nov 12 16:01:16 2013 UTC
@@ -145,6 +145,10 @@
if p + l > sl || p < 0 || l < 0 then invalid_arg "IO.output";
o.out_output s p l
+let scanf i fmt =
+ let ib = Scanf.Scanning.from_function (fun () -> try read i with
No_more_input -> raise End_of_file) in
+ Scanf.kscanf ib (fun _ exn -> raise exn) fmt
+
let printf o fmt =
Printf.kprintf (fun s -> nwrite o s) fmt
=======================================
--- /trunk/extlib/IO.mli Tue Nov 12 15:48:23 2013 UTC
+++ /trunk/extlib/IO.mli Tue Nov 12 16:01:16 2013 UTC
@@ -141,6 +141,9 @@
(** {6 Utilities} *)
+val scanf : input -> ('a, 'b, 'c, 'd) Scanf.scanner
+(** The scanf function works for any input. *)
+
val printf : 'a output -> ('b, unit, string, unit) format4 -> 'b
(** The printf function works for any output. *)