Add website/fastjizz.lua (NSFW)
[libquvi-scripts.git] / share / lua / website / quvi / html.lua
blob497fa4263d46216f1d3d5d7fe4cd2eae4949600a
2 -- libquvi-scripts
3 -- Copyright (C) 2011 Toni Gundogdu <legatvs@gmail.com>
4 --
5 -- This file is part of libquvi-scripts <http://quvi.sourceforge.net/>.
6 --
7 -- This library is free software; you can redistribute it and/or
8 -- modify it under the terms of the GNU Lesser General Public
9 -- License as published by the Free Software Foundation; either
10 -- version 2.1 of the License, or (at your option) any later version.
12 -- This library is distributed in the hope that it will be useful,
13 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
14 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 -- Lesser General Public License for more details.
17 -- You should have received a copy of the GNU Lesser General Public
18 -- License along with this library; if not, write to the Free Software
19 -- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20 -- 02110-1301 USA
24 -- A modularized revision of <http://www.hpelbers.org/lua/utf8>
26 -- convert numeric html entities to utf8
27 -- example: &#8364; -> €
30 local M = {}
31 local char = string.char
33 function M.tail(n, k)
34 local u, r=''
35 for i=1,k do
36 n,r = math.floor(n/0x40), n%0x40
37 u = char(r+0x80) .. u
38 end
39 return u, n
40 end
42 function M.to_utf8(a)
43 local n, r, u = tonumber(a)
44 if n<0x80 then -- 1 byte
45 return char(n)
46 elseif n<0x800 then -- 2 byte
47 u, n = M.tail(n, 1)
48 return char(n+0xc0) .. u
49 elseif n<0x10000 then -- 3 byte
50 u, n = M.tail(n, 2)
51 return char(n+0xe0) .. u
52 elseif n<0x200000 then -- 4 byte
53 u, n = M.tail(n, 3)
54 return char(n+0xf0) .. u
55 elseif n<0x4000000 then -- 5 byte
56 u, n = M.tail(n, 4)
57 return char(n+0xf8) .. u
58 else -- 6 byte
59 u, n = M.tail(n, 5)
60 return char(n+0xfc) .. u
61 end
62 end
65 --for line in io.lines() do
66 -- out = string.gsub(line, '&#(%d+);', to_utf8)
67 -- print(out)
68 --end
71 return M
73 -- vim: set ts=4 sw=4 tw=72 expandtab: