package topkg

  1. Overview
  2. Docs

Strings.

String additions

include module type of Stdlib.String
type t = string
val make : int -> char -> string
val init : int -> (int -> char) -> string
val empty : string
val of_bytes : bytes -> string
val to_bytes : string -> bytes
val length : string -> int
val get : string -> int -> char
val concat : string -> string list -> string
val cat : string -> string -> string
val equal : t -> t -> bool
val compare : t -> t -> int
val starts_with : prefix:string -> string -> bool
val ends_with : suffix:string -> string -> bool
val contains_from : string -> int -> char -> bool
val rcontains_from : string -> int -> char -> bool
val contains : string -> char -> bool
val sub : string -> int -> int -> string
val split_on_char : char -> string -> string list
val map : (char -> char) -> string -> string
val mapi : (int -> char -> char) -> string -> string
val fold_left : ('a -> char -> 'a) -> 'a -> string -> 'a
val fold_right : (char -> 'a -> 'a) -> string -> 'a -> 'a
val trim : string -> string
val escaped : string -> string
val uppercase_ascii : string -> string
val lowercase_ascii : string -> string
val capitalize_ascii : string -> string
val uncapitalize_ascii : string -> string
val iter : (char -> unit) -> string -> unit
val iteri : (int -> char -> unit) -> string -> unit
val index_from : string -> int -> char -> int
val index_from_opt : string -> int -> char -> int option
val rindex_from : string -> int -> char -> int
val rindex_from_opt : string -> int -> char -> int option
val index : string -> char -> int
val index_opt : string -> char -> int option
val rindex : string -> char -> int
val rindex_opt : string -> char -> int option
val to_seq : t -> char Stdlib.Seq.t
val to_seqi : t -> (int * char) Stdlib.Seq.t
val of_seq : char Stdlib.Seq.t -> t
val get_utf_8_uchar : t -> int -> Stdlib.Uchar.utf_decode
val is_valid_utf_8 : t -> bool
val get_utf_16be_uchar : t -> int -> Stdlib.Uchar.utf_decode
val is_valid_utf_16be : t -> bool
val get_utf_16le_uchar : t -> int -> Stdlib.Uchar.utf_decode
val is_valid_utf_16le : t -> bool
val create : int -> bytes
  • deprecated Use Bytes.create/BytesLabels.create instead.
val set : bytes -> int -> char -> unit
  • deprecated Use Bytes.set/BytesLabels.set instead.
val blit : string -> int -> bytes -> int -> int -> unit
val copy : string -> string
  • deprecated Strings now immutable: no need to copy
val fill : bytes -> int -> int -> char -> unit
  • deprecated Use Bytes.fill/BytesLabels.fill instead.
val uppercase : string -> string
  • deprecated Use String.uppercase_ascii/StringLabels.uppercase_ascii instead.
val lowercase : string -> string
  • deprecated Use String.lowercase_ascii/StringLabels.lowercase_ascii instead.
val capitalize : string -> string
  • deprecated Use String.capitalize_ascii/StringLabels.capitalize_ascii instead.
val uncapitalize : string -> string
  • deprecated Use String.uncapitalize_ascii/StringLabels.uncapitalize_ascii instead.
val get_uint8 : string -> int -> int
val get_int8 : string -> int -> int
val get_uint16_ne : string -> int -> int
val get_uint16_be : string -> int -> int
val get_uint16_le : string -> int -> int
val get_int16_ne : string -> int -> int
val get_int16_be : string -> int -> int
val get_int16_le : string -> int -> int
val get_int32_ne : string -> int -> int32
val get_int32_be : string -> int -> int32
val get_int32_le : string -> int -> int32
val get_int64_ne : string -> int -> int64
val get_int64_be : string -> int -> int64
val get_int64_le : string -> int -> int64
val unsafe_get : string -> int -> char
val unsafe_set : bytes -> int -> char -> unit
  • deprecated
val unsafe_blit : string -> int -> bytes -> int -> int -> unit
val unsafe_fill : bytes -> int -> int -> char -> unit
  • deprecated
val head : string -> char option

head s if Some s.[0] if s <> "" and None otherwise.

Predicates

val is_prefix : affix:string -> string -> bool

is_prefix ~affix s is true iff affix.[i] = s.[i] for all indices i of affix.

val is_suffix : affix:string -> string -> bool

is_suffix ~affix s is true iff affix.[n - i] = s.[m - i] for all indices i of affix with n = String.length affix - 1 and m = String.length s - 1.

val for_all : (char -> bool) -> string -> bool

for_all p s is true iff for all indices i of s, p s.[i] = true.

val exists : (char -> bool) -> string -> bool

exists p s is true iff there exists an index i of s with p s.[i] = true.

Extracting substrings

val with_index_range : ?first:int -> ?last:int -> string -> string

with_index_range ~first ~last s are the consecutive bytes of s whose indices exist in the range [first;last].

first defaults to 0 and last to String.length s - 1.

Note that both first and last can be any integer. If first > last the interval is empty and the empty string is returned.

val cut : ?rev:bool -> sep:char -> string -> (string * string) option

cut ~sep s is either the pair Some (l,r) of the two (possibly empty) substrings of s that are delimited by the first match of the separator character sep or None if sep can't be matched in s. Matching starts from the beginning of s (rev is false, default) or the end (rev is true).

The invariant l ^ (String.make 1 sep) ^ r = s holds.

val cuts : ?empty:bool -> sep:char -> string -> string list

cuts ~sep s is the list of all substring of s that are delimited by matches of sep. Empty substrings are ommited in the list if empty is falsee (defaults to true). The invariant String.concat (String.make 1 sep) (split ~sep s) = s holds.

Parsing version strings

val parse_version : string -> (int * int * int * string option) option

parse_version parses version strings of the form:

"[v]major.minor[.patchlevel][(+|~)additional-info]"

into (major, minor, patch, (+|~)additional_info) tuples.

val drop_initial_v : string -> string

drop_initial_v s drops a leading 'v' or 'V' from s.

OCaml

Innovation. Community. Security.