mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-06 03:05:28 -05:00
style update for some string functions
This commit is contained in:
parent
14d701f84c
commit
54e12b7f62
2 changed files with 17 additions and 9 deletions
|
|
@ -492,18 +492,20 @@ let repeat s n =
|
|||
|
||||
let prefix ~pre s =
|
||||
String.length pre <= String.length s &&
|
||||
(let i = ref 0 in
|
||||
while !i < String.length pre && s.[!i] = pre.[!i] do incr i done;
|
||||
!i = String.length pre
|
||||
)
|
||||
begin
|
||||
let i = ref 0 in
|
||||
while !i < String.length pre && s.[!i] = pre.[!i] do incr i done;
|
||||
!i = String.length pre
|
||||
end
|
||||
|
||||
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
|
||||
)
|
||||
begin
|
||||
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
|
||||
end
|
||||
|
||||
let take n s =
|
||||
if n < String.length s
|
||||
|
|
|
|||
|
|
@ -212,6 +212,10 @@ val prefix : pre:string -> string -> bool
|
|||
prefix ~pre:"aab" "aabcd"
|
||||
not (prefix ~pre:"ab" "aabcd")
|
||||
not (prefix ~pre:"abcd" "abc")
|
||||
prefix ~pre:"abc" "abcde"
|
||||
prefix ~pre:"" ""
|
||||
prefix ~pre:"" "abc"
|
||||
prefix ~pre:"abc" "abc"
|
||||
*)
|
||||
|
||||
val suffix : suf:string -> string -> bool
|
||||
|
|
@ -220,6 +224,8 @@ val suffix : suf:string -> string -> bool
|
|||
|
||||
(*$T
|
||||
suffix ~suf:"cd" "abcd"
|
||||
suffix ~suf:"" ""
|
||||
suffix ~suf:"" "abc"
|
||||
not (suffix ~suf:"cd" "abcde")
|
||||
not (suffix ~suf:"abcd" "cd")
|
||||
*)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue