Commits

camlspotter committed 46ef7a7

xstring

Comments (0)

Files changed (2)

+let is_prefix_from str pos sub =
+  let str_len = String.length str in
+  let sub_len = String.length sub in
+  if pos + sub_len > str_len then false
+  else 
+    let rec iter i = 
+      if str.[pos + i] <> sub.[i] then false
+      else 
+        let i' = i + 1 in
+        if i' = sub_len then true
+        else iter i'
+    in
+    iter 0
+
+let index_string_from str pos sub =
+  let sub_len = String.length sub in
+  if sub_len = 0 then pos 
+  else 
+    let limit = String.length str - sub_len in
+    let rec iter i = 
+      if i > limit then raise Not_found
+      else if is_prefix_from str i sub then i
+      else iter (i+1)
+    in
+    iter pos
+val is_prefix_from : string -> int -> string -> bool
+val index_string_from : string -> int -> string -> int (* may raise Not_found *)