lol = {};

function lol:getQueryParams(query)
        if type(query) == "string" and #query > 0 then
                if query:match("=") then
                        local params = {};
                        for k, v in query:gmatch("&?([^=%?]+)=([^&%?]+)&?") do
                                if k and v then
                                        params[self:urldecode(k)] = self:urldecode(v);
                                end
                        end
                        return params;
                else
                        return self.urldecode(query);
                end
        end
end

lol.urlcodes = setmetatable({}, { __index = function (t, k) t[k] = string.char(tonumber("0x"..k)); return t[k]; end });

function lol:urldecode(s)
                return s and (s:gsub("+", " "):gsub("%%([a-fA-F0-9][a-fA-F0-9])", self.urlcodes));
end

function lol:nl2br(s)
        return s and s:gsub("\n", "<br/>\n");
end

function lol:br2nl(s)
        return s and s:gsub("<br/>\n?", "\n");
end

function lol:htmlentities(s)
        return s and s:gsub("[^%w]", { ["<"] = "&lt;", [">"] = "&gt;", ["&"] = "&amp;", ["\""] = "&quot;", ["'"] = "&apos;" });
end

module "lol"

