Note:

You are viewing a development version of the library. Goto the latest version.

let find ~what ?(offset=0) str =
  let what_idx = ref 0 in
  let str_idx = ref offset in 
    while !str_idx < String.length str && 
          !what_idx < String.length what do
      if str.[!str_idx] = what.[!what_idx] then
        incr what_idx
      else
        what_idx := 0;
      incr str_idx
    done;
    if !what_idx <> String.length what then
      raise Not_found
    else 
      !str_idx - !what_idx