webmcp
view framework/env/encode/mime/atom_token.lua @ 2:72860d232f32
Version 1.0.2
Fixed bug with explicit garbage collection (requests > 256kB caused an error)
Views prefixed with an underscore can't be called externally
ui.paginate now displays the last page, if the selected page number is too high.
Fixed bug with explicit garbage collection (requests > 256kB caused an error)
Views prefixed with an underscore can't be called externally
ui.paginate now displays the last page, if the selected page number is too high.
author | jbe/bsw |
---|---|
date | Thu Dec 10 12:00:00 2009 +0100 (2009-12-10) |
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