More StringComparison.Ordinal
authorGonzalo Paniagua Javier <gonzalo.mono@gmail.com>
Sun, 31 Oct 2010 21:22:15 +0000 (17:22 -0400)
committerGonzalo Paniagua Javier <gonzalo.mono@gmail.com>
Sun, 31 Oct 2010 21:23:18 +0000 (17:23 -0400)
Use StringComparison.Ordinal when calling IndexOf to find the index of
an ASCII string.

mcs/class/System/System.Net/BasicClient.cs
mcs/class/System/System.Net/EndPointManager.cs
mcs/class/System/System.Net/HttpListenerRequest.cs
mcs/class/System/System.Net/HttpListenerResponse.cs
mcs/class/System/System.Net/HttpWebRequest.cs
mcs/class/System/System.Net/HttpWebResponse.cs
mcs/class/System/System.Net/HttpWebResponse.jvm.cs
mcs/class/System/System.Net/ServicePointManager.cs
mcs/class/System/System.Net/WebConnection.cs
mcs/class/System/System.Net/WebConnectionStream.cs
mcs/class/System/System.Net/WebProxy.cs

index 5d89b269ff3fa143d72af4f78f415fd67d00cfae..6385d8f30ff8790a4d112779889a0fa8fb64c02e 100644 (file)
@@ -39,7 +39,7 @@ namespace System.Net
                                return null;
 
                        string header = challenge.Trim ();
-                       if (header.ToLower ().IndexOf ("basic") == -1)
+                       if (header.ToLower ().IndexOf ("basic", StringComparison.Ordinal) == -1)
                                return null;
 
                        return InternalAuthenticate (webRequest, credentials);
