コード例 #1
0
        public static string UrlEncode(string s, Encoding encoding)
        {
            int length;

            if (s == null || (length = s.Length) == 0)
            {
                return(s);
            }
            bool flag = false;

            foreach (char c in s)
            {
                if (c < '0' || (c < 'A' && c > '9') || (c > 'Z' && c < 'a') || c > 'z')
                {
                    if (!HttpUtility.NotEncoded(c))
                    {
                        flag = true;
                        break;
                    }
                }
            }
            if (!flag)
            {
                return(s);
            }
            if (encoding == null)
            {
                encoding = Encoding.UTF8;
            }
            byte[] bytes  = new byte[encoding.GetMaxByteCount(length)];
            int    bytes2 = encoding.GetBytes(s, 0, length, bytes, 0);

            return(Encoding.ASCII.GetString(HttpUtility.UrlEncodeToBytesInternal(bytes, 0, bytes2)));
        }
コード例 #2
0
 public static byte[] UrlEncodeToBytes(string s, Encoding encoding)
 {
     if (s == null)
     {
         return(null);
     }
     if (s.Length == 0)
     {
         return(new byte[0]);
     }
     if (encoding == null)
     {
         encoding = Encoding.UTF8;
     }
     byte[] bytes = encoding.GetBytes(s);
     return(HttpUtility.UrlEncodeToBytesInternal(bytes, 0, bytes.Length));
 }
コード例 #3
0
        public static byte[] UrlEncodeToBytes(byte[] bytes, int offset, int count)
        {
            int num;

            if (bytes == null || (num = bytes.Length) == 0)
            {
                return(bytes);
            }
            if (count == 0)
            {
                return(new byte[0]);
            }
            if (offset < 0 || offset >= num)
            {
                throw new ArgumentOutOfRangeException("offset");
            }
            if (count < 0 || count > num - offset)
            {
                throw new ArgumentOutOfRangeException("count");
            }
            return(HttpUtility.UrlEncodeToBytesInternal(bytes, offset, count));
        }
コード例 #4
0
        public static byte[] UrlEncodeToBytes(byte[] bytes)
        {
            int count;

            return((bytes != null && (count = bytes.Length) != 0) ? HttpUtility.UrlEncodeToBytesInternal(bytes, 0, count) : bytes);
        }
コード例 #5
0
        public static string UrlEncode(byte[] bytes)
        {
            int count;

            return((bytes != null) ? (((count = bytes.Length) != 0) ? Encoding.ASCII.GetString(HttpUtility.UrlEncodeToBytesInternal(bytes, 0, count)) : string.Empty) : null);
        }