utf8.next | Multi Theft Auto: Wiki Skip to content

utf8.next

Client-side
Server-side
Shared

This is an iteration function to traverse each single codepoint of a UTF-8 string.

Syntax

int,​ int utf8.next ( string input, [ int charpos = 0, int offset = 1 ] )
Required Arguments
  • input: A string character sequence.
Optional Arguments

NOTE: When using optional arguments, you might need to supply all arguments before the one you wish to use.

  • charpos (default: 0): An integer representing the beginning position (offset will be added/subtracted).
  • offset (default: 1): An integer representing the offset to charpos.

Returns

  • int: position
  • int: codepoint

Returns the integer position in bytes and the integer codepoint at this position, nil otherwise.

Code Examples

shared

This example shows how to traverse a UTF-8 string the proper way without running into problems as in byte strings.

for position, codepoint in utf8.next("utf8-string") do
print("Codepoint @ " .. position .. " = " .. codepoint)
end
for position, codepoint in utf8.next("Как") do
print("Codepoint @ " .. position .. " = " .. codepoint)
end