diff --git a/src/core/CCString.cppo.ml b/src/core/CCString.cppo.ml index 0758d71c..cbf78bc5 100644 --- a/src/core/CCString.cppo.ml +++ b/src/core/CCString.cppo.ml @@ -388,6 +388,20 @@ module Split = struct let right ~by s = try Some (right_exn ~by s) with Not_found -> None end +let split_on_char c s: _ list = + Split.list_cpy ~by:(String.make 1 c) s + +(*$= & ~printer:Q.Print.(list string) + ["a"; "few"; "words"; "from"; "our"; "sponsors"] \ + (split_on_char ' ' "a few words from our sponsors") +*) + +(*$Q + Q.(printable_string) (fun s -> \ + let s = split_on_char ' ' s |> String.concat " " in \ + s = split_on_char ' ' s |> String.concat " ") +*) + let compare_versions a b = let of_int s = try Some (int_of_string s) with _ -> None in let rec cmp_rec a b = match a(), b() with diff --git a/src/core/CCString.mli b/src/core/CCString.mli index 85aa5a6d..184862cf 100644 --- a/src/core/CCString.mli +++ b/src/core/CCString.mli @@ -495,6 +495,10 @@ module Split : sig *) end +val split_on_char : char -> string -> string list +(** Split the string along the given char + @since NEXT_RELEASE *) + (** {2 Utils} *) val compare_versions : string -> string -> int