An extension of the standard StringLabels. If you open Base, you'll get these in
the String module.
include sig ... endval t_of_sexp : Base__.Sexplib.Sexp.t ‑> tval sexp_of_t : t ‑> Base__.Sexplib.Sexp.tval hash_fold_t : Base__.Ppx_hash_lib.Std.Hash.state ‑> t ‑> Base__.Ppx_hash_lib.Std.Hash.stateval hash : t ‑> Base__.Ppx_hash_lib.Std.Hash.hash_valuemodule Caseless : sig ... endCaseless compares and hashes strings ignoring case, so that for example
Caseless.equal "OCaml" "ocaml" and Caseless.("apple" < "Banana") are true, and
Caseless.Map, Caseless.Table lookup and Caseless.Set membership is
case-insensitive. Caseless also provides case insensitive is_suffix and is_prefix
functions, so that for example Caseless.is_suffix "OCaml" ~suffix:"AmL" and
Caseless.is_prefix "OCaml" ~prefix:"oc" are true.
include Blit.S with type t := tval blit : (t, t) Blit_intf.blitval blito : (t, t) Blit_intf.blitoval unsafe_blit : (t, t) Blit_intf.blitval sub : (t, t) Blit_intf.subval subo : (t, t) Blit_intf.suboinclude Container.S0 with type t := t with type elt = charval length : t ‑> intval is_empty : t ‑> booliter must allow exceptions raised in f to escape, terminating the iteration
cleanly. The same holds for all functions below taking an f.
val fold_result : t ‑> init:'accum ‑> f:('accum ‑> elt ‑> ('accum, 'e) Result.t) ‑> ('accum, 'e) Result.tfold_result t ~init ~f is a short-circuiting version of fold that runs in the
Result monad. If f returns an Error _, that value is returned without any
additional invocations of f.
val fold_until : t ‑> init:'accum ‑> f:('accum ‑> elt ‑> ('accum, 'stop) Container_intf.Continue_or_stop.t) ‑> ('accum, 'stop) Container_intf.Finished_or_stopped_early.tfold_until t ~init ~f is a short-circuiting version of fold. If f
returns Stop _ the computation ceases and results in that value. If f returns
Continue _, the fold will proceed.
Returns true if and only if there exists an element for which the provided
function evaluates to true. This is a short-circuiting operation.
Returns true if and only if the provided function evaluates to true for all
elements. This is a short-circuiting operation.
val sum : (module Commutative_group.S with type t = 'sum) ‑> t ‑> f:(elt ‑> 'sum) ‑> 'sumReturns the sum of f i for i in the container
include Identifiable.S with type t := tinclude sig ... endval t_of_sexp : Base__.Sexplib.Sexp.t ‑> tval sexp_of_t : t ‑> Base__.Sexplib.Sexp.tval hash_fold_t : Base__.Ppx_hash_lib.Std.Hash.state ‑> t ‑> Base__.Ppx_hash_lib.Std.Hash.stateval hash : t ‑> Base__.Ppx_hash_lib.Std.Hash.hash_valueinclude Comparable.S with type t := tinclude Comparable_intf.Polymorphic_compareascending is identical to compare. descending x y = ascending y x. These are
intended to be mnemonic when used like List.sort ~cmp:ascending and List.sort
~cmp:descending, since they cause the list to be sorted in ascending or descending
order, respectively.
clamp_exn t ~min ~max returns t', the closest value to t such that
between t' ~low:min ~high:max is true.
Raises if not (min <= max).
val clamp : t ‑> min:t ‑> max:t ‑> t Or_error.tinclude Comparator.S with type t := tval comparator : (t, comparator_witness) Comparator.comparatorinclude Comparable_intf.Validate with type t := tval validate_lbound : min:t Maybe_bound.t ‑> t Validate.checkval validate_ubound : max:t Maybe_bound.t ‑> t Validate.checkval validate_bound : min:t Maybe_bound.t ‑> max:t Maybe_bound.t ‑> t Validate.checkexternal length : t ‑> int = "%string_length" external get : t ‑> int ‑> char = "%string_safe_get" val create : int ‑> tval make : int ‑> char ‑> tval init : int ‑> f:(int ‑> char) ‑> tval fill : t ‑> pos:int ‑> len:int ‑> char ‑> unitString append. Also available unqualified, but re-exported here for documentation purposes.
Note that a ^ b must copy both a and b into a newly-allocated result string, so
a ^ b ^ c ^ ... ^ z is quadratic in the number of strings. String.concat does not
have this problem -- it allocates the result buffer only once. The Rope module
provides a data structure which uses a similar trick to achieve fast concatenation at
either end of a string.
Warning: Only returns a copy if changes are necessary! Special characters are represented by escape sequences, following the lexical conventions of Objective Caml.
val contains : ?pos:int ‑> ?len:int ‑> t ‑> char ‑> boolval index : t ‑> char ‑> int optionval index_exn : t ‑> char ‑> intval rindex : t ‑> char ‑> int optionval rindex_exn : t ‑> char ‑> intval index_from : t ‑> int ‑> char ‑> int optionval index_from_exn : t ‑> int ‑> char ‑> intval rindex_from : t ‑> int ‑> char ‑> int optionval rindex_from_exn : t ‑> int ‑> char ‑> intmodule Search_pattern : sig ... endSubstring search and replace functions. They use the Knuth-Morris-Pratt algorithm (KMP) under the hood.
Substring search and replace convenience functions. They call Search_pattern.create
and then forget the preprocessed pattern when the search is complete. pos < 0 or
pos >= length t result in no match (hence substr_index returns None and
substr_index_exn raises). may_overlap indicates whether to report overlapping
matches, see Search_pattern.index_all.
slice s start stop gets a slice of s between start and stop.
start and stop will be normalized before the access.
(viz. Array.normalize).
If the string s contains the character on, then lsplit2_exn
s ~on returns a pair containing s split around the first
appearance of on (from the left).
on cannot be found in sIf the string s contains the character on, then rsplit2_exn
s ~on returns a pair containing s split around the first
appearance of on (from the right).
on cannot be found in slsplit2 line ~on optionally returns line split into two strings around the * first appearance of on from the left
rsplit2 line ~on optionally returns line split into two strings around the * first appearance of on from the right
split s ~on
s that are separated by
on. Consecutive on characters will cause multiple empty strings
in the result. Splitting the empty string returns a list of the empty
string, not the empty list.split_on_chars s ~on
s
that are separated by one of the chars from on. on
are not grouped. So a grouping of on in the source string will
produce multiple empty string splits in the result.split_lines t returns the list of lines that comprise t. The lines do
not include the trailing "\n" or "\r\n".
val lfindi : ?pos:int ‑> t ‑> f:(int ‑> char ‑> bool) ‑> int optionlfindi ?pos t ~f returns the smallest i >= pos such that f i t.[i], if there is
such an i. By default, pos = 0.
val rfindi : ?pos:int ‑> t ‑> f:(int ‑> char ‑> bool) ‑> int optionrfindi ?pos t ~f returns the largest i <= pos such that f i t.[i], if there is
such an i. By default pos = length t - 1.
Warning: the following strip functions may return the same string passed in
lstrip ?drop s returns a string with consecutive chars satisfying drop (by default
white space, e.g. tabs, spaces, newlines, and carriage returns) stripped from the
beginning of s.
rstrip ?drop s returns a string with consecutive chars satisfying drop (by default
white space, e.g. tabs, spaces, newlines, and carriage returns) stripped from the end
of s.
strip ?drop s returns a string with consecutive chars satisfying drop (by default
white space, e.g. tabs, spaces, newlines, and carriage returns) stripped from the
beginning and end of s.
val foldi : t ‑> init:'a ‑> f:(int ‑> 'a ‑> char ‑> 'a) ‑> 'afoldi works similarly to fold, but also pass in index of each character to f
val tr_inplace : target:char ‑> replacement:char ‑> t ‑> unittr_inplace target replacement s destructively modifies s (in place!)
replacing every instance of target in s with replacement.
chop_suffix_exn s ~suffix returns a copy of s without the trailing suffix
suffix is not a suffix of schop_prefix_exn s ~prefix returns a copy of s without the leading prefix
prefix is not a prefix of sval of_char : char ‑> tval of_char_list : char list ‑> tmodule Escaping : sig ... endOperations for escaping and unescaping strings, with parameterized escape and escapeworthy characters. Escaping/unescaping using this module is more efficient than using Pcre. Benchmark code can be found in core/benchmarks/string_escaping.ml.
String_set_primitives is generated by a rule in the jbuild to work around the fact
that the %string_*_set primitives are renamed to %bytes_*_set in OCaml 4.04, and then
deleted in OCaml 4.05.