Neovim-SpecSwitcher/lua/SpecSwitcher/ExtensionMap.lua
2024-10-08 22:13:30 +02:00

58 lines
1.3 KiB
Lua

local ExtMap = {}
function ExtMap:new (o)
o = o or {}
setmetatable(o, self)
self.__index = self
return o
end
function ExtMap:add_single (in_ext, out_ext)
if self[in_ext] ~= nil then
if type(out_ext) == "table" then
for _, out in ipairs(out_ext) do
table.insert(self[in_ext], out)
end
else
table.insert(self[in_ext], out_ext)
end
else
if type(out_ext) == "table" then
self[in_ext] = out_ext
else
self[in_ext] = {out_ext}
end
end
end
function ExtMap:add (in_exts, out_exts)
if type(in_exts) == "table" then
for _, in_ext in ipairs(in_exts) do
self:add_single( in_ext, out_exts)
end
else
self:add_single( in_exts, out_exts )
end
if type(out_exts) == "table" then
for _, out_ext in ipairs(out_exts) do
self:add_single( out_ext, in_exts)
end
else
self:add_single( out_exts, in_exts )
end
end
function ExtMap:print ()
base = "%s -> "
for I in pairs(self) do
local in_map = string.format(base, I)
for _, O in ipairs(self[I]) do
in_map = in_map .. O .. ","
end
print(in_map)
end
end
return ExtMap