Azmyth.Vector.Parse C# (CSharp) Method

Parse() public static method

public static Parse ( string input ) : Vector
input string
return Vector
        public static Vector Parse(string input)
        {
            input = input.Trim();

            Regex vectorRegex = new Regex(@"[{(\[\|]\s*[0-9]+\s*[.:;,\-]\s*[0-9]+\s*[.:;,\-]\s*[0-9]+\s*[})\]\|]");

            if (vectorRegex.IsMatch(input))
            {
                input = input.Substring(1, input.Length - 2);

                input = input.Trim();

                string[] values = input.Split(new char[] { ';', ':', '.', ',', '-'});

                if(values.Length > 3)
                {
                    throw new ArgumentException();
                }

                int x, y, z;

                if (int.TryParse(values[0], out x) && int.TryParse(values[1], out y) && int.TryParse(values[2], out z))
                {
                    return new Vector(x, y, z);
                }

                throw new InvalidCastException();
            }

            throw new ArgumentOutOfRangeException();
        }