[Modify] Polish it

This commit is contained in:
sta 2018-09-19 19:42:36 +09:00
parent 0b853ecf70
commit ea43df2f61

View File

@ -539,33 +539,24 @@ namespace WebSocketSharp.Net
output.WriteByte ((byte) _hexChars[idx]); output.WriteByte ((byte) _hexChars[idx]);
} }
private static void urlPathEncode (char c, Stream result) private static void urlPathEncode (char c, Stream output)
{ {
if (c < 33 || c > 126) { if (c > 32 && c < 127) {
var bytes = Encoding.UTF8.GetBytes (c.ToString ()); output.WriteByte ((byte) c);
foreach (var b in bytes) {
result.WriteByte ((byte) '%');
var i = (int) b;
var idx = i >> 4;
result.WriteByte ((byte) _hexChars[idx]);
idx = i & 0x0F;
result.WriteByte ((byte) _hexChars[idx]);
}
return; return;
} }
if (c == ' ') { var bytes = Encoding.UTF8.GetBytes (c.ToString ());
result.WriteByte ((byte) '%'); foreach (var b in bytes) {
result.WriteByte ((byte) '2'); output.WriteByte ((byte) '%');
result.WriteByte ((byte) '0');
return; var i = (int) b;
var idx = i >> 4;
output.WriteByte ((byte) _hexChars[idx]);
idx = i & 0x0F;
output.WriteByte ((byte) _hexChars[idx]);
} }
result.WriteByte ((byte) c);
} }
private static void writeCharBytes (char c, IList buffer, Encoding encoding) private static void writeCharBytes (char c, IList buffer, Encoding encoding)