module String:`sig`

..`end`

Strings.

`include String`

`val head : ``string -> char option`

`head s`

if `Some s.[0]`

if `s <> ""`

and `None`

otherwise.`val of_char : ``char -> string`

`of_char c`

is `c`

as a string.`val is_prefix : ``affix:string -> string -> bool`

`is_prefix ~affix s`

is `true`

iff `affix.[i] = s.[i]`

for
all indices `i`

of `affix`

.`val is_suffix : ``affix:string -> string -> bool`

`is_suffix ~affix s`

is true iff `affix.[n - i] = s.[m - i]`

for all
indices `i`

of `affix`

with `n = String.length affix - 1`

and ```
m =
String.length s - 1
```

.`val for_all : ``(char -> bool) -> string -> bool`

`for_all p s`

is `true`

iff for all indices `i`

of `s`

, ```
p s.[i]
= true
```

.`val exists : ``(char -> bool) -> string -> bool`

`exists p s`

is `true`

iff there exists an index `i`

of `s`

with
`p s.[i] = true`

.`val with_index_range : ``?first:int -> ?last:int -> string -> string`

`with_index_range ~first ~last s`

are the consecutive bytes of `s`

whose indices exist in the range [`first`

;`last`

].
`first`

defaults to `0`

and last to `String.length s - 1`

.

Note that both `first`

and `last`

can be any integer. If
`first > last`

the interval is empty and the empty string is
returned.

`val span : ``sat:(char -> bool) -> string -> string * string`

`span ~sat s`

is `(l,r)`

where `l`

are the consecutive
initial `sat`

satisfying bytes of `s`

or the empty string
if there are no such bytes and `r`

the remaining bytes.`val take : ``sat:(char -> bool) -> string -> string`

`take ~sat s`

is `fst (span ~sat s)`

.`val drop : ``sat:(char -> bool) -> string -> string`

`drop ~sat s`

is `snd (span ~sat s)`

.`val cut : ``?rev:bool -> sep:string -> string -> (string * string) option`

`cut ~sep s`

is either the pair `Some (l,r)`

of the two
(possibly empty) substrings of `s`

that are delimited by the
first match of the separator character `sep`

or `None`

if
`sep`

can't be matched in `s`

. Matching starts from the
beginning of `s`

(`rev`

is `false`

, default) or the end (`rev`

is `true`

).
The invariant `l ^ sep ^ r = s`

holds.

**Raises** `Invalid_argument`

if `sep`

is the empty string.

`val cuts : ``?rev:bool -> ?empty:bool -> sep:string -> string -> string list`

`cuts sep s`

is the list of all substrings of `s`

that are
delimited by matches of the non empty separator string
`sep`

. Empty substrings are omitted in the list if `empty`

is
`false`

(defaults to `true`

).
Matching separators in `s`

starts from the beginning of `s`

(`rev`

is `false`

, default) or the end (`rev`

is `true`

). Once
one is found, the separator is skipped and matching starts
again, that is separator matches can't overlap. If there is no
separator match in `s`

, the list `[s]`

is returned.

The following invariants hold:

`concat ~sep (cuts ~empty:true ~sep s) = s`

`cuts ~empty:true ~sep s <> []`

`Invalid_argument`

if `sep`

is the empty string.`val map : ``(char -> char) -> string -> string`

`map f s`

is `s'`

with `s'.[i] = f s.[i]`

for all indices `i`

of
`s`

. `f`

is invoked in increasing index order.`val mapi : ``(int -> char -> char) -> string -> string`

`mapi f s`

is `s'`

with `s'.[i] = f i s.[i]`

for all indices `i`

of `s`

. `f`

is invoked in increasing index order.`val pp : ``string B0.Fmt.t`

`pp ppf s`

prints `s`

's bytes on `ppf`

.`val dump : ``string B0.Fmt.t`

`dump ppf s`

prints `s`

as a syntactically valid OCaml string
on `ppf`

.`val uniquify : ``string list -> string list`

`uniquify ss`

is `ss`

without duplicates, the list order is
preserved.`val unique : ``exists:(string -> bool) -> string -> string B0.result`

`unique ~exist n`

is `n`

if `exists n`

is `false`

or
`r = strf "%s~%d" n d`

with `d`

the smallest integer in [`1`

;`1e9`

]
such that `exists r`

is `false`

or an error if there is no such
string.`val edit_distance : ``string -> string -> int`

`edit_distance s0 s1`

is the number of single character edits (insertion,
deletion, substitution) that are needed to change `s0`

into `s1`

.`val suggest : ``?dist:int -> string list -> string -> string list`

`suggest ~dist candidates s`

are the elements of `candidates`

whose edit distance is the smallest to `s`

and
at most at a distance of `dist`

of `s`

(defaults to `2`

). If
multiple results are returned the order of `candidates`

is
preserved.`val parse_version : ``string -> (int * int * int * string option) option`

`parse_version`

parses version strings of the form:
```
"[v]major.minor[.patchlevel][+additional-info]"
```

into `(major, minor, patch, additional_info)`

tuples.`val drop_initial_v : ``string -> string`

`drop_initial_v s`

drops a leading `'v'`

or `'V'`

from `s`

.`type `

set

The type for sets of strings.

module Set:`sig`

..`end`

String sets.

`type ``+'a`

map

The type for maps from strings to values of type

`'a`

.module Map:`sig`

..`end`

String maps.