Legend:
Library
Module
Module type
Parameter
Class
Class type
Substrings.
A substring defines a possibly empty subsequence of bytes in a base string.
The positions of a string s of length l are the slits found before each byte and after the last byte of the string. They are labelled from left to right by increasing number in the range [0;l].
The ith byte index is between positions i and i+1.
Formally we define a substring of s as being a subsequence of bytes defined by a start and a stop position. The former is always smaller or equal to the latter. When both positions are equal the substring is empty. Note that for a given base string there are as many empty substrings as there are positions in the string.
Like in strings, we index the bytes of a substring using zero-based indices.
tail s is s without its first (rev is false, default) or last (rev is true) byte or s if it is empty.
val extend : ?rev:bool ->?max:int ->?sat:(char -> bool)->sub->sub
extend ~rev ~max ~sat s extends s by at most max consecutive sat satisfiying bytes of the base string located after stop s (rev is false, default) or before start s (rev is true). If max is unspecified the extension is limited by the extents of the base string of s. sat defaults to fun _ -> true.
raisesInvalid_argument
if max is negative.
val reduce : ?rev:bool ->?max:int ->?sat:(char -> bool)->sub->sub
reduce ~rev ~max ~sat s reduces s by at most max consecutive sat satisfying bytes of s located before stop
s (rev is false, default) or after start s (rev is true). If max is unspecified the reduction is limited by the extents of the substring s. sat defaults to fun _ ->
true.
overlap s s' is the smallest substring that includes all the positions common to s and s' or None if there are no such positions. Note that the overlap substring may be empty.
raisesInvalid_argument
if s and s' are not on the same base string according to physical equality.
concat ~sep ss is like String.concat. The substrings can all be on different bases and the result is on a base string that holds exactly the concatenated bytes.
val find : ?rev:bool ->(char -> bool)->sub->sub option
find ~rev sat s is the substring of s (if any) that spans the first byte that satisfies sat in s after position start s (rev is false, default) or before stop s (rev is true). None is returned if there is no matching byte in s.
val find_sub : ?rev:bool ->sub:sub->sub->sub option
find_sub ~rev ~sub s is the substring of s (if any) that spans the first match of sub in s after position start s (rev is false, default) or before stop s (rev is true). Only bytes are compared and sub can be on a different base string. None is returned if there is no match of sub in s.
mapi is like String.mapi. The result is on a base string that holds only the mapped bytes. The indices are the substring's zero-based ones, not those in the base string.
to_float s is a float from s, if any. Relies on Stdlib.float_of_string.
Substring stretching graphical guide
+---+---+---+---+---+---+---+---+---+---+---+
| R | e | v | o | l | t | | n | o | w | ! |
+---+---+---+---+---+---+---+---+---+---+---+
|---------------| a
| start a
| stop a
|-----------| tail a
|-----------| tail ~rev:true a
|-----------------------------------| extend a
|-----------------------| extend ~rev:true a
|-------------------------------------------| base a
|-----------| b
| start b
| stop b
|-------| tail b
|-------| tail ~rev:true b
|-------------------------------------------| extend b
|-----------| extend ~rev:true b
|-------------------------------------------| base b
|-----------------------| extent a b
|---| overlap a b
| c
| start c
| stop c
| tail c
| tail ~rev:true c
|---------------| extend c
|---------------------------| extend ~rev:true c
|-------------------------------------------| base c
|-------------------| extent a c
None overlap a c
|---------------| d
| start d
| stop d
|-----------| tail d
|-----------| tail ~rev:true d
|---------------| extend d
|-------------------------------------------| extend ~rev:true d
|-------------------------------------------| base d
|---------------| extent d c
| overlap d c