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.
9 local gmatch = string.gmatch;
10 local t_concat, t_insert = table.concat, table.insert;
11 local to_byte, to_char = string.byte, string.char;
13 local function _latin1toutf8(str)
14 if not str then return str; end
16 for ch in gmatch(str, ".") do
19 t_insert(p, to_char(ch));
20 elseif (ch < 0xC0) then
21 t_insert(p, to_char(0xC2, ch));
23 t_insert(p, to_char(0xC3, ch - 64));
29 function latin1toutf8()
30 local function assert_utf8(latin, utf8)
31 assert_equal(_latin1toutf8(latin), utf8, "Incorrect UTF8 from Latin1: "..tostring(latin));
35 assert_utf8("test", "test")
37 assert_utf8("foobar.r\229kat.se", "foobar.r\195\165kat.se")