let compare_substring (a, idxa, lena) (b, idxb, lenb) =
let module With_exns = struct
exception Return of int
exception Left_out of int
exception Right_out of int
let f () =
try
let shortest = min lena lenb in
for i = 0 to shortest - 1 do
let ca = try B.get a (idxa + i) with _ -> raise (Left_out i) in
let cb = try B.get b (idxb + i) with _ -> raise (Right_out i) in
let c = Char.compare ca cb in
if c <> 0
then raise (Return c)
else ()
done;
(Pervasives.compare (lena : int) lenb)
with
| Return c -> c
| Left_out c -> -1
| Right_out _ ->
1
end in
With_exns.f ()