utf8codes

function utf8codes( str ) --> iter

Description

Creates a Lua iterator over all utf8 chars in a string.

Parameters

str

The utf8 string.

Return Values

iter

Lua iterator that returns each single utf8 character inside a string.

Code

--ZFUNC-utf8codes-v1
local function utf8codes( str ) --> iter
   return str:gmatch( "[%z\1-\127\194-\244][\128-\191]*" )
end

return utf8codes

Examples

local t = require( "tapered" )
local utf8codes = require( "utf8codes" )
-- util functions
local collectk = require( "collectk" )

local codes = collectk( utf8codes( "ÆØÅ" ) )
t.same( { "Æ", "Ø", "Å" }, codes )

t.done()