diff --git a/stdlib/scanf.ml b/stdlib/scanf.ml index ba98e27ec..78adcc706 100644 --- a/stdlib/scanf.ml +++ b/stdlib/scanf.ml @@ -265,8 +265,9 @@ let check_char_in range ib = (* Checking that [c] is indeed in the input, then skip it. *) let check_char ib c = let ci = Scanning.checked_peek_char ib in - if ci == c then Scanning.next_char ib else - bad_input (Printf.sprintf "looking for %C, found %C" c ci);; + if ci != c + then bad_input (Printf.sprintf "looking for %C, found %C" c ci) + else Scanning.next_char ib;; (* Extracting tokens from ouput token buffer. *) @@ -662,7 +663,7 @@ let make_bv bit set = if i <= lim then match set.[i] with | '-' when rp -> - (* if i = 0 then rp is false (since the initial call is loop false 0) + (* if i = 0 then rp is false (since the initial call is loop bit false 0) hence i >= 1 and the following is safe. *) let c1 = set.[i - 1] in let i = i + 1 in @@ -697,6 +698,7 @@ let make_setp stp char_set = (fun c -> if c == p1 || c == p2 then 1 else 0) | 3 -> let p1 = set.[0] and p2 = set.[1] and p3 = set.[2] in + if p2 = '-' then make_pred 1 set stp else (fun c -> if c == p1 || c == p2 || c == p3 then 1 else 0) | n -> make_pred 1 set stp end @@ -711,6 +713,7 @@ let make_setp stp char_set = (fun c -> if c != p1 && c != p2 then 1 else 0) | 3 -> let p1 = set.[0] and p2 = set.[1] and p3 = set.[2] in + if p2 = '-' then make_pred 0 set stp else (fun c -> if c != p1 && c != p2 && c != p3 then 1 else 0) | n -> make_pred 0 set stp end;; @@ -783,14 +786,14 @@ let scan_chars_in_char_set stp char_set max ib = | 0 -> loop (fun c -> 0) max | 1 -> loop_pos1 set.[0] max | 2 -> loop_pos2 set.[0] set.[1] max - | 3 -> loop_pos3 set.[0] set.[1] set.[2] max + | 3 when set.[1] != '-' -> loop_pos3 set.[0] set.[1] set.[2] max | n -> loop (find_setp stp char_set) max end | Neg_set set -> begin match String.length set with | 0 -> loop (fun c -> 1) max | 1 -> loop_neg1 set.[0] max | 2 -> loop_neg2 set.[0] set.[1] max - | 3 -> loop_neg3 set.[0] set.[1] set.[2] max + | 3 when set.[1] != '-' -> loop_neg3 set.[0] set.[1] set.[2] max | n -> loop (find_setp stp char_set) max end in if stp != [] then check_char_in stp ib; max;;