Difference between revisions of "Utf8.next"
From GiderosMobile
(6 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 === | ||
− | + | 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 | ||
− | + | </syntaxhighlight> | |
− | + | ||
− | + | 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 === | === Parameters === | ||
− | '''s''': (string) | + | '''s''': (string) <br/> |
− | '''charpos''': (number) | + | '''charpos''': (number) '''optional'''<br/> |
− | '''offset''': (number) | + | '''offset''': (number) '''optional'''<br/> |
+ | |||
=== Return values === | === 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