Difference between revisions of "Utf8.charpos"

From GiderosMobile
 
(2 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
__NOTOC__
 
__NOTOC__
<languages />
+
'''Available since:''' Gideros 2016.06<br/>
'''<translate>Available since</translate>:''' Gideros 2016.06<br/>
+
'''Class:''' [[utf8]]<br/>
'''<translate>Class</translate>:''' [[Special:MyLanguage/utf8|utf8]]<br/>
+
 
=== <translate>Description</translate> ===
+
=== 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>
=== <translate>Parameters</translate> ===
+
 
'''s''': (string) <translate></translate> <br/>
+
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.
'''charpos''': (number) <translate></translate> '''optional'''<br/>
+
 
'''offset''': (number) <translate></translate> '''optional'''<br/>
+
=== Parameters ===
=== <translate>Return values</translate> ===
+
'''s''': (string) <br/>
'''<translate>Returns</translate>''' (number) <translate>return byte offset of this UTF-8 char index</translate><br/>
+
'''charpos''': (number) '''optional'''<br/>
 +
'''offset''': (number) '''optional'''<br/>
 +
 
 +
=== Return values ===
 +
'''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