An extension of the standard StringLabels. If you open Base, you'll get these
extensions in the String module.
module 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.
include 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, 'final) Base__.Container_intf.Continue_or_stop.t) ‑> finish:('accum ‑> 'final) ‑> 'finalfold_until t ~init ~f ~finish 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. If f never returns Stop _, the final result
is computed by finish.
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 all i in the container.
include Identifiable.S with type t := tinclude Comparable.S with type t := tinclude Base__.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 ~compare: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 Base__.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" external unsafe_get : string ‑> int ‑> char = "%string_unsafe_get" unsafe_get t i is like get t i but does not perform bounds checking. The caller
must ensure that it is a memory-safe operation.
val make : int ‑> char ‑> tval init : int ‑> f:(int ‑> char) ‑> tval fill : bytes ‑> 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 OCaml.
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.
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). Raises
Caml.Not_found or Not_found_s when on cannot be found in s.
If 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). Raises
Caml.Not_found or Not_found_s when on cannot be found in s.
lsplit2 s ~on optionally returns s split into two strings around the
first appearance of on from the left.
rsplit2 s ~on optionally returns s split into two strings around the first
appearance of on from the right.
split s ~on returns a list of substrings of 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 returns a list of all substrings of 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 passes the index of each character to
f.
val tr_inplace : target:char ‑> replacement:char ‑> bytes ‑> 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,
raising Invalid_argument if suffix is not a suffix of s.
chop_prefix_exn s ~prefix returns a copy of s without the leading prefix,
raising Invalid_argument if prefix is not a prefix of s.
concat_array sep ar like String.concat, but operates on arrays.
val is_empty : t ‑> boolval 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.