Skip to content

Commit

Permalink
Implement sscanf in terms of ksscanf
Browse files Browse the repository at this point in the history
Signed-off-by: Rudi Grinberg <me@rgrinberg.com>
  • Loading branch information
rgrinberg committed Nov 4, 2019
1 parent 5143254 commit afbc1a5
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/stdune/scanf.ml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
module Scanf = Dune_caml.Scanf

let try_ f =
match f () with
| exception End_of_file -> Error ()
let unescaped x =
match Scanf.unescaped x with
| exception Scanf.Scan_failure _ -> Error ()
| exception (Failure _) -> Error ()
| x -> Ok x

let unescaped x = try_ (fun () -> Scanf.unescaped x)

let sscanf x fmt f = try_ (fun () -> Scanf.sscanf x fmt f)
exception E
let sscanf x fmt f =
match Scanf.ksscanf x (fun _ _ -> raise_notrace E) fmt f with
| exception E -> Error ()
| x -> Ok x

0 comments on commit afbc1a5

Please sign in to comment.