try Some (String.index_from t from c)

- let index_of_character_reverse t ?(from=0) c =

+ let index_of_character_reverse t ?from c =

+ let length_of_t = length t in

+ | None -> length_of_t - 1

+ | Some s when s < 0 -> -1

+ | Some s when s > length_of_t - 1 -> length_of_t - 1

try Some (String.rindex_from t from c)

- let index_of_character_reverse t ?(from=0) c =

+ let index_of_character_reverse t ?from c =

let rec loop lgth acc = function

| h :: t -> loop (lgth + 1) (h :: acc) t in

- match index_of_character rev ~from:(length - from - 1) c with

- | Some c -> Some (length - c - 1)

+ | None -> length_of_t - 1

+ | Some s when s < 0 -> -1

+ | Some s when s > length_of_t - 1 -> length_of_t - 1

+ match index_of_character rev ~from:(length_of_t - from - 1) c with

+ | Some c -> Some (length_of_t - c - 1)

let compare_substring (a, idxa, lena) (b, idxb, lenb) =

let index_of_character_reverse t ?from c =

- let from = match from with Some s -> s | None -> length t - 1 in

+ let length_of_t = length t in

+ | None -> length_of_t - 1

+ | Some s when s < 0 -> -1

+ | Some s when s > length_of_t - 1 -> length_of_t - 1