mirror of
https://github.com/sbrl/Minetest-WorldEditAdditions.git
synced 2024-11-21 23:13:00 +00:00
split tochars to separate file
This commit is contained in:
parent
622ea7a683
commit
7553163e11
3 changed files with 20 additions and 20 deletions
|
@ -1,2 +1,3 @@
|
|||
dofile(worldeditadditions.modpath.."/utils/strings/split.lua")
|
||||
dofile(worldeditadditions.modpath.."/utils/strings/polyfill.lua")
|
||||
dofile(worldeditadditions.modpath.."/utils/strings/tochars.lua")
|
||||
|
|
|
@ -55,23 +55,3 @@ function worldeditadditions.split(text, pattern, plain)
|
|||
end
|
||||
return ret
|
||||
end
|
||||
|
||||
-- Split into table of characters.
|
||||
-- @param text string The string to iterate over
|
||||
-- @param s bool Sort characters
|
||||
-- @param d bool Remove duplicate characters
|
||||
-- @returns table A sequence table containing the substrings
|
||||
function worldeditadditions.tochars(text,s,d)
|
||||
--function tochars(text,s,d)
|
||||
t, set = {}, {}
|
||||
if d 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 s then table.sort(t) end
|
||||
|
||||
return t
|
||||
end
|
||||
|
|
19
worldeditadditions/utils/strings/tochars.lua
Normal file
19
worldeditadditions/utils/strings/tochars.lua
Normal file
|
@ -0,0 +1,19 @@
|
|||
--- 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)
|
||||
--function tochars(text,s,d)
|
||||
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
|
Loading…
Reference in a new issue