webmcp

view framework/env/encode/mime/atom_token.lua @ 23:3a6fe8663b26

Code cleanup and documentation added; Year in copyright notice changed to 2009-2010

Details:
- Changed quoting style in auth.openid.xrds_document{...}
- Fixed documentation for auth.openid.initiate{...}
- Added documentation for mondelefant
- Code-cleanup in mondelefant:
-- removed unneccessary lines "rows = PQntuples(res); cols = PQnfields(res);"
-- avoided extra copy of first argument (self) in mondelefant_conn_query
-- no rawget in meta-method "__index" of database result lists and objects
-- removed unreachable "return 0;" in meta-method "__newindex" of database result lists and objects
- Year in copyright notice changed to 2009-2010
- Version string changed to "1.1.1"
author jbe
date Fri Jun 04 19:00:34 2010 +0200 (2010-06-04)
parents 9fdfb27f8e67
children
line source
1 function encode.mime.atom_token(str)
2 local charset = "UTF-8" -- TODO: support other charsets via locale system
3 if
4 string.find(str, "^[0-9A-Za-z!#%$%%&'%*%+%-/=%?%^_`{|}~]+$")
5 then
6 return str
7 elseif
8 string.find(str, "^[\t 0-9A-Za-z!#%$%%&'%*%+%-/=%?%^_`{|}~]+$")
9 then
10 return '"' .. str .. '"'
11 elseif
12 string.find(str, "^[\t -~]*$")
13 then
14 local parts = { '"' }
15 for char in string.gmatch(str, ".") do
16 if char == '"' or char == "\\" then
17 parts[#parts+1] = "\\"
18 end
19 parts[#parts+1] = char
20 end
21 parts[#parts+1] = '"'
22 return table.concat(parts)
23 else
24 local parts = { "=?", charset, "?Q?" }
25 for char in string.gmatch(str, ".") do
26 local byte = string.byte(char)
27 if string.find(char, "^[0-9A-Za-z%.%-]$") then
28 parts[#parts+1] = char
29 else
30 local byte = string.byte(char)
31 if byte == 32 then
32 parts[#parts+1] = "_"
33 else
34 parts[#parts+1] = string.format("=%02X", byte)
35 end
36 end
37 end
38 parts[#parts+1] = "?="
39 return table.concat(parts)
40 end
41 end

Impressum / About Us