Difference between revisions of "Utf8.next"

From GiderosMobile
 
(7 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 ===
Iterate though the UTF-8 string s. If only s is given, it can used as a iterator:
+
Iterates through the UTF-8 string ''s''.
 +
<syntaxhighlight lang="lua">
 +
(varies) = utf8.next(s,charpos,offset)
 +
</syntaxhighlight>
 +
 
 +
If only ''s'' is given, it can used as a iterator:
 +
<syntaxhighlight lang="lua">
 
for pos, code in utf8.next, "utf8-string" do
 
for pos, code in utf8.next, "utf8-string" do
 
-- ...
 
-- ...
 
end
 
end
if only charpos is given, return the next byte offset of in string. 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 (in bytes), and code point (a number) at this position.
+
</syntaxhighlight>
<source lang="lua">
+
 
(varies) = utf8.next(s,charpos,offset)
+
If only ''charpos'' is given, returns the next byte offset of in string.
</source>
+
 
'''s''': (string) ''''''<br/>
+
If ''charpos'' and ''offset'' are given, a new charpos will be calculated, by add/subtract UTF-8 char offset to current charpos.
'''charpos''': (number) '''optional'''<br/>
+
 
'''offset''': (number) '''optional'''<br/>
+
In all cases, it returns a new char position (in bytes), and code point (a number) at this position.
 +
 
 +
=== Parameters ===
 +
'''s''': (string) <br/>
 +
'''charpos''': (number) '''optional'''<br/>
 +
'''offset''': (number) '''optional'''<br/>
 +
 
 +
=== Return values ===
 
'''Returns''' (varies) next iteration<br/>
 
'''Returns''' (varies) next iteration<br/>
 +
 +
{{Utf8}}

Latest revision as of 22:08, 1 December 2023

Available since: Gideros 2016.06
Class: utf8

Description

Iterates through the UTF-8 string s.

(varies) = utf8.next(s,charpos,offset)

If only s is given, it can used as a iterator:

for pos, code in utf8.next, "utf8-string" do
-- ...
end

If only charpos is given, returns the next byte offset of in string.

If charpos and offset are given, a new charpos will be calculated, by add/subtract UTF-8 char offset to current charpos.

In all cases, it returns a new char position (in bytes), and code point (a number) at this position.

Parameters

s: (string)
charpos: (number) optional
offset: (number) optional

Return values

Returns (varies) next iteration