3 -- Copyright (C) 2011 Toni Gundogdu <legatvs@gmail.com>
5 -- This file is part of quvi <http://quvi.sourceforge.net/>.
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
24 -- A modularized revision of <http://www.hpelbers.org/lua/utf8>
26 -- convert numeric html entities to utf8
27 -- example: € -> €
31 local char
= string.char
36 n
,r
= math
.floor(n
/0x40), n
%0x40
43 local n
, r
, u
= tonumber(a
)
44 if n
<0x80 then -- 1 byte
46 elseif n
<0x800 then -- 2 byte
48 return char(n
+0xc0) .. u
49 elseif n
<0x10000 then -- 3 byte
51 return char(n
+0xe0) .. u
52 elseif n
<0x200000 then -- 4 byte
54 return char(n
+0xf0) .. u
55 elseif n
<0x4000000 then -- 5 byte
57 return char(n
+0xf8) .. u
60 return char(n
+0xfc) .. u
65 --for line in io.lines() do
66 -- out = string.gsub(line, '&#(%d+);', to_utf8)
73 -- vim: set ts=4 sw=4 tw=72 expandtab: