Module CCString.Split

type drop_if_empty = {
first : bool;
last : bool;
}

Specification of what to do with empty blocks, as in split ~by:"-" "-a-b-".

  • {first=false; last=false} will return ""; "a"; "b"; ""
  • {first=true; last=false} will return "a"; "b" ""
  • {first=false; last=true} will return ""; "a"; "b"
  • {first=true; last=true} will return "a"; "b"

The default value of all remaining functions is Drop_none.

  • since 1.5
val no_drop : drop_if_empty

no_drop does not drop any group, even empty and on borders.

  • since 1.5
val list_ : ?drop:drop_if_empty -> by:string -> string -> (string * int * int) list

list_ ~drop ~by s splits the given string s along the given separator by. Should only be used with very small separators, otherwise use Containers_string.KMP.

  • returns

    a list of slices (s,index,length) that are separated by by. String.sub can then be used to actually extract a string from the slice.

  • raises Failure

    if by = "".

val gen : ?drop:drop_if_empty -> by:string -> string -> (string * int * int) gen

gen ~drop ~by s splits the given string s along the given separator by. Returns a gen of slices.

val iter : ?drop:drop_if_empty -> by:string -> string -> (string * int * int) iter

iter ~drop ~by s splits the given string s along the given separator by. Returns an iter of slices.

  • since 2.8
val seq : ?drop:drop_if_empty -> by:string -> string -> (string * int * int) Stdlib.Seq.t

seq ~drop ~by s splits the given string s along the given separator by. Returns a Seq.t of slices. Renamed from std_seq since 3.0.

  • since 3.0
Copying functions

Those split functions actually copy the substrings, which can be more convenient but less efficient in general.

val list_cpy : ?drop:drop_if_empty -> by:string -> string -> string list

list_cpy ~drop ~by s splits the given string s along the given separator by. Returns a list of strings.

val gen_cpy : ?drop:drop_if_empty -> by:string -> string -> string gen

gen_cpy ~drop ~by s splits the given string s along the given separator by. Returns a gen of strings.

val iter_cpy : ?drop:drop_if_empty -> by:string -> string -> string iter

iter_cpy ~drop ~by s splits the given string s along the given separator by. Returns an iter of strings.

  • since 2.8
val seq_cpy : ?drop:drop_if_empty -> by:string -> string -> string Stdlib.Seq.t

seq_cpy ~drop ~by s splits the given string s along the given separator by. Returns a Seq.t of strings. Renamed from std_seq_cpy since 3.0.

  • since 3.0
val left : by:string -> string -> (string * string) option

left ~by s splits on the first occurrence of by from the leftmost part of the string s.

  • since 0.12
val left_exn : by:string -> string -> string * string

left_exn ~by s splits on the first occurrence of by from the leftmost part of the string s.

  • raises Not_found

    if by is not part of the string s.

  • since 0.16
val right : by:string -> string -> (string * string) option

right ~by s splits on the first occurrence of by from the rightmost part of the string s.

  • since 0.12
val right_exn : by:string -> string -> string * string

right_exn ~by s splits on the first occurrence of by from the rightmost part of the string s.

  • raises Not_found

    if by is not part of the string s.

  • since 0.16