1
/* -------------------- UTF-8 encoder ------------------------- */
2
function encode_utf8(t)
4
// dient der Normalisierung des Zeilenumbruchs
6
for(var n=0; n<t.length; n++)
9
// all the signs of ansi => 1byte
12
// all the signs between 127 and 2047 => 2byte
13
else if((c>127) && (c<2048))
15
d[d.length]= ((c>>6)|192);
16
d[d.length]= ((c&63)|128);
18
// all the signs between 2048 and 66536 => 3byte
21
d[d.length]= ((c>>12)|224);
22
d[d.length]= (((c>>6)&63)|128);
23
d[d.length]= ((c&63)|128);
26
for (var n=0; n<d.length; n++)
27
d[n] = String.fromCharCode(d[n]);
31
/* -------------------- UTF-8 decoder ------------------------- */
32
function decode_utf8(d)
41
r[r.length]= String.fromCharCode(c);
44
else if((c>191) && (c<224))
46
c1 = d.charCodeAt(i+1);
47
r[r.length]= String.fromCharCode(((c&31)<<6) | (c1&63));
52
c2 = d.charCodeAt(i+2);
53
r[r.length]= String.fromCharCode(((c&15)<<12) | ((c1&63)<<6) | (c2&63));
60
function hex_to_char(string)
62
return String.fromCharCode(parseInt(string.substring(1,3), 16));
65
var sHex = "0123456789ABCDEF"
67
function char_to_hex(string)
69
var iChar = string.charCodeAt(0);
70
return '%' + sHex.charAt((iChar>>4)&15) + sHex.charAt(iChar&15);
73
function decodeUrl(url)
75
url = url.replace(/%../g , hex_to_char);
76
return decode_utf8(url);
79
function encodeUrl(url)
81
url = encode_utf8(url);
82
return url.replace(/[^a-zA-Z\/.:]/g, char_to_hex);