mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-07 03:35:30 -05:00
Fix CCString.Split.{left,right} (#75)
This commit is contained in:
parent
e704020e35
commit
47abd87f74
2 changed files with 10 additions and 2 deletions
|
|
@ -367,14 +367,18 @@ module Split = struct
|
|||
let left_exn ~by s =
|
||||
let i = find ~sub:by s in
|
||||
if i = ~-1 then raise Not_found
|
||||
else String.sub s 0 i, String.sub s (i+1) (String.length s - i - 1)
|
||||
else
|
||||
let right = i + String.length by in
|
||||
String.sub s 0 i, String.sub s right (String.length s - right)
|
||||
|
||||
let left ~by s = try Some (left_exn ~by s) with Not_found -> None
|
||||
|
||||
let right_exn ~by s =
|
||||
let i = rfind ~sub:by s in
|
||||
if i = ~-1 then raise Not_found
|
||||
else String.sub s 0 i, String.sub s (i+1) (String.length s - i - 1)
|
||||
else
|
||||
let right = i + String.length by in
|
||||
String.sub s 0 i, String.sub s right (String.length s - right)
|
||||
|
||||
let right ~by s = try Some (right_exn ~by s) with Not_found -> None
|
||||
end
|
||||
|
|
|
|||
|
|
@ -449,7 +449,9 @@ module Split : sig
|
|||
|
||||
(*$T
|
||||
Split.left ~by:" " "ab cde f g " = Some ("ab", "cde f g ")
|
||||
Split.left ~by:"__" "a__c__e_f" = Some ("a", "c__e_f")
|
||||
Split.left ~by:"_" "abcde" = None
|
||||
Split.left ~by:"a_" "abcde" = None
|
||||
*)
|
||||
|
||||
val right : by:string -> string -> (string * string) option
|
||||
|
|
@ -464,7 +466,9 @@ module Split : sig
|
|||
|
||||
(*$T
|
||||
Split.right ~by:" " "ab cde f g" = Some ("ab cde f", "g")
|
||||
Split.right ~by:"__" "a__c__e_f" = Some ("a__c", "e_f")
|
||||
Split.right ~by:"_" "abcde" = None
|
||||
Split.right ~by:"a_" "abcde" = None
|
||||
*)
|
||||
end
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue