1. camlspotter
  2. spotlib

Commits

camlspotter  committed a57f9e7

added is_postfix

  • Participants
  • Parent commits 7582fc2
  • Branches default

Comments (0)

Files changed (2)

File xstring.ml

View file
  • Ignore whitespace
-let is_prefix_from str pos sub =
+let is_prefix ?from:(pos=0) ~prefix:sub str =
   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 ~postfix:sub str =
+  is_prefix ~from:(String.length str - String.length sub) ~prefix: sub str

File xstring.mli

View file
  • Ignore whitespace
-val is_prefix_from : string -> int -> string -> bool
+val is_prefix : ?from:int -> prefix:string -> string -> bool
+val is_postfix : postfix:string -> string -> bool
 val index_string_from : string -> int -> string -> int (* may raise Not_found *)