Beispiel #1
0
        private static string UrlDecodeEncoding(string str, Encoding enc)
        {
            int length = str.Length;

            InternalDecoder decoder = new InternalDecoder(length, enc);

            for (int i = 0; i < length; i++)
            {
                char ch = str[i];
                if ((ch == '%') && (i < (length - 2)))
                {
                    if ((str[i + 1] == 'u') && (i < (length - 5)))
                    {
                        int next2 = HexCharToInt(str[i + 2]);
                        int next3 = HexCharToInt(str[i + 3]);
                        int next4 = HexCharToInt(str[i + 4]);
                        int next5 = HexCharToInt(str[i + 5]);

                        if (((next2 < 0) || (next3 < 0)) || ((next4 < 0) || (next5 < 0)))
                        {
                            //just add the char and continue
                            decoder.AddChar(ch);
                            continue;
                        }

                        ch = (char)((((next2 << 12) | (next3 << 8)) | (next4 << 4)) | next5);

                        // step to next 5 char
                        i += 5;

                        decoder.AddChar(ch);
                        continue;
                    }

                    int nextC1 = HexCharToInt(str[i + 1]);
                    int nextC2 = HexCharToInt(str[i + 2]);
                    if ((nextC1 >= 0) && (nextC2 >= 0))
                    {
                        decoder.AddChar(ch);
                        continue;
                    }
                }
                else
                {
                    //just add the char and continue
                    decoder.AddChar(ch);
                    continue;
                }
            }
            return(decoder.GetString());
        }
Beispiel #2
0
        private static string UrlDecodeEncoding(string str, Encoding enc)
        {
            int length = str.Length;

            InternalDecoder decoder = new InternalDecoder(length, enc);
            for (int i = 0; i < length; i++)
            {
                char ch = str[i];
                if ((ch == '%') && (i < (length - 2)))
                {
                    if ((str[i + 1] == 'u') && (i < (length - 5)))
                    {
                        int next2 = HexCharToInt(str[i + 2]);
                        int next3 = HexCharToInt(str[i + 3]);
                        int next4 = HexCharToInt(str[i + 4]);
                        int next5 = HexCharToInt(str[i + 5]);

                        if (((next2 < 0) || (next3 < 0)) || ((next4 < 0) || (next5 < 0)))
                        {
                            //just add the char and continue
                            decoder.AddChar(ch);
                            continue;
                        }

                        ch = (char)((((next2 << 12) | (next3 << 8)) | (next4 << 4)) | next5);

                        // step to next 5 char
                        i += 5;

                        decoder.AddChar(ch);
                        continue;
                    }

                    int nextC1 = HexCharToInt(str[i + 1]);
                    int nextC2 = HexCharToInt(str[i + 2]);
                    if ((nextC1 >= 0) && (nextC2 >= 0))
                    {
                        decoder.AddChar(ch);
                        continue;
                    }
                }
                else
                {
                    //just add the char and continue
                    decoder.AddChar(ch);
                    continue;
                }
            }
            return decoder.GetString();
        }