diff --git a/src/core/CCString.cppo.ml b/src/core/CCString.cppo.ml index 6097665a..dbd84898 100644 --- a/src/core/CCString.cppo.ml +++ b/src/core/CCString.cppo.ml @@ -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 diff --git a/src/core/CCString.mli b/src/core/CCString.mli index d0a2c5c2..edb10378 100644 --- a/src/core/CCString.mli +++ b/src/core/CCString.mli @@ -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