add CCString.mem

This commit is contained in:
Simon Cruanes 2015-07-03 16:52:20 +02:00
parent bca172a7a8
commit 1a73ad7e29
2 changed files with 11 additions and 0 deletions

View file

@ -102,6 +102,8 @@ let find ?(start=0) ~sub s =
with Exit ->
!i
let mem ?start ~sub s = find ?start ~sub s >= 0
let rfind ~sub s =
let n = String.length sub in
let i = ref (String.length s - n) in

View file

@ -108,6 +108,15 @@ val find : ?start:int -> sub:string -> string -> int
find ~sub:"a" "_a_a_a_" = 1
*)
val mem : ?start:int -> sub:string -> string -> bool
(** [mem ~sub s] is true iff [sub] is a substring of [s]
@since NEXT_RELEASE *)
(*$T
mem ~sub:"bc" "abcd"
not (mem ~sub:"a b" "abcd")
*)
val rfind : sub:string -> string -> int
(** Find [sub] in string from the right, returns its first index or [-1].
Should only be used with very small [sub]