UTF-8 enoded strings
Type of UTF-8 encoded strings.
Invalid(error, text)
Exception raised when an invalid UTF-8
encoded string is encountered. text
is the faulty text and
error
is a description of the first error in text
.
Exception raised when trying to access a character which is outside the bounds of a string.
Same as check but raises an exception in case the argument is not a valid text, otherwise returns the length of the string.
next_error str ofs
returns (ofs', count, msg)
where ofs'
is the offset of the start of the first invalid sequence after
ofs
(inclusive) in str
, count
is the number of unicode
character between ofs
and ofs'
(exclusive) and msg
is an
error message. If there is no error until the end of string then
ofs
is String.length str
and msg
is the empty string.
singleton ch
creates a string of length 1 containing only the
given character.
make n ch
creates a string of length n
filled with ch
.
init n f
returns the contenation of singleton (f 0)
,
singleton (f 1)
, ..., singleton (f (n - 1))
.
rev_init n f
returns the contenation of singleton (f (n -
1))
, ..., singleton (f 1)
, singleton (f 0)
.
get str idx
returns the character at index idx
in
str
.
explode str
returns the list of all characters of str
.
rev_explode str
returns the list of all characters of str
in
reverse order.
implode l
returns the concatenation of all characters of l
.
rev_implode l
is the same as implode (List.rev l)
but more
efficient.
iter f str
applies f
an all characters of str
starting
from the left.
rev_iter f str
applies f
an all characters of str
starting
from the right.
fold f str acc
applies f
on all characters of str
starting from the left, accumulating a value.
rev_fold f str acc
applies f
on all characters of str
starting from the right, accumulating a value.
map f str
maps all characters of str
with f
.
rev_map f str
maps all characters of str
with f
in reverse
order.
filter f str
filters characters of str
with f
.
rev_filter f str
filters characters of str
with f
in
reverse order.
filter_map f str
filters and maps characters of str
with
f
.
rev_filter_map f str
filters and maps characters of str
with
f
in reverse order.
for_all f text
returns whether all characters of text
verify
the predicate f
.
exists f text
returns whether at least one character of text
verify f
.
count f text
returhs the number of characters of text
verifying f
.
strip ?predicate text
returns text
without its firsts and
lasts characters that match predicate
. predicate
default to
testing whether the given character has the `White_Space
unicode property. For example:
strip "\n foo\n " = "foo"
add buf ch
is the same as Buffer.add_string buf (singleton
ch)
but is more efficient.
escaped_char ch
returns a string containg ch
or an escaped
version of ch
if:
ch
is a control character (code < 32)ch
is the character with code 127ch
is a non-ascii, non-alphabetic characterIt uses the syntax \xXX
, \uXXXX
, \UXXXXXX
or a specific
escape sequence \n, \r, ...
.
add_escaped_char buf ch
is the same as Buffer.add_string buf
(escaped_char ch)
but a bit more efficient.
escaped_string enc str
escape the string str
which is
encoded with encoding enc
. If decoding str
with enc
fails,
it escape all non-printable bytes of str
with the syntax
\yAB
.
add_escaped_char buf enc text
is the same as
Buffer.add_string buf (escaped_string enc text)
but a bit more
efficient.
extract str ofs
returns the code-point at offset ofs
in
str
.
extract_next str ofs
returns the code-point at offset ofs
in
str
and the offset the next character.
extract_prev str ofs
returns the code-point at the previous
offset in str
and this offset.
These functions does not check that the given offset is inside the bounds of the given string.
unsafe_next str ofs
returns the offset of the next character
in str
.
unsafe_prev str ofs
returns the offset of the previous
character in str
.
unsafe_extract str ofs
returns the code-point at offset ofs
in str
.
unsafe_extract_next str ofs
returns the code-point at offset
ofs
in str
and the offset the next character.
unsafe_extract_prev str ofs
returns the code-point at the
previous offset in str
and this offset.