module type BASIC_STRING =sig
..end
type
character
type
t
val max_string_length : int option
character
s.val empty : t
val is_empty : t -> bool
val make : int -> character -> t
make size char
builds a new string of the passed length
where the
character at every position is char
, like String.make
.
The behavior of make size
is undefined when
size
is < 0
or > {max_string_length}
(if it is Some _
).
Depending on the backend implementing the API, the function
may raise an exception.
val length : t -> int
val of_character : character -> t
val of_character_list : character list -> t
Api.BASIC_STRING.max_string_length
(depends on the backend implementation).val to_character_list : t -> character list
val get : t -> index:int -> character option
get
returns None
when index
is out of bounds.val set : t ->
index:int -> v:character -> t option
set str ~index ~v
creates a new string equal to t
with
character v
at position index
. set
returns None
when
index
is out of bounds.val get_exn : t -> index:int -> character
val set_exn : t ->
index:int -> v:character -> t
val concat : ?sep:t -> t list -> t
concat
function.
The function is subject to same limitations as
Api.BASIC_STRING.of_character_list
regarding Api.BASIC_STRING.max_string_length
.
include Api.NATIVE_CONVERSIONS
val to_string_hum : t -> string
sprintf "%S"
).
Returning an OCaml native string
, the function may raise an
exception when the resulting string
exceeds
Sys.max_string_length
.
val fold : t ->
init:'a -> f:('a -> character -> 'a) -> 'a
fold
function, see List.fold_left
for example.val foldi : t ->
init:'a -> f:(int -> 'a -> character -> 'a) -> 'a
val fold2_exn : t ->
t ->
init:'a ->
f:('a -> character -> character -> 'a) ->
'a
fold2
function, see List.fold_left2
for example. Fails on
t
s of different length.val compare : t -> t -> int
val sub : t -> index:int -> length:int -> t option
length
at position index
. If
length
is 0, sub
returns Some empty
regardless of the other
parameters.val sub_exn : t -> index:int -> length:int -> t
None
.Invalid_argument
when index
and length
do not represent a
valid substring.val slice : ?start:int -> ?finish:int -> t -> t option
start
to just before finish
if all of the
indices are in bounds.start
: defaults to 0
, must be within [0,length)
finish
: default to length
, must be within [0,length)
val slice_exn : ?start:int -> ?finish:int -> t -> t
None
if the indices are out of bounds.Invalid_argument
when start
or finish
are not in their
respective bounds. See slice
.val is_prefix : t -> prefix:t -> bool
t
start with prefix
?val is_suffix : t -> suffix:t -> bool
t
end with suffix
?val chop_prefix_exn : t -> prefix:t -> t
t
with prefix
removed from the beginning.Invalid_argument
if t
does not start with prefix
.val chop_prefix : t -> prefix:t -> t option
val chop_suffix_exn : t -> suffix:t -> t
t
with suffix
removed from the end.Invalid_argument
if t
does not end with suffix
.val chop_suffix : t -> suffix:t -> t option
val split_at : t -> index:int -> t * t
If index is =< 0
then the first element is empty and the string is
returned in the second element, similarly if the index is >= length t
then the first element is t
and the second is empty
.
val take : t -> index:int -> t
split_at
.val drop : t -> index:int -> t
split_at
.val compare_substring : t * int * int -> t * int * int -> int
compare_substring
(s1, index1, length1) (s2, index2, length2)
.
Note that out-of-bounds accesses will not be reported: for
performance reasons, if the result can be decided with the
smallest sub-string then compare_substring
won't look
further.
However, if compare_substring_strict
returns Some c
then compare_substring
must return d
such as
c
= d
or c
× d
> 0 (i.e. strictly same sign).
In other words, if sub a ~index:ia ~length:la
returns Some suba
and
sub b ~index:ib ~length:lb
returns Some subb
, then
compare_substring (a, ia, la) (b, ib, lb)
will behave like
compare suba subb
(again, with the same sign).
val compare_substring_strict : t * int * int ->
t * int * int -> int option
Some _
only
when it is well defined (same validity criteria as sub: if
length
is 0
, index
is irrelevant).
Depending on the backend implementation, this function might be
significantly slower than compare_substring
(for example when
calls to length
are not O(1)).
val iter : t -> f:(character -> unit) -> unit
f
on every character successively.val iteri : t -> f:(int -> character -> unit) -> unit
f
on every character and its index.val iter_reverse : t -> f:(character -> unit) -> unit
f
on every character successively in reverse order.val rev : t -> t
val map : t ->
f:(character -> character) ->
t
f
to all characters of the
input.val mapi : t ->
f:(int -> character -> character) ->
t
f
to all characters and their indices.val map2_exn : t ->
t ->
f:(character ->
character -> character) ->
t
f
to all pairs of characters of the
inputs. Fail if strings are not the same length.val for_all : t -> f:(character -> bool) -> bool
true
if-and-only-if f
returns true
on all characters.val exists : t -> f:(character -> bool) -> bool
true
if-and-only-if f
returns true
on at least one
character.val take_while : t ->
f:(character -> bool) -> t
f
returns false
.val take_while_with_index : t ->
f:(int -> character -> bool) -> t
val index_of_character : t -> ?from:int -> character -> int option
from
).from
: default value is 0
.
If from
is negative, 0
will be used.
If from >= length t
, None
will be returned.val index_of_character_reverse : t -> ?from:int -> character -> int option
from
: defaults to length t - 1
(end of the string).
If from
is negative, None
will be returned.
If from >= length t
, length t - 1
will be used.val index_of_string : ?from:int ->
?sub_index:int ->
?sub_length:int -> t -> sub:t -> int option
(sub, sub_index,
sub_length)
in a given string, starting at from
.sub_index
: is constrained to [0, length sub)
sub_length
: is constrained to [0, length sub - sub_index)
.
For example, if called with ~sub:"abc" ~sub_index:(-1) ~sub_length:4
then sub_index
and sub_length
will be constrained to 0
and 3
,
respectively.
If called with ~sub:"abc" ~sub_index:1 ~sub_length:3
then sub_index
and sub_length
will be constrained to 1
and 2
, respectively.
Searching for an empty string (if sub
is empty or it is constrained via
sub_index
or sub_length
) from a valid position always succeeds at
that position (ie from
).
val index_of_string_reverse : ?from:int ->
?sub_index:int ->
?sub_length:int -> t -> sub:t -> int option
sub_index
: is constrained like
index_of_string.sub_length
: is constrained like
index_of_string.val find : ?from:int ->
?length:int ->
t -> f:(character -> bool) -> int option
c
for which f c
is true
.
One can restrict to the sub-string (from, length)
(the default is to use
the whole string, “out-of-bound” values are restricted to the bounds of
the string).
val find_reverse : ?from:int ->
?length:int ->
t -> f:(character -> bool) -> int option
c
for which f c
is true
.
One can restrict to the reverse sub-string (from, length)
(the
default is to use the whole string, “out-of-bound” values are restricted
to the bounds of the string).
val filter_map : ?from:int ->
?length:int ->
t ->
f:(character -> character option) ->
t
f c
returned Some c
.
One can restrict to the sub-string (from, length)
(the default is to use
the whole string, “out-of-bound” values are restricted to the bounds of
the string).
val filter : ?from:int ->
?length:int ->
t ->
f:(character -> bool) -> t
f c
is true.
One can restrict to the sub-string (from, length)
(the default is to use
the whole string, “out-of-bound” values are restricted
to the bounds of the string).
val split : t ->
on:[ `Character of character | `String of t ] ->
t list
on
as separator.
Splitting the empty string returns []
.
Splitting with ~on:(`String empty)
explodes the t
into a list of
one-character strings.
val strip : ?on:[ `Both | `Left | `Right ] ->
?whitespace:(character -> bool) ->
t -> t
on
: defaults to `Both
.whitespace
: defaults to calling
is_whitespace of the
implemented character.module Make_output(
Model
:
Api.OUTPUT_MODEL
)
:sig
..end