Module:Utils

local p = {};

function p.toTable(s,delimiter1,delimiter2,delimiter3) local result = {}; delimiter1 = delimiter1 or ','; delimiter2 = delimiter2 or '\\='; delimiter3 = delimiter3 or ';'; local ind = ''; for match1 in (s..delimiter1):gmatch("(.-)"..delimiter1) do   	for match2 in (match1..delimiter2):gmatch("(.-)"..delimiter2) do    		if ind == '' then ind = match2; else result[ind] = match2; ind = ''; end end end if (delimiter3 ~= '') then for k,v in pairs(result) do	       result[k] = string.gsub(v,delimiter3,','); end end return result; end

function p.toNumberedTable(s, delimiter1) local result = {}; delimiter1 = delimiter1 or '/'; for match1 in (s..delimiter1):gmatch("(.-)"..delimiter1) do   	result[#result+1] = match1; end return result; end

function p.trimBrackets(s) local ls = string.gsub(s,"%[",''); local rs = string.gsub(ls,"%]",''); return rs; end

function p.toBoolean(s) if (type(s)=="string" and s=="true") or (type(s)=="number" and s==1) then return true; else return false; end end

return p