LuaSTG-x Core API
utf8 Class Reference

Public Member Functions

static function char (local ...)
 
static function codepoint (local s, local i, local j)
 
static function codes (local s)
 The pattern (a string, not a function) "[\0-\x7F\xC2-\xF4][\x80-\xBF]*" (see §6.4.1), which matches exactly one UTF-8 byte sequence, assuming that the subject is a valid UTF-8 string. More...
 
static function len (local s, local i, local j)
 
static function offset (local s, local n, local i)
 

Member Function Documentation

◆ char()

static function char ( local ...  )

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.

Returns
string

◆ codepoint()

static function codepoint ( local  s,
local  i,
local  j 
)

Returns the codepoints (as integers) from all characters in s that start between byte position i and j (both included). The default for i is 1 and for j is i. It raises an error if it meets any invalid byte sequence.

Parameters
sstring
inumber optional
jnumber optional

◆ codes()

static function codes ( local  s)

The pattern (a string, not a function) "[\0-\x7F\xC2-\xF4][\x80-\xBF]*" (see §6.4.1), which matches exactly one UTF-8 byte sequence, assuming that the subject is a valid UTF-8 string.

Returns values so that the construction

for p, c in utf8.codes(s) do body end

will iterate over all characters in string s, with p being the position (in bytes) and c the code point of each character. It raises an error if it meets any invalid byte sequence.

Parameters
sstring

◆ len()

static function len ( local  s,
local  i,
local  j 
)

Returns the number of UTF-8 characters in string s that start between positions i and j (both inclusive). The default for i is 1 and for j is -1. If it finds any invalid byte sequence, returns a false value plus the position of the first invalid byte.

Parameters
sstring
inumber optional
jnumber optional
Returns
number

◆ offset()

static function offset ( local  s,
local  n,
local  i 
)

Returns the position (in bytes) where the encoding of the n-th character of s (counting from position i) starts. A negative n gets characters before position i. The default for i is 1 when n is non-negative and #s + 1 otherwise, so that utf8.offset(s, -n) gets the offset of the n-th character from the end of the string. If the specified character is neither in the subject nor right after its end, the function returns nil.

As a special case, when n is 0 the function returns the start of the encoding of the character that contains the i-th byte of s.

This function assumes that s is a valid UTF-8 string.

Parameters
sstring
nnumber
inumber optional
Returns
number

The documentation for this class was generated from the following file:
utf8
Definition: utf8.lua.hpp:7
utf8::codes
static function codes(local s)
The pattern (a string, not a function) "[\0-\x7F\xC2-\xF4][\x80-\xBF]*" (see §6.4....
Definition: utf8.lua.hpp:33