From 7553163e11e5fa7ce78bf0c0cbcd85e1e24c18ca Mon Sep 17 00:00:00 2001 From: VorTechnix <45538536+VorTechnix@users.noreply.github.com> Date: Thu, 3 Jun 2021 10:02:17 -0700 Subject: [PATCH] split tochars to separate file --- worldeditadditions/utils/strings/init.lua | 1 + worldeditadditions/utils/strings/split.lua | 20 -------------------- worldeditadditions/utils/strings/tochars.lua | 19 +++++++++++++++++++ 3 files changed, 20 insertions(+), 20 deletions(-) create mode 100644 worldeditadditions/utils/strings/tochars.lua diff --git a/worldeditadditions/utils/strings/init.lua b/worldeditadditions/utils/strings/init.lua index c62cc67..167ac70 100644 --- a/worldeditadditions/utils/strings/init.lua +++ b/worldeditadditions/utils/strings/init.lua @@ -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") diff --git a/worldeditadditions/utils/strings/split.lua b/worldeditadditions/utils/strings/split.lua index 1fe9fae..69e5518 100644 --- a/worldeditadditions/utils/strings/split.lua +++ b/worldeditadditions/utils/strings/split.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 diff --git a/worldeditadditions/utils/strings/tochars.lua b/worldeditadditions/utils/strings/tochars.lua new file mode 100644 index 0000000..7398868 --- /dev/null +++ b/worldeditadditions/utils/strings/tochars.lua @@ -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