mirror of
https://github.com/sbrl/Minetest-WorldEditAdditions.git
synced 2024-12-23 12:05:01 +00:00
Integrate split_shell into worldeditadditions
...it's not used anywhere yet though
This commit is contained in:
parent
b708fec2db
commit
bd1da727a4
2 changed files with 26 additions and 28 deletions
|
@ -1,3 +1,6 @@
|
||||||
dofile(worldeditadditions.modpath.."/utils/strings/split.lua")
|
local wea = worldeditadditions
|
||||||
dofile(worldeditadditions.modpath.."/utils/strings/polyfill.lua")
|
|
||||||
dofile(worldeditadditions.modpath.."/utils/strings/tochars.lua")
|
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")
|
||||||
|
|
|
@ -1,17 +1,10 @@
|
||||||
function is_whitespace(char)
|
local table_map = dofile(worldeditadditions.modpath.."/utils/tables/table_map.lua")
|
||||||
return char == " " or char == "\t" or char == "\r" or char == "\n"
|
|
||||||
|
local function is_whitespace(char)
|
||||||
|
return char:match("%s")
|
||||||
end
|
end
|
||||||
|
|
||||||
local function table_map(tbl, func)
|
local function split_shell(text)
|
||||||
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 text_length = #text
|
local text_length = #text
|
||||||
local scan_pos = 1
|
local scan_pos = 1
|
||||||
local result = { }
|
local result = { }
|
||||||
|
@ -76,17 +69,19 @@ function split_shell(text)
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
function test(text)
|
return split_shell
|
||||||
print("Source", text)
|
|
||||||
for i,value in ipairs(split_shell(text)) do
|
|
||||||
print("i", i, "→", value)
|
|
||||||
end
|
|
||||||
print("************")
|
|
||||||
end
|
|
||||||
|
|
||||||
test("yay yay yay")
|
-- function test(text)
|
||||||
test("yay \"yay yay\" yay")
|
-- print("Source", text)
|
||||||
test("yay \"yay\\\" yay\" yay")
|
-- for i,value in ipairs(split_shell(text)) do
|
||||||
test("yay \"yay 'inside quotes' yay\\\"\" yay")
|
-- print("i", i, "→", value)
|
||||||
test("yay 'inside quotes' another")
|
-- end
|
||||||
test("y\"ay \"yay 'in\\\"side quotes' yay\" y\\\"ay")
|
-- 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")
|
||||||
|
|
Loading…
Reference in a new issue