Merge pull request #5636 from BrzVlad/fix-xmm-scan
[mono.git] / mcs / class / WindowsBase / System.Windows / Point.cs
index c72a171353669f0554a37d0714a1537a443d9302..af57f92829d43bcffa045a95f4e6dafa3eaff50e 100644 (file)
@@ -39,18 +39,18 @@ namespace System.Windows {
        {
                public Point (double x, double y)
                {
-                       this.x = x;
-                       this.y = y;
+                       this._x = x;
+                       this._y = y;
                }
 
                public double X {
-                       get { return x; }
-                       set { x = value; }
+                       get { return _x; }
+                       set { _x = value; }
                }
 
                public double Y {
-                       get { return y; }
-                       set { y = value; }
+                       get { return _y; }
+                       set { _y = value; }
                }
 
                public override bool Equals (object o)
@@ -62,19 +62,19 @@ namespace System.Windows {
 
                public bool Equals (Point value)
                {
-                       return x == value.X && y == value.Y;
+                       return _x == value.X && _y == value.Y;
                }
 
                public override int GetHashCode ()
-               {\r
-                   return (x.GetHashCode() ^ y.GetHashCode());
+               {
+                   return (_x.GetHashCode() ^ _y.GetHashCode());
                }
 
 
                public void Offset (double offsetX, double offsetY)
                {
-                       x += offsetX;
-                       y += offsetY;
+                       _x += offsetX;
+                       _y += offsetY;
                }
 
                public static Point Add (Point point, Vector vector)
@@ -146,50 +146,51 @@ namespace System.Windows {
                }
 
                public static Point Parse (string source)
-               {\r
-                       string[] points = source.Split(',');\r
-\r
-                       if (points.Length<2)\r
-                               throw new InvalidOperationException ("source does not contain two numbers");\r
-                       if (points.Length > 2)\r
-                               throw new InvalidOperationException ("source contains too many delimiters");\r
-\r
-                       CultureInfo ci = CultureInfo.InvariantCulture;
-                       return new Point (Convert.ToDouble(points[0],ci), Convert.ToDouble(points[1],ci));      
+               {
+                       if (source == null)
+                               throw new ArgumentNullException ("source");
+                       var tokenizer = new NumericListTokenizer (source, CultureInfo.InvariantCulture);
+                       double x;
+                       double y;
+                       if (!double.TryParse (tokenizer.GetNextToken (), NumberStyles.Float, CultureInfo.InvariantCulture, out x) ||
+                           !double.TryParse (tokenizer.GetNextToken (), NumberStyles.Float, CultureInfo.InvariantCulture, out y))
+                       {
+                               throw new FormatException (string.Format ("Invalid Point format: {0}", source));
+                       }
+                       if (!tokenizer.HasNoMoreTokens ())
+                       {
+                               throw new InvalidOperationException ("Invalid Point format: " + source);
+                       }
+                       return new Point(x, y);
                }
 
                public override string ToString ()
-               {\r
+               {
                        return this.ToString(null, null);
                }
 
-               public string ToString (IFormatProvider formatProvider)
-               {\r
-                       return this.ToString(null,formatProvider);
+               public string ToString (IFormatProvider provider)
+               {
+                       return this.ToString(null, provider);
                }
 
-               private string ToString(string format,IFormatProvider formatProvider)\r
-               {\r
-                       CultureInfo ci = (CultureInfo)formatProvider;\r
-\r
-                       if (ci == null)\r
-                               ci = CultureInfo.CurrentCulture;\r
-                       string seperator = ci.NumberFormat.NumberDecimalSeparator;\r
-                       if (seperator.Equals(","))\r
-                               seperator = ";";\r
-                       else\r
-                               seperator = ",";\r
-                       object[] ob = { this.x, seperator, this.y };\r
-\r
-                       return string.Format(formatProvider, "{0:" + format + "}{1}{2:" + format + "}", ob);\r
+               private string ToString(string format,IFormatProvider formatProvider)
+               {
+                       if (formatProvider == null)
+                               formatProvider = CultureInfo.CurrentCulture;
+                       if (format == null)
+                               format = string.Empty;
+                       var separator = NumericListTokenizer.GetSeparator (formatProvider);
+                       var pointFormat  = string.Format ("{{0:{0}}}{1}{{1:{0}}}", format, separator);
+                       return string.Format (formatProvider, pointFormat, _x, _y);
                }
 
                string IFormattable.ToString (string format, IFormatProvider formatProvider)
-               {\r
+               {
                        return this.ToString(format, formatProvider);
                }
 
-               double x;
-               double y;
+               double _x;
+               double _y;
        }
 }