mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-04 18:41:51 +00:00
add string.url_encode, string.url_decode
This commit is contained in:
parent
348797931d
commit
3aca54178d
1 changed files with 15 additions and 0 deletions
|
|
@ -125,3 +125,18 @@ end
|
|||
function string.ends_with(str, endStr)
|
||||
return endStr == "" or string.sub(str, -string.len(endStr)) == endStr
|
||||
end
|
||||
|
||||
function string.url_encode(str)
|
||||
str = string.gsub(str, "([^%w%-%.%_%~])", function(c)
|
||||
return string.format("%%%02X", string.byte(c))
|
||||
end)
|
||||
return str
|
||||
end
|
||||
|
||||
function string.url_decode(str)
|
||||
str = string.gsub(str, "+", " ")
|
||||
str = string.gsub(str, "%%(%x%x)", function(hex)
|
||||
return string.char(tonumber(hex, 16))
|
||||
end)
|
||||
return str
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue