local function encodeHtmlSpecialChars(str)
    local html = {
        ["<"] = "&lt;",
        [">"] = "&gt;",
        ["&"] = "&amp;",
    }
    local decstr, _ = string.gsub(tostring(str), "[<>&]", function(char)
        return html[char] or char
    end)
    return decstr
end

local function decodeHtmlSpecialChars(str)
    local html = {
        ["&lt;"] = "<",
        ["&gt;"] = ">",
        ["&amp;"] = "&",
    }
    local rawstr, _ = string.gsub(tostring(str), "%b&;", function(char)
        return html[char] or char
    end)
    return rawstr
end

标签: Lua

添加新评论