Utf8.offset: Difference between revisions
From GiderosMobile
Created page with "__NOTOC__ '''Available since:''' Gideros 2016.06<br/> === Description === Returns the position (in bytes) where the encoding of the n-th character of s (counting from position..." |
No edit summary |
||
| Line 6: | Line 6: | ||
This function assumes that s is a valid UTF-8 string. | This function assumes that s is a valid UTF-8 string. | ||
<source lang="lua"> | <source lang="lua"> | ||
(number) | (number) = utf8.offset(s,n,i) | ||
</source> | </source> | ||
'''s | '''s''': (string) ''''''<br/> | ||
'''n | '''n''': (number) ''''''<br/> | ||
'''i | '''i''': (number) '''optional'''<br/> | ||
'''Returns''' (number) position (in bytes)<br/> | '''Returns''' (number) position (in bytes)<br/> | ||
Revision as of 09:21, 23 August 2018
Available since: Gideros 2016.06
Description
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.
(number) = utf8.offset(s,n,i)
's: (string) '
'n: (number) '
i: (number) optional
Returns (number) position (in bytes)