package brr
Install
dune-project
Dependency
Authors
Maintainers
Sources
sha512=49e7bfbad2ea6a0139354e4a33c59c8a113c4c1e20a4f629bc5cad24aa801e474b4af10ce35adbda5d23dd294d1de5efa5b10bb3030d03f4758459977250a0f6
doc/brr/Jstr/index.html
Module JstrSource
JavaScript strings
The type for JavaScript UTF-16 encoded strings.
Constants
Assembling
concat ?sep ss is the concatenates the list of strings ss inserting sep between each of them (defaults to empty).
pad_start ~pad n s is s with pad strings prepended to s until the length of the result is n or s if length s >= n. The first prepended pad may be truncated to satisfy the constraint. pad defaults to sp.
Warning. Since length is neither the number of Unicode characters of s nor its number of grapheme clusters, if you are using this for visual layout, it will fail in many cases. At least consider normalizing s to `NFC before.
pad_end ~pad n s is s with pad strings appended to s until the length of the result is n or s if length s >= n. The last appended pad may be truncated to satisfy the constraint. pad defaults to sp.
Warning. Since length is neither the number of Unicode characters of s nor its number of grapheme clusters, if you are using this for visual layout, it will fail in many cases. At least consider normalizing s to `NFC before.
Finding
find_sub ~start ~sub s is the start index (if any) of the first occurence of sub in s at or after start .
find_last_sub ~before ~sub s is the start index (if any) of the last occurence of sub in s before before (defaults to length s).
Breaking
slice ~start ~stop s is the string s.start, s.start+1, ... s.stop - 1. start defaults to 0 and stop to length s.
If start or stop are negative they are subtracted from length s. This means that -1 denotes the last character of the string.
sub ~start ~len s is the string s.start, ... s.start + len - 1. start default to 0 and len to length s - start.
If start is negative it is subtracted from length s. This means that -1 denotes the last character of the string. If len is negative it is treated as 0.
cuts sep s is the list of all (possibly empty) substrings of s that are delimited by matches of the non empty separator string sep.
Traversing and transforming
fold_uchars f acc s folds f over the Unicode characters of s starting with acc. Decoding errors (that is unpaired UTF-16 surrogates) are reported as Uchar.rep.
fold_jstr_uchars is like fold_uchars but the characters are given as strings.
Normalization
For more information on normalization consult a short introduction, the UAX #15 Unicode Normalization Forms and normalization charts.
The type for normalization forms.
`NFDnormalization form D, canonical decomposition.`NFCnormalization form C, canonical decomposition followed by canonical composition.`NFKDnormalization form KD, compatibility decomposition.`NFKCnormalization form KC, compatibility decomposition, followed by canonical composition.
normalized nf t is t normalized to nf.
Case mapping
For more information about case see the Unicode case mapping FAQ and the case mapping charts. Note that these algorithms are insensitive to language and context and may produce sub-par results for some users.
lowercased s is s lowercased according to Unicode's default case conversion.
lowercased s is s uppercased according to Unicode's default case conversion.
Predicates and comparisons
starts_with ~prefix s is true iff s starts with prefix (as per equal).
includes ~suffix s is true iff s includes affix (as per equal).
ends_with ~suffix s is true iff s ends with suffix (as per equal).
equal s0 s1 is true iff s0 and s1 are equal. Warning. Unless s0 and s1 are known to be in a particular normal form the test is textually meaningless.
compare s0 s1 is a total order on strings compatible with equal. Warning. The comparison is textually meaningless.
Conversions
of_string s is the UTF-8 encoded OCaml string s as a JavaScript string.
binary_to_octets s is the JavaScript binary string s as an OCaml string of bytes. In s each 16-bit JavaScript character encodes a byte.
binary_of_octets s is the OCaml string of bytes s as a JavaScript binary string in which each 16-bit character encodes a byte.
to_int s is the integer resulting from parsing s as a number in base base (guessed by default). The function uses Number.parseInt and maps Float.nan results to None.
of_int ~base i formats i as a number in base base (defaults to 10). Conversion is performed via Number.toString.
to_float s is the floating point number resulting from parsing s. This always succeeds and returns Float.nan on unparseable inputs. The function uses Number.parseFloat.
of_float ~frac n formats n with frac fixed fractional digits (or as needed if unspecified). This function uses Number.toFixed if f is specified and Number.toString otherwise.