package containers

  1. Overview
  2. Docs

Basic String Utils

Consider using Containers_string.KMP for pattern search, or Regex libraries.

type 'a gen = unit -> 'a option
type 'a sequence = ('a -> unit) -> unit
type 'a klist = unit -> [ `Nil | `Cons of 'a * 'a klist ]

Common Signature

module type S = sig ... end

Strings

val equal : string -> string -> bool
val compare : string -> string -> int
val hash : string -> int
val init : int -> (int -> char) -> string

Analog to Array.init.

  • since 0.3.3
val of_gen : char gen -> string
val of_seq : char sequence -> string
val of_klist : char klist -> string
val of_list : char list -> string
val of_array : char array -> string
val to_array : string -> char array
val find : ?start:int -> sub:string -> string -> int

Find sub in string, returns its first index or -1. Should only be used with very small sub

val is_sub : sub:string -> int -> string -> int -> len:int -> bool

is_sub ~sub i s j ~len returns true iff the substring of sub starting at position i and of length len

val repeat : string -> int -> string

The same string, repeated n times

val prefix : pre:string -> string -> bool

prefix ~pre s returns true iff pre is a prefix of s

val suffix : suf:string -> string -> bool

suffix ~suf s returns true iff suf is a suffix of s

  • since 0.7
val lines : string -> string list

lines s returns a list of the lines of s (splits along '\n')

  • since 0.10
val lines_gen : string -> string gen

lines_gen s returns a generator of the lines of s (splits along '\n')

  • since 0.10
val concat_gen : sep:string -> string gen -> string

concat_gen ~sep g concatenates all strings of g, separated with sep.

  • since 0.10
val unlines : string list -> string

unlines l concatenates all strings of l, separated with '\n'

  • since 0.10
val unlines_gen : string gen -> string

unlines_gen g concatenates all strings of g, separated with '\n'

  • since 0.10
include S with type t := string
val length : string -> int
val blit : string -> int -> string -> int -> int -> unit
val fold : ('a -> char -> 'a) -> 'a -> string -> 'a

Fold on chars by increasing index.

  • since 0.7

Conversions

val to_gen : string -> char gen
val to_seq : string -> char sequence
val to_klist : string -> char klist
val to_list : string -> char list
val pp : Buffer.t -> string -> unit
val print : Format.formatter -> string -> unit

Splitting

module Split : sig ... end

Slices

A contiguous part of a string

module Sub : sig ... end
OCaml

Innovation. Community. Security.