Minetest-WorldEditAdditions/worldeditadditions_core/utils/strings/tochars.lua

28 lines
816 B
Lua
Raw Normal View History

2021-06-03 17:02:17 +00:00
--- 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
2022-09-18 16:32:13 +00:00
function worldeditadditions_core.tochars(text,sort,rem_dups)
2021-06-22 16:33:49 +00:00
local t, set = {}, {}
2021-06-03 17:02:17 +00:00
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
2021-06-22 16:33:49 +00:00
--- Split into a set of characters.
2021-06-22 16:33:49 +00:00
-- @param text string The string to iterate over
-- @returns table A sequence set table containing the substrings
2022-09-18 16:32:13 +00:00
function worldeditadditions_core.tocharset(text)
2021-06-22 16:33:49 +00:00
local t = {}
text:gsub(".",function(c) t[c] = true end)
return t
end