2008-05-19 Sebastien Pouliot <sebastien@ximian.com>
[mono.git] / mcs / class / corlib / System / UInt32.cs
index bf83021ece2b11015465f9819e01e90527b4a343..f352f1aec43182d010f646792b2eec4b465a3aea 100644 (file)
@@ -34,6 +34,9 @@ namespace System
 {
        [Serializable]
        [CLSCompliant (false)]
+#if NET_2_0
+       [System.Runtime.InteropServices.ComVisible (true)]
+#endif
        public struct UInt32 : IFormattable, IConvertible, IComparable
 #if NET_2_0
                , IComparable<UInt32>, IEquatable <UInt32>
@@ -52,13 +55,12 @@ namespace System
                        if (!(value is System.UInt32))
                                throw new ArgumentException (Locale.GetText ("Value is not a System.UInt32."));
 
-                       if (this.m_value == (uint) value)
-                               return 0;
+                       uint val = (uint) value;
 
-                       if (this.m_value < (uint) value)
-                               return -1;
+                       if (m_value == val)
+                               return 0;
 
-                       return 1;
+                       return (m_value < val) ? -1 : 1;
                }
 
                public override bool Equals (object obj)
@@ -85,9 +87,9 @@ namespace System
                                return -1;
                }
 
-               public bool Equals (uint value)
+               public bool Equals (uint obj)
                {
-                       return value == m_value;
+                       return obj == m_value;
                }
 #endif
 
@@ -137,24 +139,15 @@ namespace System
                                if (c >= '0' && c <= '9') {
                                        uint d = (uint) (c - '0');
 
-                                       val = checked (val * 10 + d);
-                                       digits_seen = true;
-                               }
-                               else {
-                                       if (Char.IsWhiteSpace (c)) {
-                                               for (i++; i < len; i++) {
-                                                       if (!Char.IsWhiteSpace (s [i])) {
-                                                               if (!tryParse)
-                                                                       exc = Int32.GetFormatException ();
-                                                               return false;
-                                                       }
-                                               }
-                                               break;
-                                       } else {
+                                       if ((val > MaxValue/10) || (val == (MaxValue / 10) && d > (MaxValue % 10))){
                                                if (!tryParse)
-                                                       exc = Int32.GetFormatException ();
+                                                       exc = new OverflowException (Locale.GetText ("Value is too large"));
                                                return false;
                                        }
+                                       val = (val * 10) + d;
+                                       digits_seen = true;
+                               } else if (!Int32.ProcessTrailingWhitespace (tryParse, s, i, ref exc)){
+                                       return false;
                                }
                        }
                        if (!digits_seen) {
@@ -308,7 +301,14 @@ namespace System
                                        else
                                                digitValue = (uint) (hexDigit - 'A' + 10);
 
-                                       number = checked (number * 16 + digitValue);
+                                       if (tryParse){
+                                               ulong l = number * 16 + digitValue;
+
+                                               if (l > MaxValue)
+                                                       return false;
+                                               number = (uint) l;
+                                       } else
+                                               number = checked (number * 16 + digitValue);
                                }
                                else if (decimalPointFound) {
                                        nDigits++;
@@ -408,12 +408,12 @@ namespace System
                }
 
                [CLSCompliant (false)]
-               public static uint Parse (string s, NumberStyles style, IFormatProvider fp
+               public static uint Parse (string s, NumberStyles style, IFormatProvider provider
                {
                        Exception exc;
                        uint res;
 
-                       if (!Parse (s, style, fp, false, out res, out exc))
+                       if (!Parse (s, style, provider, false, out res, out exc))
                                throw exc;
 
                        return res;
@@ -459,12 +459,12 @@ namespace System
 
                public override string ToString ()
                {
-                       return NumberFormatter.FormatGeneral (new NumberFormatter.NumberStore (m_value));
+                       return NumberFormatter.NumberToString (m_value, null);
                }
 
-               public string ToString (IFormatProvider fp)
+               public string ToString (IFormatProvider provider)
                {
-                       return NumberFormatter.FormatGeneral (new NumberFormatter.NumberStore (m_value), fp);
+                       return NumberFormatter.NumberToString (m_value, provider);
                }
 
                public string ToString (string format)
@@ -472,10 +472,9 @@ namespace System
                        return ToString (format, null);
                }
 
-               public string ToString (string format, IFormatProvider fp)
+               public string ToString (string format, IFormatProvider provider)
                {
-                       NumberFormatInfo nfi = NumberFormatInfo.GetInstance (fp);
-                       return NumberFormatter.NumberToString (format, m_value, nfi);
+                       return NumberFormatter.NumberToString (format, m_value, provider);
                }
 
                // =========== IConvertible Methods =========== //