Example #1
0
        /**
         * Unescapes an URL. All the "%xx" are replaced by the 'xx' hex char value.
         * @param src the url to unescape
         * @return the eunescaped value
         */
        public static String UnEscapeURL(String src)
        {
            StringBuilder bf = new StringBuilder();

            char[] s = src.ToCharArray();
            for (int k = 0; k < s.Length; ++k)
            {
                char c = s[k];
                if (c == '%')
                {
                    if (k + 2 >= s.Length)
                    {
                        bf.Append(c);
                        continue;
                    }
                    int a0 = PRTokeniser.GetHex((int)s[k + 1]);
                    int a1 = PRTokeniser.GetHex((int)s[k + 2]);
                    if (a0 < 0 || a1 < 0)
                    {
                        bf.Append(c);
                        continue;
                    }
                    bf.Append((char)(a0 * 16 + a1));
                    k += 2;
                }
                else
                {
                    bf.Append(c);
                }
            }
            return(bf.ToString());
        }