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 ===
<translate>convert UTF-8 position to byte offset. if only offset is given, return 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 case, it return a new char position, and code point (a number) at this position.</translate>
+
Converts UTF-8 position to byte offset.
<source lang="lua">
+
<syntaxhighlight lang="lua">
 
(number) = utf8.charpos(s,charpos,offset)
 
(number) = utf8.charpos(s,charpos,offset)
</source>
+
</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) <translate></translate> <br/>
+
'''s''': (string) <br/>
'''charpos''': (number) <translate></translate> '''optional'''<br/>
+
'''charpos''': (number) '''optional'''<br/>
'''offset''': (number) <translate></translate> '''optional'''<br/>
+
'''offset''': (number) '''optional'''<br/>
 +
 
 
=== Return values ===
 
=== Return values ===
'''Returns''' (number) <translate>return byte offset of this UTF-8 char index</translate><br/>
+
'''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