|
@@ -64,13 +64,14 @@ let parse_int s =
|
|
|
| '0'..'9' | 'a'..'f' | 'A'..'F' -> loop_hex sp (i + 1)
|
|
|
| _ -> String.sub s sp (i - sp)
|
|
|
in
|
|
|
- let rec loop sp i =
|
|
|
+ let rec loop sp i digits_count =
|
|
|
if i = String.length s then (if sp = 0 then s else String.sub s sp (i - sp)) else
|
|
|
match String.unsafe_get s i with
|
|
|
- | '0'..'9' -> loop sp (i + 1)
|
|
|
- | ' ' | ' ' when sp = i -> loop (sp + 1) (i + 1)
|
|
|
- | '-' when i = sp -> loop sp (i + 1)
|
|
|
- | ('x' | 'X') when i > 0 && String.get s (i - 1) = '0' -> loop_hex sp (i + 1)
|
|
|
+ | '0'..'9' -> loop sp (i + 1) (digits_count + 1)
|
|
|
+ | ' ' | '+' when sp = i -> loop (sp + 1) (i + 1) digits_count
|
|
|
+ | c when sp = i && Char.code c > 8 && Char.code c < 14 -> loop (sp + 1) (i + 1) digits_count
|
|
|
+ | '-' when i = sp -> loop sp (i + 1) digits_count
|
|
|
+ | ('x' | 'X') when digits_count = 1 && String.get s (i - 1) = '0' -> loop_hex sp (i + 1)
|
|
|
| _ -> String.sub s sp (i - sp)
|
|
|
in
|
|
|
- Int32.of_string (loop 0 0)
|
|
|
+ Int32.of_string (loop 0 0 0)
|