Difference between revisions of "Utf8.charpos"
From GiderosMobile
| (5 intermediate revisions by 2 users not shown) | |||
| Line 1: | Line 1: | ||
__NOTOC__ | __NOTOC__ | ||
'''Available since:''' Gideros 2016.06<br/> | '''Available since:''' Gideros 2016.06<br/> | ||
| + | '''Class:''' [[utf8]]<br/> | ||
| + | |||
=== Description === | === Description === | ||
| − | + | Converts UTF-8 position to byte offset. | |
| − | < | + | <syntaxhighlight lang="lua"> |
(number) = utf8.charpos(s,charpos,offset) | (number) = utf8.charpos(s,charpos,offset) | ||
| − | </ | + | </syntaxhighlight> |
| + | |||
| + | If only offset is given, returns byte offset of this UTF-8 char index. If charpos and offset is given, a new charpos will calculate, by add/subtract UTF-8 char offset to current charpos. In all cases, it returns a new char position, and code point (a number) at this position. | ||
| + | |||
=== Parameters === | === Parameters === | ||
| − | '''s''': (string) | + | '''s''': (string) <br/> |
| − | '''charpos''': (number) | + | '''charpos''': (number) '''optional'''<br/> |
| − | '''offset''': (number) | + | '''offset''': (number) '''optional'''<br/> |
| + | |||
=== Return values === | === Return values === | ||
| − | '''Returns''' (number) | + | '''Returns''' (number) byte offset of this UTF-8 char index<br/> |
| + | |||
| + | {{Utf8}} | ||
Latest revision as of 21:32, 1 December 2023
Available since: Gideros 2016.06
Class: utf8
Description
Converts UTF-8 position to byte offset.
(number) = utf8.charpos(s,charpos,offset)
If only offset is given, returns byte offset of this UTF-8 char index. If charpos and offset is given, a new charpos will calculate, by add/subtract UTF-8 char offset to current charpos. In all cases, it returns a new char position, and code point (a number) at this position.
Parameters
s: (string)
charpos: (number) optional
offset: (number) optional
Return values
Returns (number) byte offset of this UTF-8 char index