mirror of
https://github.com/sbrl/Minetest-WorldEditAdditions.git
synced 2024-11-09 17:03:45 +01:00
a40b65af3e
Co-authored-by: Starbeamrainbowlabs <sbrl@starbeamrainbowlabs.com>
29 lines
832 B
Lua
29 lines
832 B
Lua
--- Split into table of characters.
|
|
-- @param text string The string to iterate over
|
|
-- @param sort bool Sort characters
|
|
-- @param rem_dups bool Remove duplicate characters
|
|
-- @returns table A sequence table containing the substrings
|
|
function worldeditadditions.tochars(text,sort,rem_dups)
|
|
local t, set = {}, {}
|
|
if rem_dups then
|
|
text:gsub(".",function(c) set[c] = true end)
|
|
for k,v in pairs(set) do table.insert(t,k) end
|
|
else
|
|
text:gsub(".",function(c) table.insert(t,c) end)
|
|
end
|
|
|
|
if sort then table.sort(t) end
|
|
|
|
return t
|
|
end
|
|
|
|
--- Split into set of characters.
|
|
-- @param text string The string to iterate over
|
|
-- @returns table A sequence set table containing the substrings
|
|
function worldeditadditions.tocharset(text)
|
|
-- function tocharset(text)
|
|
local t = {}
|
|
text:gsub(".",function(c) t[c] = true end)
|
|
return t
|
|
end
|