mirror of
https://github.com/appgurueu/modlib.git
synced 2024-11-22 15:23:48 +01:00
Add text.i(chars|bytes)
This commit is contained in:
parent
3d585154eb
commit
53bb6915db
22
text.lua
22
text.lua
@ -123,5 +123,27 @@ function is_identifier(text)
|
|||||||
return (not keywords[text]) and text:match"^[A-Za-z_][A-Za-z%d_]*$"
|
return (not keywords[text]) and text:match"^[A-Za-z_][A-Za-z%d_]*$"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function inextchar(text, i)
|
||||||
|
if i >= #text then return end
|
||||||
|
i = i + 1
|
||||||
|
return i, text:sub(i, i)
|
||||||
|
end
|
||||||
|
|
||||||
|
function ichars(text, start)
|
||||||
|
-- Iterator over `index, character`
|
||||||
|
return inextchar, text, (start or 1) - 1
|
||||||
|
end
|
||||||
|
|
||||||
|
local function inextbyte(text, i)
|
||||||
|
if i >= #text then return end
|
||||||
|
i = i + 1
|
||||||
|
return i, text:byte(i, i)
|
||||||
|
end
|
||||||
|
|
||||||
|
function ibytes(text, start)
|
||||||
|
-- Iterator over `index, byte`
|
||||||
|
return inextbyte, text, (start or 1) - 1
|
||||||
|
end
|
||||||
|
|
||||||
-- Export environment
|
-- Export environment
|
||||||
return _ENV
|
return _ENV
|
||||||
|
Loading…
Reference in New Issue
Block a user