Merge pull request #439 from mono-soc-2012/garyb/iconfix
[mono.git] / mcs / class / System / System.Net / IPv6Address.cs
index 494ea66dca765b05b05fa29e39efd89df7df8b0d..26bb3497c123cee8781c0c4c2e3028d56e218d7d 100644 (file)
@@ -34,6 +34,7 @@
 \r
 \r
 using System;\r
+using System.Globalization;\r
 using System.Net.Sockets;\r
 using System.Runtime.InteropServices;\r
 using System.Text;\r
@@ -94,7 +95,7 @@ namespace System.Net {
                                return 0;\r
                        \r
                        // Catch double uses of ::\r
-                       if (ipString.IndexOf ("::") != -1)\r
+                       if (ipString.IndexOf ("::", StringComparison.Ordinal) != -1)\r
                                return -1;\r
 \r
                        for (int i = 0; i < ipString.Length; i++){\r
@@ -132,6 +133,11 @@ namespace System.Net {
 \r
                        return slot;\r
                }\r
+\r
+               static bool TryParse (string prefix, out int res)\r
+               {\r
+                       return Int32.TryParse (prefix, NumberStyles.Integer, CultureInfo.InvariantCulture, out res);\r
+               }\r
                \r
                public static bool TryParse (string ipString, out IPv6Address result)\r
                {\r
@@ -152,11 +158,8 @@ namespace System.Net {
                        int pos = ipString.LastIndexOf ('/');\r
                        if (pos != -1) {\r
                                string prefix = ipString.Substring (pos + 1);\r
-                               try {\r
-                                       prefixLen = Int32.Parse (prefix);\r
-                               } catch (Exception) {\r
+                               if (!TryParse (prefix , out prefixLen))\r
                                        prefixLen = -1;\r
-                               }\r
                                if (prefixLen < 0 || prefixLen > 128)\r
                                        return false;\r
                                ipString = ipString.Substring (0, pos);\r
@@ -164,12 +167,8 @@ namespace System.Net {
                                pos = ipString.LastIndexOf ('%');\r
                                if (pos != -1) {\r
                                        string prefix = ipString.Substring (pos + 1);\r
-                                       try  {\r
-                                               scopeId = Int32.Parse (prefix);\r
-                                       } \r
-                                       catch (Exception) {\r
+                                       if (!TryParse (prefix, out scopeId))\r
                                                scopeId = 0;\r
-                                       }\r
                                        ipString = ipString.Substring (0, pos);\r
                                }                       \r
                        }\r
@@ -184,7 +183,7 @@ namespace System.Net {
                        // Is there an ipv4 address at the end?\r
                        //\r
                        bool ipv4 = false;\r
-                       int pos2 = ipString.LastIndexOf (":");\r
+                       int pos2 = ipString.LastIndexOf (':');\r
                        if (pos2 == -1)\r
                                return false;\r
 \r
@@ -213,7 +212,7 @@ namespace System.Net {
                        // Only an ipv6 block remains, either:\r
                        // "hexnumbers::hexnumbers", "hexnumbers::" or "hexnumbers"\r
                        //\r
-                       int c = ipString.IndexOf ("::");\r
+                       int c = ipString.IndexOf ("::", StringComparison.Ordinal);\r
                        if (c != -1){\r
                                int right_slots = Fill (addr, ipString.Substring (c+2));\r
                                if (right_slots == -1){\r