mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-07 03:35:30 -05:00
CCstring.suffix
This commit is contained in:
parent
b8b0cc3645
commit
15aecd2435
2 changed files with 28 additions and 2 deletions
|
|
@ -181,7 +181,17 @@ let prefix ~pre s =
|
||||||
String.length pre <= String.length s &&
|
String.length pre <= String.length s &&
|
||||||
(let i = ref 0 in
|
(let i = ref 0 in
|
||||||
while !i < String.length pre && s.[!i] = pre.[!i] do incr i done;
|
while !i < String.length pre && s.[!i] = pre.[!i] do incr i done;
|
||||||
!i = String.length pre)
|
!i = String.length pre
|
||||||
|
)
|
||||||
|
|
||||||
|
let suffix ~suf s =
|
||||||
|
String.length suf <= String.length s &&
|
||||||
|
let off = String.length s - String.length suf in
|
||||||
|
(let i = ref 0 in
|
||||||
|
while !i < String.length suf && s.[off + !i] = suf.[!i] do incr i done;
|
||||||
|
!i = String.length suf
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
let blit = String.blit
|
let blit = String.blit
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -91,7 +91,23 @@ val repeat : string -> int -> string
|
||||||
(** The same string, repeated n times *)
|
(** The same string, repeated n times *)
|
||||||
|
|
||||||
val prefix : pre:string -> string -> bool
|
val prefix : pre:string -> string -> bool
|
||||||
(** [str_prefix ~pre s] returns [true] iff [pre] is a prefix of [s] *)
|
(** [prefix ~pre s] returns [true] iff [pre] is a prefix of [s] *)
|
||||||
|
|
||||||
|
(*$T
|
||||||
|
prefix ~pre:"aab" "aabcd"
|
||||||
|
not (prefix ~pre:"ab" "aabcd")
|
||||||
|
not (prefix ~pre:"abcd" "abc")
|
||||||
|
*)
|
||||||
|
|
||||||
|
val suffix : suf:string -> string -> bool
|
||||||
|
(** [suffix ~suf s] returns [true] iff [suf] is a suffix of [s]
|
||||||
|
@since NEXT_RELEASE *)
|
||||||
|
|
||||||
|
(*$T
|
||||||
|
suffix ~suf:"cd" "abcd"
|
||||||
|
not (suffix ~suf:"cd" "abcde")
|
||||||
|
not (suffix ~suf:"abcd" "cd")
|
||||||
|
*)
|
||||||
|
|
||||||
include S with type t := string
|
include S with type t := string
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue