Difference between revisions of "Utf8.widthindex"

From GiderosMobile
(Created page with "__NOTOC__ '''Available since:''' Gideros 2016.06<br/> === Description === Return the character index at given location in string s. this is a reverse operation of utf8.width()...")
 
 
(8 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 ===
Return the character index at given location in string s. this is a reverse operation of utf8.width(). this function return a index of location, and a offset in in UTF-8 encoding. e.g. if cursor is at the second column (middle) of the wide char, offset will be 2. the width of character at idx is returned, also.
+
Returns the character index at given ''location'' in string ''s''. This is a reverse operation of utf8.width().
<source lang="lua">
+
<syntaxhighlight lang="lua">
(number), = utf8.widthindex(slocationambi_is_doubledefault_width,)
+
(number) = utf8.widthindex(s,location,ambi_is_double,default_width)
</source>
+
</syntaxhighlight>
'''s:''' (string) ''''''<br/>
+
 
'''location:''' (number) ''''''<br/>
+
This function returns an index of location, and an offset in in UTF-8 encoding. e.g. if cursor is at the second column (middle) of the wide char, offset will be 2. The width of character index is also returned.
'''ambi_is_double:''' (boolean) '''optional'''<br/>
+
 
'''default_width:''' (number) '''optional'''<br/>
+
=== Parameters ===
 +
'''s''': (string) <br/>
 +
'''location''': (number) <br/>
 +
'''ambi_is_double''': (boolean) '''optional'''<br/>
 +
'''default_width''': (number) '''optional'''<br/>
 +
 
 +
=== Return values ===
 
'''Returns''' (number) character index at given location<br/>
 
'''Returns''' (number) character index at given location<br/>
 +
 +
{{Utf8}}

Latest revision as of 23:27, 1 December 2023

Available since: Gideros 2016.06
Class: utf8

Description

Returns the character index at given location in string s. This is a reverse operation of utf8.width().

(number) = utf8.widthindex(s,location,ambi_is_double,default_width)

This function returns an index of location, and an offset in in UTF-8 encoding. e.g. if cursor is at the second column (middle) of the wide char, offset will be 2. The width of character index is also returned.

Parameters

s: (string)
location: (number)
ambi_is_double: (boolean) optional
default_width: (number) optional

Return values

Returns (number) character index at given location