diff options
author | Pierre Weis <Pierre.Weis@inria.fr> | 2003-07-14 10:04:25 +0000 |
---|---|---|
committer | Pierre Weis <Pierre.Weis@inria.fr> | 2003-07-14 10:04:25 +0000 |
commit | 9cad9931a181f3c422785254bf492a3f8e62d963 (patch) | |
tree | dce549273ec55d1e8b7f67d7a1866716a66f847d /stdlib | |
parent | edfdb0e6337229b6035d58aa373b7a8d6236fea8 (diff) |
Suite au PR#1745 %F lit un flottant au format token Caml.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@5685 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
Diffstat (limited to 'stdlib')
-rw-r--r-- | stdlib/scanf.ml | 17 | ||||
-rw-r--r-- | stdlib/scanf.mli | 2 |
2 files changed, 18 insertions, 1 deletions
diff --git a/stdlib/scanf.ml b/stdlib/scanf.ml index 7230075c6..78b2f15f5 100644 --- a/stdlib/scanf.ml +++ b/stdlib/scanf.ml @@ -403,6 +403,18 @@ let scan_float max ib = scan_exp_part max ib | c -> scan_exp_part max ib;; +let scan_Float max ib = + let bad_float () = bad_input "no dot found in float" in + let max = scan_optionally_signed_decimal_int max ib in + if max = 0 || Scanning.eof ib then bad_float () else + let c = Scanning.peek_char ib in + match c with + | '.' -> + let max = Scanning.store_char ib c max in + let max = scan_frac_part max ib in + scan_exp_part max ib + | c -> bad_float ();; + (* Scan a regular string: it stops with a space or one of the characters in stp. It also stops when the maximum number of characters has been read.*) @@ -671,9 +683,12 @@ let kscanf ib ef fmt f = | 'd' | 'i' | 'o' | 'u' | 'x' | 'X' as conv -> let x = scan_int conv max ib in scan_fmt (stack f (token_int conv ib)) (i + 1) - | 'f' | 'g' | 'G' | 'e' | 'E' | 'F' -> + | 'f' | 'g' | 'G' | 'e' | 'E' -> let x = scan_float max ib in scan_fmt (stack f (token_float ib)) (i + 1) + | 'F' -> + let x = scan_Float max ib in + scan_fmt (stack f (token_float ib)) (i + 1) | 's' -> let i, stp = scan_fmt_stoppers (i + 1) in let x = scan_string stp max ib in diff --git a/stdlib/scanf.mli b/stdlib/scanf.mli index 3b9c1da41..fe1d99ba7 100644 --- a/stdlib/scanf.mli +++ b/stdlib/scanf.mli @@ -125,6 +125,8 @@ val bscanf : - [f], [e], [E], [g], [G], [F]: reads an optionally signed floating-point number in decimal notation, in the style [dddd.ddd e/E+-dd]. + - [F]: reads a floating point number according to the lexical + conventions of Caml (hence the decimal point is mandatory). - [B]: reads a boolean argument ([true] or [false]). - [b]: reads a boolean argument (for backward compatibility; do not use in new programs). |