Source

cadastr / src / cd_StringsCommon.ml

(* common functions used both in Cd_Strings and Cd_Buffer
   which depend on each other
*)


value is_valid_substring str ofs len =
     ofs >= 0
  && len >= 0
  && ofs + len <= String.length str
;

(* does not check bounds! *)
value substring_eq ~s1 ~ofs1 ~s2 ~ofs2 ~len =
  if    not (is_valid_substring s1 ofs1 len)
     || not (is_valid_substring s2 ofs2 len)
  then invalid_arg "Cd_StringsCommon.substring_eq"
  else
  inner 0
  where rec inner i =
    if i = len
    then True
    else
      if s1.[ofs1 + i] = s2.[ofs2 + i]
      then inner (i + 1)
      else False
;