package batteries
Install
Dune Dependency
Authors
Maintainers
Sources
md5=1fd7bddce07cf5d244fc9427f7b5e4d4
sha512=c0f2a0fdc8253e0ea999d8d4c58bfbf32b18d251a2e1d9656bf279de5f01a33e9aabac3af4d95f465f8b671e7711ebd37218043face233340a0c11b08fa62f78
doc/batteries.unthreaded/BatUTF8/index.html
Module BatUTF8
Source
UTF-8 encoded Unicode strings. The type is normal string.
UTF-8 encoded Unicode strings. The type is normal string.
validate s
successes if s is valid UTF-8, otherwise raises Malformed_code. Other functions assume strings are valid UTF-8, so it is prudent to test their validity for strings from untrusted origins.
get s n
returns n
-th Unicode character of s
. The call requires O(n)-time.
init len f
returns a new string which contains len
Unicode characters. The i-th Unicode character is initialized by f i
Positions in the string represented by the number of bytes from the head. The location of the first character is 0
nth s n
returns the position of the n
-th Unicode character. The call requires O(n)-time
look s i
returns the Unicode character of the location i
in the string s
.
out_of_range s i
tests whether i
is a position inside of s
.
compare_index s i1 i2
returns a value < 0 if i1
is the position located before i2
, 0 if i1
and i2
points the same location, a value > 0 if i1
is the position located after i2
.
next s i
returns the position of the head of the Unicode character located immediately after i
. If i
is inside of s
, the function always successes. If i
is inside of s
and there is no Unicode character after i
, the position outside s
is returned. If i
is not inside of s
, the behaviour is unspecified.
prev s i
returns the position of the head of the Unicode character located immediately before i
. If i
is inside of s
, the function always successes. If i
is inside of s
and there is no Unicode character before i
, the position outside s
is returned. If i
is not inside of s
, the behaviour is unspecified.
move s i n
returns n
-th Unicode character after i
if n >= 0, n
-th Unicode character before i
if n < 0. If there is no such character, the result is unspecified.
iter f s
applies f
to all Unicode characters in s
. The order of application is same to the order of the Unicode characters in s
.
Code point comparison by the lexicographic order. compare s1 s2
returns a positive integer if s1
> s2
, 0 if s1
= s2
, a negative integer if s1
< s2
.