package conex

  1. Overview
  2. Docs

Some String utilities implemented here to avoid external dependencies. This is a subset of Astring.

type t = string

Our string type is an OCaml string

val cuts : char -> t -> t list

cuts sep str separates str into multiple substrings, stripping out the separating character sep. String.concat "/" (String.cuts '/' xs) is not the identity since empty substrings are stripped.

val cut : char -> t -> (t * t) option

cut sep str cuts the string str at the first occurence of sep into its left and right parts. If sep is not found, None is returned. If Some (a, b) is returned, a ^ sep ^ b is equal to str.

val is_prefix : prefix:t -> t -> bool

is_prefix ~prefix str is true if str begins with prefix, false otherwise.

val is_suffix : suffix:t -> t -> bool

is_suffix ~suffix str is true if str ends with suffix, false otherwise.

val slice : ?start:int -> ?stop:int -> t -> t

slice ~start ~stop str slices str into a smaller piece, starting at offset start (default 0), ending at stop (default String.length).

val to_lower : t -> t

to_lower str converts all printable ASCII characters to lowercase.

val is_ascii : ?p:(char -> bool) -> t -> bool

is_ascii ~p str is true if all characters in str are ASCII characters: 0-9, a-z, A-Z OR satisfy p. Otherwise false.

val trim : t -> t

trim str removes leading and trailing whitespaces of str.

val get : t -> int -> char

get str offset retrieves the character at offset in str.

val concat : t -> t list -> t

concat sep xs concatenates all xs, using sep as separator.

val compare : t -> t -> int

compare a b compares a with b using String.compare.

val length : t -> int

length str is the byte length of str.

val compare_insensitive : t -> t -> int

compare_insensitive a b first converts a and b to lowercase strings, then uses compare.

OCaml

Innovation. Community. Security.