Ejemplo n.º 1
0
        private static string UrlEncodeUnicodeStringToStringInternal(string s, bool ignoreAscii)
        {
            int           length        = s.Length;
            StringBuilder stringBuilder = new StringBuilder(length);

            for (int i = 0; i < length; i++)
            {
                char chr = s[i];
                if ((chr & '\uFF80') != 0)
                {
                    stringBuilder.Append("%u");
                    stringBuilder.Append(UrlUtility.IntToHex(chr >> '\f' & 15));
                    stringBuilder.Append(UrlUtility.IntToHex(chr >> '\b' & 15));
                    stringBuilder.Append(UrlUtility.IntToHex(chr >> '\u0004' & 15));
                    stringBuilder.Append(UrlUtility.IntToHex(chr & '\u000F'));
                }
                else
                {
                    if (ignoreAscii || UrlUtility.IsSafe(chr))
                    {
                        stringBuilder.Append(chr);
                    }
                    else
                    {
                        if (chr != ' ')
                        {
                            stringBuilder.Append('%');
                            stringBuilder.Append(UrlUtility.IntToHex(chr >> '\u0004' & 15));
                            stringBuilder.Append(UrlUtility.IntToHex(chr & '\u000F'));
                        }
                        else
                        {
                            stringBuilder.Append('+');
                        }
                    }
                }
            }
            return(stringBuilder.ToString());
        }
Ejemplo n.º 2
0
        private static byte[] UrlEncodeBytesToBytesInternal(byte[] bytes, int offset, int count, bool alwaysCreateReturnValue)
        {
            int num  = 0;
            int num1 = 0;

            for (int i = 0; i < count; i++)
            {
                char chr = (char)bytes[offset + i];
                if (chr != ' ')
                {
                    if (!UrlUtility.IsSafe(chr))
                    {
                        num1++;
                    }
                }
                else
                {
                    num++;
                }
            }
            if (alwaysCreateReturnValue || num != 0 || num1 != 0)
            {
                byte[] hex  = new byte[count + num1 * 2];
                int    num2 = 0;
                for (int j = 0; j < count; j++)
                {
                    byte num3 = bytes[offset + j];
                    char chr1 = (char)num3;
                    if (!UrlUtility.IsSafe(chr1))
                    {
                        if (chr1 != ' ')
                        {
                            int num4 = num2;
                            num2      = num4 + 1;
                            hex[num4] = 37;
                            int num5 = num2;
                            num2      = num5 + 1;
                            hex[num5] = (byte)UrlUtility.IntToHex(num3 >> 4 & 15);
                            int num6 = num2;
                            num2      = num6 + 1;
                            hex[num6] = (byte)UrlUtility.IntToHex(num3 & 15);
                        }
                        else
                        {
                            int num7 = num2;
                            num2      = num7 + 1;
                            hex[num7] = 43;
                        }
                    }
                    else
                    {
                        int num8 = num2;
                        num2      = num8 + 1;
                        hex[num8] = num3;
                    }
                }
                return(hex);
            }
            else
            {
                return(bytes);
            }
        }