From 47abd87f74dbb7dbf4fe8db0af89f32fbabc101f Mon Sep 17 00:00:00 2001 From: Fabian Date: Mon, 22 Aug 2016 01:52:44 +0200 Subject: [PATCH] Fix CCString.Split.{left,right} (#75) --- src/core/CCString.cppo.ml | 8 ++++++-- src/core/CCString.mli | 4 ++++ 2 files changed, 10 insertions(+), 2 deletions(-) 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