diff --git a/worldeditadditions/utils/strings/init.lua b/worldeditadditions/utils/strings/init.lua index 167ac70..32a8454 100644 --- a/worldeditadditions/utils/strings/init.lua +++ b/worldeditadditions/utils/strings/init.lua @@ -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") diff --git a/worldeditadditions/utils/strings/split_shell.lua b/worldeditadditions/utils/strings/split_shell.lua index e7b48c5..32d4d0d 100644 --- a/worldeditadditions/utils/strings/split_shell.lua +++ b/worldeditadditions/utils/strings/split_shell.lua @@ -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")