[Modify] Polish it
This commit is contained in:
parent
36b74f63ad
commit
883ea87175
@ -1124,32 +1124,22 @@ namespace WebSocketSharp.Net
|
|||||||
|
|
||||||
public static string UrlEncode (string s, Encoding encoding)
|
public static string UrlEncode (string s, Encoding encoding)
|
||||||
{
|
{
|
||||||
int len;
|
if (s == null)
|
||||||
if (s == null || (len = s.Length) == 0)
|
|
||||||
return s;
|
return s;
|
||||||
|
|
||||||
var needEncode = false;
|
var len = s.Length;
|
||||||
foreach (var c in s) {
|
if (len == 0)
|
||||||
if ((c < '0') || (c < 'A' && c > '9') || (c > 'Z' && c < 'a') || (c > 'z')) {
|
|
||||||
if (notEncoded (c))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
needEncode = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!needEncode)
|
|
||||||
return s;
|
return s;
|
||||||
|
|
||||||
if (encoding == null)
|
if (encoding == null)
|
||||||
encoding = Encoding.UTF8;
|
encoding = Encoding.UTF8;
|
||||||
|
|
||||||
// Avoided GetByteCount call.
|
|
||||||
var bytes = new byte[encoding.GetMaxByteCount (len)];
|
var bytes = new byte[encoding.GetMaxByteCount (len)];
|
||||||
var realLen = encoding.GetBytes (s, 0, len, bytes, 0);
|
var realLen = encoding.GetBytes (s, 0, len, bytes, 0);
|
||||||
|
|
||||||
return Encoding.ASCII.GetString (InternalUrlEncodeToBytes (bytes, 0, realLen));
|
return Encoding.ASCII.GetString (
|
||||||
|
InternalUrlEncodeToBytes (bytes, 0, realLen)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string UrlEncode (byte[] bytes, int offset, int count)
|
public static string UrlEncode (byte[] bytes, int offset, int count)
|
||||||
|
Loading…
Reference in New Issue
Block a user