index 33c5940b43210f7a982cbc788fe15331fcf2e486..dc05a339acd27dbb3591acb9d0ea94bfa790ad60 100644 (file)
@@ -71,7 +71,7 @@ namespace System.Net {
                        if (lp.Path.IndexOf ('%') != -1)
                                throw new HttpListenerException (400, "Invalid path.");
 
-                       if (lp.Path.IndexOf ("//") != -1) // TODO: Code?
+                       if (lp.Path.IndexOf ("//", StringComparison.Ordinal) != -1) // TODO: Code?
                                throw new HttpListenerException (400, "Invalid path.");
 
                        // Always listens on all the interfaces, no matter the host name/ip used.
@@ -136,7 +136,7 @@ namespace System.Net {
                        if (lp.Path.IndexOf ('%') != -1)
                                return;
 
-                       if (lp.Path.IndexOf ("//") != -1)
+                       if (lp.Path.IndexOf ("//", StringComparison.Ordinal) != -1)
                                return;
 
                        EndPointListener epl = GetEPListener (IPAddress.Any, lp.Port, listener, lp.Secure);
index beb772088b4f1b49127654f1986098d11424d56b..491a7a851b0bb896e0e890aea7ec9ec18c475693 100644 (file)
@@ -259,22 +259,22 @@ namespace System.Net {
                                                if (str.Length == 0)
                                                        continue;
                                                if (str.StartsWith ("$Version")) {
-                                                       version = Int32.Parse (Unquote (str.Substring (str.IndexOf ("=") + 1)));
+                                                       version = Int32.Parse (Unquote (str.Substring (str.IndexOf ('=') + 1)));
                                                } else if (str.StartsWith ("$Path")) {
                                                        if (current != null)
-                                                               current.Path = str.Substring (str.IndexOf ("=") + 1).Trim ();
+                                                               current.Path = str.Substring (str.IndexOf ('=') + 1).Trim ();
                                                } else if (str.StartsWith ("$Domain")) {
                                                        if (current != null)
-                                                               current.Domain = str.Substring (str.IndexOf ("=") + 1).Trim ();
+                                                               current.Domain = str.Substring (str.IndexOf ('=') + 1).Trim ();
                                                } else if (str.StartsWith ("$Port")) {
                                                        if (current != null)
-                                                               current.Port = str.Substring (str.IndexOf ("=") + 1).Trim ();
+                                                               current.Port = str.Substring (str.IndexOf ('=') + 1).Trim ();
                                                } else {
                                                        if (current != null) {
                                                                cookies.Add (current);
                                                        }
                                                        current = new Cookie ();
-                                                       int idx = str.IndexOf ("=");
+                                                       int idx = str.IndexOf ('=');
                                                        if (idx > 0) {
                                                                current.Name = str.Substring (0, idx).Trim ();
                                                                current.Value =  str.Substring (idx + 1).Trim ();
index b275e3de13c36f798a9de367b882fe622e75526b..3d465008c3d422bbc884e2cde8d6318e0e20fe15 100644 (file)
@@ -398,7 +398,7 @@ namespace System.Net {
                                encoding = Encoding.Default;
 
                        if (content_type != null) {
-                               if (content_encoding != null && content_type.IndexOf ("charset=") == -1) {
+                               if (content_encoding != null && content_type.IndexOf ("charset=", StringComparison.Ordinal) == -1) {
                                        string enc_name = content_encoding.WebName;
                                        headers.SetInternal ("Content-Type", content_type + "; charset=" + enc_name);
                                } else {
index fcad9f21c736114a8febd5ad06dd04aaac5f0589..0aa0f03ccf9f22ec83cd3656ea4918817670dc83 100644 (file)
@@ -241,7 +241,7 @@ namespace System.Net
                                if (val == "keep-alive" || val == "close") 
                                        throw new ArgumentException ("Keep-Alive and Close may not be set with this property");
 
-                               if (keepAlive && val.IndexOf ("keep-alive") == -1)
+                               if (keepAlive && val.IndexOf ("keep-alive", StringComparison.Ordinal) == -1)
                                        value = value + ", Keep-Alive";
                                
                                webHeaders.RemoveAndAdd ("Connection", value);
index 83eef98ca697bca3ce61fcc93f523814d81b2a12..f8efd4187428e17a581607482c8bfad04af16eb8 100644 (file)
@@ -123,7 +123,7 @@ namespace System.Net
                                if (contentType == null)
                                        return "ISO-8859-1";
                                string val = contentType.ToLower ();                                    
-                               int pos = val.IndexOf ("charset=");
+                               int pos = val.IndexOf ("charset=", StringComparison.Ordinal);
                                if (pos == -1)
                                        return "ISO-8859-1";
                                pos += 8;
index f235a09675d4e733a7759d5e78b1494680ba68f8..f22222b027f86a37f83d64509f1b885888babc7a 100644 (file)
@@ -122,7 +122,7 @@ namespace System.Net
                                string contentType = ContentType;\r
                                if (contentType == null)\r
                                        return "ISO-8859-1";\r
-                               int pos = contentType.IndexOf ("charset=", StringComparison.InvariantCultureIgnoreCase);\r
+                               int pos = contentType.IndexOf ("charset=", StringComparison.OrdinalIgnoreCase);\r
                                if (pos == -1)\r
                                        return "ISO-8859-1";\r
                                pos += 8;\r
index 2b84c0c5e64a59cc414b11471bd1786753682c94..0b41c7d8c0ea618c252245bd4e75dfecb6fa82e5 100644 (file)
@@ -646,7 +646,7 @@ namespace System.Net
                                        X509Extension ext = cert.Extensions ["2.16.840.1.113730.1.1"];
                                        if (ext != null) {
                                                string text = ext.NetscapeCertType (false);
-                                               return text.IndexOf ("SSL Server Authentication") != -1;
+                                               return text.IndexOf ("SSL Server Authentication", StringComparison.Ordinal) != -1;
                                        }
                                        return true;
                                } catch (Exception e) {
index 0b55b9c68961a0af238d84da9cde34d4f9d57dfe..4e0e5048a840161d1f59c72deff58ac186ca05e4 100644 (file)
@@ -468,7 +468,7 @@ namespace System.Net
                        WebConnectionStream stream = new WebConnectionStream (cnc);
 
                        string contentType = data.Headers ["Transfer-Encoding"];
-                       cnc.chunkedRead = (contentType != null && contentType.ToLower ().IndexOf ("chunked") != -1);
+                       cnc.chunkedRead = (contentType != null && contentType.IndexOf ("chunked", StringComparison.OrdinalIgnoreCase) != -1);
                        if (!cnc.chunkedRead) {
                                stream.ReadBuffer = cnc.buffer;
                                stream.ReadBufferOffset = pos;
@@ -709,11 +709,11 @@ namespace System.Net
                                bool keepAlive = (Data.Version == HttpVersion.Version11 && this.keepAlive);
                                if (cncHeader != null) {
                                        cncHeader = cncHeader.ToLower ();
-                                       keepAlive = (this.keepAlive && cncHeader.IndexOf ("keep-alive") != -1);
+                                       keepAlive = (this.keepAlive && cncHeader.IndexOf ("keep-alive", StringComparison.Ordinal) != -1);
                                }
 
                                if ((socket != null && !socket.Connected) ||
-                                  (!keepAlive || (cncHeader != null && cncHeader.IndexOf ("close") != -1))) {
+                                  (!keepAlive || (cncHeader != null && cncHeader.IndexOf ("close", StringComparison.Ordinal) != -1))) {
                                        Close (false);
                                }
 
index a99303383128882595f3f9d97dcebc6221dc5028..4b261d55979b09120c133c1b4eea0633637f2c0d 100644 (file)
@@ -76,7 +76,7 @@ namespace System.Net
                        write_timeout = read_timeout;
                        this.cnc = cnc;
                        string contentType = cnc.Data.Headers ["Transfer-Encoding"];
-                       bool chunkedRead = (contentType != null && contentType.ToLower ().IndexOf ("chunked") != -1);
+                       bool chunkedRead = (contentType != null && contentType.IndexOf ("chunked", StringComparison.OrdinalIgnoreCase) != -1);
                        string clength = cnc.Data.Headers ["Content-Length"];
                        if (!chunkedRead && clength != null && clength != "") {
                                try {
@@ -113,7 +113,7 @@ namespace System.Net
                        bool isProxy = (request.Proxy != null && !request.Proxy.IsBypassed (request.Address));
                        string header_name = (isProxy) ? "Proxy-Authenticate" : "WWW-Authenticate";
                        string authHeader = cnc.Data.Headers [header_name];
-                       return (authHeader != null && authHeader.IndexOf ("NTLM") != -1);
+                       return (authHeader != null && authHeader.IndexOf ("NTLM", StringComparison.Ordinal) != -1);
                }
 
                internal void CheckResponseInBuffer ()
index 9232dbf5fb04e66a6f73c2177e44277a32b60278..5ef0b10ad89d54de45cb69db8fff9070e72dc4eb 100644 (file)
@@ -258,7 +258,7 @@ namespace System.Net
                        if (address == null)
                                return null;
                                
-                       if (address.IndexOf ("://") == -1) 
+                       if (address.IndexOf ("://", StringComparison.Ordinal) == -1) 
                                address = "http://" + address;
 
                        return new Uri (address);