2 -- Copyright (C) 2008-2010 Matthew Wild
3 -- Copyright (C) 2008-2010 Waqas Hussain
5 -- This project is MIT/X11 licensed. Please see the
6 -- COPYING file in the source package for more information.
11 -- This file contains a mix of encodings below.
12 -- Many editors will unquestioningly convert these for you.
13 -- Please be careful :( (I recommend Scite)
14 ---------------------------------
16 local gmatch = string.gmatch;
17 local t_concat, t_insert = table.concat, table.insert;
18 local to_byte, to_char = string.byte, string.char;
20 local function _latin1toutf8(str)
21 if not str then return str; end
23 for ch in gmatch(str, ".") do
26 t_insert(p, to_char(ch));
27 elseif (ch < 0xC0) then
28 t_insert(p, to_char(0xC2, ch));
30 t_insert(p, to_char(0xC3, ch - 64));
36 function latin1toutf8()
37 local function assert_utf8(latin, utf8)
38 assert_equal(_latin1toutf8(latin), utf8, "Incorrect UTF8 from Latin1: "..tostring(latin));
42 assert_utf8("test", "test")
44 assert_utf8("foobar.råkat.se", "foobar.rÃ¥kat.se")