[Modify] Polish it

This commit is contained in:
sta 2018-09-08 21:05:08 +09:00
parent 883ea87175
commit d00b56de8a

View File

@ -1117,6 +1117,36 @@ namespace WebSocketSharp.Net
: 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)
{
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)
{
if (bytes == null)