~ubuntu-branches/ubuntu/natty/moin/natty-updates

« back to all changes in this revision

Viewing changes to wiki/htdocs/applets/moinFCKplugins/moinurllib.js

  • Committer: Bazaar Package Importer
  • Author(s): Jonas Smedegaard
  • Date: 2008-06-22 21:17:13 UTC
  • mto: This revision was merged to the branch mainline in revision 18.
  • Revision ID: james.westby@ubuntu.com-20080622211713-inlv5k4eifxckelr
ImportĀ upstreamĀ versionĀ 1.7.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -------------------- UTF-8 encoder ------------------------- */
 
2
function encode_utf8(t)
 
3
{
 
4
  // dient der Normalisierung des Zeilenumbruchs
 
5
  var d=[];
 
6
  for(var n=0; n<t.length; n++)
 
7
  {
 
8
    var c=t.charCodeAt(n);
 
9
    // all the signs of ansi => 1byte
 
10
    if (c<128)
 
11
       d[d.length]= c;
 
12
    // all the signs between 127 and 2047 => 2byte
 
13
    else if((c>127) && (c<2048)) 
 
14
    {
 
15
      d[d.length]= ((c>>6)|192);
 
16
      d[d.length]= ((c&63)|128);
 
17
    }
 
18
    // all the signs between 2048 and 66536 => 3byte
 
19
    else 
 
20
    {
 
21
      d[d.length]= ((c>>12)|224);
 
22
      d[d.length]= (((c>>6)&63)|128);
 
23
      d[d.length]= ((c&63)|128);
 
24
    }
 
25
  }
 
26
  for (var n=0; n<d.length; n++)
 
27
    d[n] = String.fromCharCode(d[n]);
 
28
  return d.join("");
 
29
}
 
30
 
 
31
/* -------------------- UTF-8 decoder ------------------------- */
 
32
function decode_utf8(d)
 
33
{
 
34
  var r=[]; var i=0;
 
35
  var c=c1=c2=0;
 
36
  while(i<d.length)
 
37
  {
 
38
    c = d.charCodeAt(i);
 
39
    if (c<128) 
 
40
    {
 
41
       r[r.length]= String.fromCharCode(c); 
 
42
       i++;
 
43
    }
 
44
    else if((c>191) && (c<224)) 
 
45
    {
 
46
      c1 = d.charCodeAt(i+1); 
 
47
      r[r.length]= String.fromCharCode(((c&31)<<6) | (c1&63)); 
 
48
      i+=2;
 
49
    }
 
50
    else 
 
51
    {
 
52
      c2 = d.charCodeAt(i+2);
 
53
      r[r.length]= String.fromCharCode(((c&15)<<12) | ((c1&63)<<6) | (c2&63));
 
54
      i+=3;
 
55
    }
 
56
  }
 
57
  return r.join("");
 
58
}
 
59
 
 
60
function hex_to_char(string)
 
61
{
 
62
 return String.fromCharCode(parseInt(string.substring(1,3), 16));
 
63
}
 
64
 
 
65
var sHex = "0123456789ABCDEF"
 
66
 
 
67
function char_to_hex(string)
 
68
{
 
69
  var iChar = string.charCodeAt(0);
 
70
  return '%' + sHex.charAt((iChar>>4)&15) + sHex.charAt(iChar&15);
 
71
}
 
72
 
 
73
function decodeUrl(url)
 
74
{
 
75
  url = url.replace(/%../g , hex_to_char);
 
76
  return decode_utf8(url);
 
77
}
 
78
 
 
79
function encodeUrl(url)
 
80
 
81
  url = encode_utf8(url);
 
82
  return url.replace(/[^a-zA-Z\/.:]/g, char_to_hex);
 
83
}
 
84