To focus the search input from anywhere on the page, press the 'S' key.
in-package search v0.1.0
Library
Module
Module type
Parameter
Class
Class type
An extension of the standard StringLabels. If you open Base
, you'll get these in the String module.
include sig ... end
module Caseless : sig ... end
Caseless
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
.
val blito : (t, bytes) Blit.blito
include Container.S0 with type t := t with type elt = char
iter
must allow exceptions raised in f
to escape, terminating the iteration cleanly. The same holds for all functions below taking an f
.
fold t ~init ~f
returns f (... f (f (f init e1) e2) e3 ...) en
, where e1..en
are the elements of t
.
val fold_result :
t ->
init:'accum ->
f:('accum -> elt -> ('accum, 'e) Result.t) ->
('accum, 'e) Result.t
fold_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.Export.Continue_or_stop.t) ->
('accum, 'stop) Container_intf.Export.Finished_or_stopped_early.t
fold_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.
Returns the number of elements for which the provided function evaluates to true.
val sum :
(module Commutative_group.S with type t = 'sum) ->
t ->
f:(elt -> 'sum) ->
'sum
Returns the sum of f i
for all i
in the container.
Returns as an option
the first element for which f
evaluates to true.
Returns the first evaluation of f
that returns Some
, and returns None
if there is no such element.
Returns a min (resp. max) element from the collection using the provided cmp
function. In case of a tie, the first element encountered while traversing the collection is returned. The implementation uses fold
so it has the same complexity as fold
. Returns None
iff the collection is empty.
include Identifiable.S with type t := t
include sig ... end
val hash_fold_t : Hash.state -> t -> Hash.state
include Comparable.S with type t := t
include Comparable_intf.Polymorphic_compare with type t := t
compare t1 t2
returns 0 if t1
is equal to t2
, a negative integer if t1
is less than t2
, and a positive integer if t1
is greater than t2
.
ascending
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.t
include Comparator.S with type t := t
val comparator : (t, comparator_witness) Comparator.comparator
include Comparable_intf.Validate with type t := t
val validate_lbound : min:t Maybe_bound.t -> t Validate.check
val validate_ubound : max:t Maybe_bound.t -> t Validate.check
val validate_bound :
min:t Maybe_bound.t ->
max:t Maybe_bound.t ->
t Validate.check
include Pretty_printer.S with type t := t
val pp : Caml.Format.formatter -> t -> unit
val length : t -> int
val get : t -> int -> char
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 -> t
val init : int -> f:(int -> char) -> t
String 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.
concatanate all strings in the list using separator sep
(default sep "")
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 -> bool
val index : t -> char -> int option
val index_exn : t -> char -> int
val rindex : t -> char -> int option
val rindex_exn : t -> char -> int
val index_from : t -> int -> char -> int option
val index_from_exn : t -> int -> char -> int
val rindex_from : t -> int -> char -> int option
val rindex_from_exn : t -> int -> char -> int
module Search_pattern : sig ... end
Substring 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
.
As with Search_pattern.replace_all
, the result may still contain pattern
.
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).
val to_list_rev : t -> char list
Returns the reversed list of characters contained in a list.
val nget : t -> int -> char
nget s i
Gets the char at normalized position i
in s
.
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).
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).
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_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 option
lfindi ?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 option
rfindi ?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
.
map f s
applies f
to each character in s
, and returns the resulting string.
mapi f s
applies f
to each character in s
and its index, and returns the resulting string.
val foldi : t -> init:'a -> f:(int -> 'a -> char -> 'a) -> 'a
foldi
works similarly to fold
, but also pass in index of each character to f
Like map
, but allows replacement of a single character with zero or two or more characters.
filter s ~f:predicate
discards characters not satisfying predicate
tr target replacement s
replaces every instance of target
in s
with replacement
.
tr_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
chop_prefix_exn s ~prefix
returns a copy of s
without the leading prefix
suffix s n
returns the longest suffix of s
of length less than or equal to n
prefix s n
returns the longest prefix of s
of length less than or equal to n
drop_suffix s n
drops the longest suffix of s
of length less than or equal to n
drop_prefix s n
drops the longest prefix of s
of length less than or equal to n
concat_array sep ar
like String.concat
, but operates on arrays
val hash : t -> int
slightly faster hash function on strings
val is_empty : t -> bool
is_empty s
returns true
iff s
is empty (i.e. its length is 0).
val of_char : char -> t
val of_char_list : char list -> t
module Escaping : sig ... end
Operations 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.