\r
\r
using System;\r
+using System.Globalization;\r
using System.Net.Sockets;\r
using System.Runtime.InteropServices;\r
using System.Text;\r
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
\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
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
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
// 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
// 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