Skip to content
lua
--网上很多版本使用参数 [^%w%.%- ] 会转义_,下面方法为标准encode
function encode(s)
	s = string.gsub(s, '([^%w%d%._%-%* ])', function(c) return string.format("%%%02X", string.byte(c)) end)
	return string.gsub(s, " ", "+")
end

function decode(s)
	s = string.gsub(s, '%%(%x%x)', function(h) return string.char(tonumber(h, 16)) end)
	return s
end