add CCString.split_on_char

This commit is contained in:
Simon Cruanes 2017-03-10 21:33:40 +01:00
parent 48bb1e24c6
commit ef651342eb
2 changed files with 18 additions and 0 deletions

View file

@ -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

View file

@ -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