summaryrefslogtreecommitdiffstats
path: root/stdlib
diff options
context:
space:
mode:
Diffstat (limited to 'stdlib')
-rw-r--r--stdlib/scanf.ml17
-rw-r--r--stdlib/scanf.mli2
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).