package core

  1. Overview
  2. Docs
Legend:
Library
Module
Module type
Parameter
Class
Class type

A substring is a contiguous set of characters within a string. Creating a substring does not copy. Therefore modifying the string also modifies the substring.

module type S = Substring_intf.S
type base = bytes

The type of strings that type t is a substring of.

type t
include Ppx_quickcheck_runtime.Quickcheckable.S with type t := t
val quickcheck_generator : t Base_quickcheck.Generator.t
val quickcheck_observer : t Base_quickcheck.Observer.t
val quickcheck_shrinker : t Base_quickcheck.Shrinker.t
val mem : t -> Base.Char.t -> bool
val length : t -> int
val is_empty : t -> bool
val iter : t -> f:(Base.Char.t -> unit) -> unit
val fold : t -> init:'acc -> f:('acc -> Base.Char.t -> 'acc) -> 'acc
val fold_result : t -> init:'acc -> f:('acc -> Base.Char.t -> ('acc, 'e) Base__.Result.t) -> ('acc, 'e) Base__.Result.t
val fold_until : t -> init:'acc -> f: ('acc -> Base.Char.t -> ('acc, 'final) Base__Container_intf.Continue_or_stop.t) -> finish:('acc -> 'final) -> 'final
val exists : t -> f:(Base.Char.t -> bool) -> bool
val for_all : t -> f:(Base.Char.t -> bool) -> bool
val count : t -> f:(Base.Char.t -> bool) -> int
val sum : (module Base__Container_intf.Summable with type t = 'sum) -> t -> f:(Base.Char.t -> 'sum) -> 'sum
val find : t -> f:(Base.Char.t -> bool) -> Base.Char.t option
val find_map : t -> f:(Base.Char.t -> 'a option) -> 'a option
val to_list : t -> Base.Char.t list
val to_array : t -> Base.Char.t array
val min_elt : t -> compare:(Base.Char.t -> Base.Char.t -> int) -> Base.Char.t option
val max_elt : t -> compare:(Base.Char.t -> Base.Char.t -> int) -> Base.Char.t option
val foldi : (t, Base.Char.t, 'a) Base__Indexed_container_intf.foldi
val iteri : (t, Base.Char.t) Base__Indexed_container_intf.iteri
val existsi : t -> f:(int -> Base.Char.t -> bool) -> bool
val for_alli : t -> f:(int -> Base.Char.t -> bool) -> bool
val counti : t -> f:(int -> Base.Char.t -> bool) -> int
val findi : t -> f:(int -> Base.Char.t -> bool) -> (int * Base.Char.t) option
val find_mapi : t -> f:(int -> Base.Char.t -> 'a option) -> 'a option
val base : t -> base
val pos : t -> Base.Int.t

pos refers to the position in the base string, not any other substring that this substring was generated from.

val get : t -> Base.Int.t -> Base.Char.t

Per String.get and Bigstring.get, this raises an exception if the index is out of bounds.

val create : ?pos:Base.Int.t -> ?len:Base.Int.t -> base -> t

create ?pos ?len base creates a substring of the base sequence of length len starting at position pos, i.e.,

base.[pos], base.[pos + 1], ... base.[pos + len - 1] 

An exception is raised if any of those indices into base is invalid.

It does not copy the characters, so mutating base mutates t and vice versa.

val sub : ?pos:Base.Int.t -> ?len:Base.Int.t -> t -> t

Blit functions

For copying characters from a substring to and from both strings and substrings.

val blit_to_string : t -> dst:Base.Bytes.t -> dst_pos:Base.Int.t -> Base.Unit.t
val blit_to_bytes : t -> dst:Base.Bytes.t -> dst_pos:Base.Int.t -> Base.Unit.t
val blit_to_bigstring : t -> dst:Bigstring.t -> dst_pos:Base.Int.t -> Base.Unit.t
val blit_from_string : t -> src:Base.String.t -> src_pos:Base.Int.t -> len:Base.Int.t -> Base.Unit.t
val blit_from_bigstring : t -> src:Bigstring.t -> src_pos:Base.Int.t -> len:Base.Int.t -> Base.Unit.t

String concatenation

These functions always copy.

val concat : t Base.List.t -> t
val concat_string : t Base.List.t -> Base.String.t
val concat_bigstring : t Base.List.t -> Bigstring.t

Conversion to/from substrings

These functions always copy.

val to_string : t -> Base.String.t
val to_bigstring : t -> Bigstring.t

These functions always copy. Use create if you want sharing.

val of_string : Base.String.t -> t
  • deprecated [since 2017-11] use [create] instead
val of_bigstring : Bigstring.t -> t
  • deprecated [since 2017-11] use [create] instead

Prefixes and suffixes

The result of these functions share data with their input, but don't mutate the underlying string.

val drop_prefix : t -> Base.Int.t -> t
val drop_suffix : t -> Base.Int.t -> t
val prefix : t -> Base.Int.t -> t
val suffix : t -> Base.Int.t -> t
OCaml

Innovation. Community. Security.