Integrate split_shell into worldeditadditions

...it's not used anywhere yet though
This commit is contained in:
Starbeamrainbowlabs 2021-07-28 18:32:41 +01:00
parent b708fec2db
commit bd1da727a4
Signed by: sbrl
GPG Key ID: 1BE5172E637709C2
2 changed files with 26 additions and 28 deletions

View File

@ -1,3 +1,6 @@
dofile(worldeditadditions.modpath.."/utils/strings/split.lua")
dofile(worldeditadditions.modpath.."/utils/strings/polyfill.lua")
dofile(worldeditadditions.modpath.."/utils/strings/tochars.lua")
local wea = worldeditadditions
dofile(wea.modpath.."/utils/strings/split.lua")
dofile(wea.modpath.."/utils/strings/polyfill.lua")
dofile(wea.modpath.."/utils/strings/tochars.lua")
wea.split_shell = dofile(wea.modpath.."/utils/strings/split_shell.lua")

View File

@ -1,17 +1,10 @@
function is_whitespace(char)
return char == " " or char == "\t" or char == "\r" or char == "\n"
local table_map = dofile(worldeditadditions.modpath.."/utils/tables/table_map.lua")
local function is_whitespace(char)
return char:match("%s")
end
local function table_map(tbl, func)
local result = {}
for i,value in ipairs(tbl) do
local newval = func(value, i)
if newval ~= nil then table.insert(result, newval) end
end
return result
end
function split_shell(text)
local function split_shell(text)
local text_length = #text
local scan_pos = 1
local result = { }
@ -76,17 +69,19 @@ function split_shell(text)
end)
end
function test(text)
print("Source", text)
for i,value in ipairs(split_shell(text)) do
print("i", i, "", value)
end
print("************")
end
return split_shell
test("yay yay yay")
test("yay \"yay yay\" yay")
test("yay \"yay\\\" yay\" yay")
test("yay \"yay 'inside quotes' yay\\\"\" yay")
test("yay 'inside quotes' another")
test("y\"ay \"yay 'in\\\"side quotes' yay\" y\\\"ay")
-- function test(text)
-- print("Source", text)
-- for i,value in ipairs(split_shell(text)) do
-- print("i", i, "→", value)
-- end
-- print("************")
-- end
--
-- test("yay yay yay")
-- test("yay \"yay yay\" yay")
-- test("yay \"yay\\\" yay\" yay")
-- test("yay \"yay 'inside quotes' yay\\\"\" yay")
-- test("yay 'inside quotes' another")
-- test("y\"ay \"yay 'in\\\"side quotes' yay\" y\\\"ay")