2 -- Copyright (C) 2008 Matthew Wild
3 -- Copyright (C) 2008 Waqas Hussain
5 -- This program is free software; you can redistribute it and/or
6 -- modify it under the terms of the GNU General Public License
7 -- as published by the Free Software Foundation; either version 2
8 -- of the License, or (at your option) any later version.
10 -- This program is distributed in the hope that it will be useful,
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 -- GNU General Public License for more details.
15 -- You should have received a copy of the GNU General Public License
16 -- along with this program; if not, write to the Free Software
17 -- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 -- This file contains a mix of encodings below.
23 -- Many editors will unquestioningly convert these for you.
24 -- Please be careful :( (I recommend Scite)
25 ---------------------------------
27 local gmatch = string.gmatch;
28 local t_concat, t_insert = table.concat, table.insert;
29 local to_byte, to_char = string.byte, string.char;
31 local function _latin1toutf8(str)
32 if not str then return str; end
34 for ch in gmatch(str, ".") do
37 t_insert(p, to_char(ch));
38 elseif (ch < 0xC0) then
39 t_insert(p, to_char(0xC2, ch));
41 t_insert(p, to_char(0xC3, ch - 64));
47 function latin1toutf8()
48 local function assert_utf8(latin, utf8)
49 assert_equal(_latin1toutf8(latin), utf8, "Incorrect UTF8 from Latin1: "..tostring(latin));
53 assert_utf8("test", "test")
55 assert_utf8("foobar.råkat.se", "foobar.rÃ¥kat.se")