Org.BouncyCastle.Asn1.X509.GeneralName.parseIPv6 C# (CSharp) Method

parseIPv6() private method

private parseIPv6 ( string ip ) : int[]
ip string
return int[]
		private int[] parseIPv6(string ip)
		{
			if (ip.StartsWith("::"))
			{
				ip = ip.Substring(1);
			}
			else if (ip.EndsWith("::"))
			{
				ip = ip.Substring(0, ip.Length - 1);
			}

			IEnumerator sEnum = ip.Split(':').GetEnumerator();

			int index = 0;
			int[] val = new int[8];

			int doubleColon = -1;

			while (sEnum.MoveNext())
			{
				string e = (string) sEnum.Current;

				if (e.Length == 0)
				{
					doubleColon = index;
					val[index++] = 0;
				}
				else
				{
					if (e.IndexOf('.') < 0)
					{
						val[index++] = Int32.Parse(e, NumberStyles.AllowHexSpecifier);
					}
					else
					{
						string[] tokens = e.Split('.');

						val[index++] = (Int32.Parse(tokens[0]) << 8) | Int32.Parse(tokens[1]);
						val[index++] = (Int32.Parse(tokens[2]) << 8) | Int32.Parse(tokens[3]);
					}
				}
			}

			if (index != val.Length)
			{
				Array.Copy(val, doubleColon, val, val.Length - (index - doubleColon), index - doubleColon);
				for (int i = doubleColon; i != val.Length - (index - doubleColon); i++)
				{
					val[i] = 0;
				}
			}

			return val;
		}