webmcp
diff framework/env/encode/url_part.lua @ 0:9fdfb27f8e67
Version 1.0.0
author | jbe/bsw |
---|---|
date | Sun Oct 25 12:00:00 2009 +0100 (2009-10-25) |
parents | |
children |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/framework/env/encode/url_part.lua Sun Oct 25 12:00:00 2009 +0100 1.3 @@ -0,0 +1,21 @@ 1.4 +--[[-- 1.5 +url_encoded_string = -- URL-encoded string 1.6 +encode.url_part( 1.7 + obj -- any native datatype or atom 1.8 +) 1.9 + 1.10 +This function encodes any native datatype or atom in a way that it can be placed inside an URL. It is first dumped with atom.dump(...) and then url-encoded. 1.11 + 1.12 +--]]-- 1.13 + 1.14 +function encode.url_part(obj) 1.15 + return ( 1.16 + string.gsub( 1.17 + atom.dump(obj), 1.18 + "[^0-9A-Za-z_%.~-]", 1.19 + function (char) 1.20 + return string.format("%%%02x", string.byte(char)) 1.21 + end 1.22 + ) 1.23 + ) 1.24 +end