[Modify] Polish it
This commit is contained in:
parent
883ea87175
commit
d00b56de8a
@ -1117,6 +1117,36 @@ namespace WebSocketSharp.Net
|
|||||||
: String.Empty;
|
: String.Empty;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static string UrlEncode (byte[] bytes, int offset, int count)
|
||||||
|
{
|
||||||
|
if (bytes == null) {
|
||||||
|
if (count != 0)
|
||||||
|
throw new ArgumentNullException ("bytes");
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
var len = bytes.Length;
|
||||||
|
if (len == 0) {
|
||||||
|
if (offset != 0 || count != 0)
|
||||||
|
throw new ArgumentException ("An empty byte array.", "bytes");
|
||||||
|
|
||||||
|
return String.Empty;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (offset < 0 || offset >= len)
|
||||||
|
throw new ArgumentOutOfRangeException ("offset");
|
||||||
|
|
||||||
|
if (count < 0 || count > len - offset)
|
||||||
|
throw new ArgumentOutOfRangeException ("count");
|
||||||
|
|
||||||
|
return count > 0
|
||||||
|
? Encoding.ASCII.GetString (
|
||||||
|
InternalUrlEncodeToBytes (bytes, offset, count)
|
||||||
|
)
|
||||||
|
: String.Empty;
|
||||||
|
}
|
||||||
|
|
||||||
public static string UrlEncode (string s)
|
public static string UrlEncode (string s)
|
||||||
{
|
{
|
||||||
return UrlEncode (s, Encoding.UTF8);
|
return UrlEncode (s, Encoding.UTF8);
|
||||||
@ -1142,16 +1172,6 @@ namespace WebSocketSharp.Net
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string UrlEncode (byte[] bytes, int offset, int count)
|
|
||||||
{
|
|
||||||
var encoded = UrlEncodeToBytes (bytes, offset, count);
|
|
||||||
return encoded == null
|
|
||||||
? null
|
|
||||||
: encoded.Length == 0
|
|
||||||
? String.Empty
|
|
||||||
: Encoding.ASCII.GetString (encoded);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static byte[] UrlEncodeToBytes (byte[] bytes)
|
public static byte[] UrlEncodeToBytes (byte[] bytes)
|
||||||
{
|
{
|
||||||
if (bytes == null)
|
if (bytes == null)
|
||||||
|
Loading…
Reference in New Issue
Block a user