Commits

camlspotter committed f918705

is_postfix

Comments (0)

Files changed (2)

-let is_prefix_from str pos sub =
+let is_prefix str ?from:(pos=0) ~prefix:sub =
   let str_len = String.length str in
   let sub_len = String.length sub in
   if pos + sub_len > str_len then false
     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 if is_prefix str ~from:i ~prefix:sub then i
       else iter (i+1)
     in
     iter pos
+
+let is_postfix str ~postfix =
+  is_prefix str ~from:(String.length str - String.length postfix) ~prefix:postfix
+
-val is_prefix_from : string -> int -> string -> bool
+val is_prefix : string -> ?from:int -> prefix:string -> bool
+val is_postfix : string -> postfix:string -> bool
 val index_string_from : string -> int -> string -> int (* may raise Not_found *)