Refactored Ext.cs

This commit is contained in:
sta 2014-08-12 21:48:48 +09:00
parent decddde20a
commit 0a742f2e91
2 changed files with 12 additions and 12 deletions

View File

@ -615,9 +615,7 @@ namespace WebSocketSharp
internal static string Quote (this string value) internal static string Quote (this string value)
{ {
return value.IsToken () return String.Format ("\"{0}\"", value.Replace ("\"", "\\\""));
? value
: String.Format ("\"{0}\"", value.Replace ("\"", "\\\""));
} }
internal static byte[] ReadBytes (this Stream stream, int length) internal static byte[] ReadBytes (this Stream stream, int length)
@ -834,12 +832,12 @@ namespace WebSocketSharp
/// A <see cref="string"/> that represents the WebSocket URL to try. /// A <see cref="string"/> that represents the WebSocket URL to try.
/// </param> /// </param>
/// <param name="result"> /// <param name="result">
/// When this method returns, a <see cref="Uri"/> that represents the WebSocket URL if /// When this method returns, a <see cref="Uri"/> that represents the WebSocket URL
/// <paramref name="uriString"/> is valid; otherwise, <see langword="null"/>. /// if <paramref name="uriString"/> is valid; otherwise, <see langword="null"/>.
/// </param> /// </param>
/// <param name="message"> /// <param name="message">
/// When this method returns, a <see cref="string"/> that represents the error message if /// When this method returns, a <see cref="string"/> that represents the error message
/// <paramref name="uriString"/> is invalid; otherwise, <see cref="String.Empty"/>. /// if <paramref name="uriString"/> is invalid; otherwise, <see cref="String.Empty"/>.
/// </param> /// </param>
internal static bool TryCreateWebSocketUri ( internal static bool TryCreateWebSocketUri (
this string uriString, out Uri result, out string message) this string uriString, out Uri result, out string message)
@ -880,9 +878,9 @@ namespace WebSocketSharp
} }
} }
else { else {
uri = String.Format ( uri = new Uri (
"{0}://{1}:{2}{3}", schm, uri.Host, schm == "ws" ? 80 : 443, uri.PathAndQuery) String.Format (
.ToUri (); "{0}://{1}:{2}{3}", schm, uri.Host, schm == "ws" ? 80 : 443, uri.PathAndQuery));
} }
result = uri; result = uri;

View File

@ -667,8 +667,10 @@ namespace WebSocketSharp.Net
if (!_comment.IsNullOrEmpty ()) if (!_comment.IsNullOrEmpty ())
result.AppendFormat ("; Comment={0}", _comment.UrlEncode ()); result.AppendFormat ("; Comment={0}", _comment.UrlEncode ());
if (_commentUri != null) if (_commentUri != null) {
result.AppendFormat ("; CommentURL={0}", _commentUri.OriginalString.Quote ()); var url = _commentUri.OriginalString;
result.AppendFormat ("; CommentURL={0}", url.IsToken () ? url : url.Quote ());
}
if (_discard) if (_discard)
result.Append ("; Discard"); result.Append ("; Discard");