Expand description
Basic support for UTF-8 encoding.
This library does not provide any support for Unicode other than the handling of the encoding itself. Any operation that needs the meaning of a character, such as character classification, is outside its scope.
Unless stated otherwise, all functions that expect a byte position as a parameter assume that the given position is either the start of a byte sequence or one plus the length of the subject string.
Constants§
- charpattern
- The pattern
"[\0-\x7F\xC2-\xFD][\x80-\xBF]*", which matches exactly one UTF-8 byte sequence, assuming that the subject is a valid UTF-8 string.
Functions§
- char
- Receives zero or more integers, converts each one to its corresponding UTF-8 byte sequence, and returns a string with the concatenation of all these sequences.
- codepoint
- Returns the code points (as integers) from all characters in
sthat start between byte positionsiandj(both included). The default foriis 1 and forjisi. It raises an error if it meets any invalid byte sequence. - codes
- Returns values so that the construction
- len
- Returns the number of UTF-8 characters in string
sthat start between byte positionsiandj(default 1 and −1). If it finds any invalid byte sequence, returnsnilplus the position of the first invalid byte. - offset
- Returns the position (in bytes) where the encoding of the
n-th character ofs(counting from byte positioni) starts, and — since Lua 5.5 — also the position of the final byte of that character. A negativengets characters before positioni.utf8.offset(s, -1)gets the last character of the string.