Module:Utils

local p = {}

-- http://lua-users.org/wiki/StringTrim function trim(s) return (s:gsub("^%s*(.-)%s*$", "%1")) end

-- http://stackoverflow.com/questions/1426954/split-string-in-lua function split(inputstr, sep) if sep == nil then sep = "%s" end local t={} ; i=1 for str in string.gmatch(inputstr, "([^"..sep.."]+)") do       t[i] = str i = i + 1 end return t end

-- http://stackoverflow.com/questions/2705793/how-to-get-number-of-entries-in-a-lua-table function tablelength(table) local count = 0 for _ in pairs(table) do       count = count + 1 end return count end

function p.filetype(frame) local str = frame.args[1] local spl = split(str, ',') local res = '' for key, value in pairs(spl) do       res = res .. ' '   end return frame:preprocess(res:sub(0, -7)) end

function p.items(frame) local str = frame.args[1] if str == '-' then return 'N/A' end local spl = split(str, ',') local res = '' for key, value in pairs(spl) do       res = res .. ''   end return frame:preprocess(res) end

function p.item_name(frame) local str = trim(frame.args[1]) if str:sub(0, 1) == '+' then return frame:preprocess(' ' .. str:sub(2) .. ' ') end return str end

function p.item_id(frame) local subd, _ = trim(frame.args[1]:lower):gsub(' ', '_') subd, _ = subd:gsub('\, ) return subd end

return p