Example #1
0
 public void Dispose()
 {
     _buffer = null;
     Debug.GC(true);
 }
Example #2
0
        internal static string UnescapeDataString(string stringToUnescape, bool safe)
        {
            if (stringToUnescape == null)
                throw new ArgumentNullException("stringToUnescape");

            if (stringToUnescape.IndexOf('%') == -1 && stringToUnescape.IndexOf('+') == -1)
                return stringToUnescape;

            StringBuilder output = new StringBuilder();
            long len = stringToUnescape.Length;
            var bytes = new CircularBuffer(128,1,128);
            int xchar;

            for (int i = 0; i < len; i++)
            {
                if (stringToUnescape[i] == '%' && i + 2 < len && stringToUnescape[i + 1] != '%')
                {
                    if (stringToUnescape[i + 1] == 'u' && i + 5 < len)
                    {
                        if (bytes.Size > 0)
                        {
                            output.Append(Encoding.UTF8.GetChars(bytes.Get(bytes.Size)));
                            bytes.Clear();
                        }

                        xchar = GetChar(stringToUnescape, i + 2, 4, safe);
                        if (xchar != -1)
                        {
                            output.Append((char)xchar);
                            i += 5;
                        }
                        else
                        {
                            output.Append('%');
                        }
                    }
                    else if ((xchar = GetChar(stringToUnescape, i + 1, 2, safe)) != -1)
                    {
                        bytes.Put((byte)xchar);
                        i += 2;
                    }
                    else
                    {
                        output.Append('%');
                    }
                    continue;
                }

                if (bytes.Size > 0)
                {
                    output.Append(Encoding.UTF8.GetChars(bytes.Get(bytes.Size)));
                    bytes.Clear();
                }

                output.Append(stringToUnescape[i]);
            }

            if (bytes.Size> 0)
            {
                output.Append(Encoding.UTF8.GetChars(bytes.Get(bytes.Size)));
            }

            bytes = null;
            return output.ToString();
        }