]> git.proxmox.com Git - ceph.git/blob - ceph/src/civetweb/test/html_esc.lua
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / civetweb / test / html_esc.lua
1 htmlEscape = { "☺", "☻", "♥", "♦", "♣", "♠", "•", -- ASCII 1-7 (symbols for control characters, see code page 437)
2 "◘", "○", "◙", "♂", "♀", "♪", "♫", "☼", -- ASCII 8-15
3 "►", "◄", "↕", "‼", "¶", "§", "▬", "↨", -- ASCII 16-23
4 "↑", "↓", "↨", "←", "∟", "→", "▲", "▼", -- ASCII 24-31
5 " ", "!", """, "#", "$", "%", "&", "'", -- ASCII 32-39
6 "(", ")", "*", "+", ",", "-", ".", "/", -- ASCII 40-47
7 "0", "1", "2", "3", "4", "5", "6", "7", -- ASCII 48-55
8 "8", "9", ":", ";", "<", "=", ">", "?", -- ASCII 56-63
9 "@", "A", "B", "C", "D", "E", "F", "G", -- ASCII 64-71
10 "H", "I", "J", "K", "L", "M", "N", "O", -- ASCII 72-79
11 "P", "Q", "R", "S", "T", "U", "V", "W", -- ASCII 80-87
12 "X", "Y", "Z", "[", "\\", "]", "^", "_", -- ASCII 88-95
13 "`", "a", "b", "c", "d", "e", "f", "g", -- ASCII 96-103
14 "h", "i", "j", "k", "l", "m", "n", "o", -- ASCII 104-111
15 "p", "q", "r", "s", "t", "u", "v", "w", -- ASCII 112-119
16 "x", "y", "z", "{", "|", "}", "~", "⌂", -- ASCII 120-127
17 "Ç", "ü", "é", "â", "ä", "à", "å", "ç", -- 128-135 (dos code page 850)
18 "ê", "ë", "è", "ï", "î", "ì", "Ä", "Å", -- 136-143
19 "É", "æ", "Æ", "ô", "ö", "ò", "û", "ù", -- 144-151
20 "ÿ", "Ö", "Ü", "ø", "£", "Ø", "×", "ƒ", -- 152-159
21 "á", "í", "ó", "ú", "ñ", "Ñ", "ª", "º", -- 160-167
22 "¿", "®", "¬", "½", "¼", "¡", "«", "»", -- 168-175
23 "░", "▒", "▓", "│", "┤", "Á", "Â", "À", -- 176-183
24 "©", "╣", "║", "╗", "╝", "¢", "¥", "┐", -- 184-191
25 "└", "┴", "┬", "├", "─", "┼", "ã", "Ã", -- 192-199
26 "╚", "╔", "╩", "╦", "╠", "═", "╬", "¤", -- 200-207
27 "ð", "Ð", "Ê", "Ë", "È", "ı", "Í", "Î", -- 208-215
28 "Ï", "┘", "┌", "█", "▄", "¦", "Ì", "▀", -- 216-223
29 "Ó", "ß", "Ô", "Ò", "õ", "Õ", "µ", "þ", -- 224-231
30 "Þ", "Ú", "Û", "Ù", "ý", "Ý", "¯", "´", -- 232-239
31 "≡", "±", "‗", "¾", "¶", "§", "÷", "¸", -- 240-247
32 "°", "¨", "·", "¹", "³", "²", "■", "□", -- 248-255 (use empty box for 255)
33 };
34 htmlEscape[0] = "·" -- in this table, we use a 8 bit character set, where every has a different graphical representation
35
36 -- the conversion table should work as a convertion function for strings as well
37 setmetatable(htmlEscape, {__call = function (tab,str) return string.gsub(str, ".", function (c) return tab[c:byte()] end) end})
38
39
40 function htmlEsc(txt)
41 s = txt:gsub("%&", "&")
42 s = s:gsub("%<", "&lt;")
43 return s:gsub("%>", "&gt;")
44 end
45
46
47 function iso8859_1_to_utf8(txt)
48 local s = txt:gsub(".",
49 function (c)
50 local b = c:byte()
51 if b < 128 then
52 return c
53 elseif b < 192 then
54 return string.char(194, b)
55 else
56 return string.char(195, b-64)
57 end
58 end)
59 return s
60 end