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.
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.
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.
trim is like String.trim. If all bytes are dropped returns an empty string located in the middle of the argument.
val span :
?rev:bool ->?min:int ->?max:int ->?sat:(char -> bool)->sub->sub * sub
span is like String.span. For a substring s a left empty span is start s and a right empty span is stop s.
val take :
?rev:bool ->?min:int ->?max:int ->?sat:(char -> bool)->sub->sub
take is like String.take.
val drop :
?rev:bool ->?min:int ->?max:int ->?sat:(char -> bool)->sub->sub
drop is like String.drop.
val cut : ?rev:bool ->sep:sub->sub->(sub * sub) option
cut is like String.cut. sep can be on a different base string
val cuts : ?rev:bool ->?empty:bool ->sep:sub->sub->sub list
cuts is like String.cuts. sep can be on a different base string
val fields : ?empty:bool ->?is_sep:(char -> bool)->sub->sub list
fields is like String.fields.
Traversing substrings
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, defaults) or before stop s (rev is false). 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.
+---+---+---+---+---+---+---+---+---+---+---+
| 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