Tue Feb 26 14:21:19 CET 2002 Paolo Molaro <lupus@ximian.com>
authorPaolo Molaro <lupus@oddwiz.org>
Tue, 26 Feb 2002 09:30:47 +0000 (09:30 -0000)
committerPaolo Molaro <lupus@oddwiz.org>
Tue, 26 Feb 2002 09:30:47 +0000 (09:30 -0000)
* UInt64.cs: fixed Parse method () to handle some of the NumberStyle flags.

svn path=/trunk/mcs/; revision=2666

mcs/class/corlib/System/ChangeLog
mcs/class/corlib/System/UInt64.cs

index 7bf328e69e943cb06788491df792475952d26f31..751282d67a6ae7827a1409f1cc0d0aef8249641f 100644 (file)
@@ -1,3 +1,8 @@
+
+Tue Feb 26 14:21:19 CET 2002 Paolo Molaro <lupus@ximian.com>
+
+       * UInt64.cs: fixed Parse method () to handle some of the NumberStyle flags.
+
 2002-02-26  Martin Baulig  <martin@gnome.org>
 
        * DateTime.cs: Miguel already committed this, but there was still a
index 6d96f722f8ddb43d753dd28fdbb3a9bcc9417c60..c2daf8a48e95ff0199d7974496dc616c9135006e 100644 (file)
@@ -49,6 +49,21 @@ namespace System {
                }
 
                public static ulong Parse (string s)
+               {
+                       return Parse (s, NumberStyles.Integer, null);
+               }
+
+               public static ulong Parse (string s, IFormatProvider fp)
+               {
+                       return Parse (s, NumberStyles.Integer, fp);
+               }
+
+               public static ulong Parse (string s, NumberStyles style)
+               {
+                       return Parse (s, style, null);
+               }
+
+               public static ulong Parse (string s, NumberStyles style, IFormatProvider fp)
                {
                        ulong val = 0;
                        int len;
@@ -61,65 +76,61 @@ namespace System {
                        len = s.Length;
 
                        char c;
-                       for (i = 0; i < len; i++){
-                               c = s [i];
-                               if (!Char.IsWhiteSpace (c))
-                                       break;
-                       }
+                       i = 0;
+                       if ((style & NumberStyles.AllowLeadingWhite) != 0)
+                               for (i = 0; i < len; i++){
+                                       c = s [i];
+                                       if (!Char.IsWhiteSpace (c))
+                                               break;
+                               }
                        
                        if (i == len)
                                throw new FormatException ();
 
-                       if (s [i] == '+')
+                       if ((style & NumberStyles.AllowLeadingSign) != 0 && (s [i] == '+'))
                                i++;
 
                        for (; i < len; i++){
                                c = s [i];
 
-                               if (c >= '0' && c <= '9'){
+                               if ((style & NumberStyles.AllowHexSpecifier) != 0) {
+                                       if (c >= '0' && c <= '9') {
+                                               uint d = (uint) (c - '0');
+                                               val = checked (val * 16 + d);
+                                               digits_seen = true;
+                                       } else if (c >= 'a' && c <= 'f') {
+                                               uint d = (uint) (c - 'a');
+                                               val = checked (val * 16 + 10 + d);
+                                               digits_seen = true;
+                                       } else if (c >= 'A' && c <= 'F') {
+                                               uint d = (uint) (c - 'A');
+                                               val = checked (val * 16 + 10 + d);
+                                               digits_seen = true;
+                                       } else
+                                               break;
+                               } else 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]))
-                                                               throw new FormatException ();
-                                               }
-                                               break;
-                                       } else
-                                               throw new FormatException ();
+                                       break;
                                }
                        }
                        if (!digits_seen)
                                throw new FormatException ();
-                       
-                       return val;
-
-               }
-
-               public static ulong Parse (string s, IFormatProvider fp)
-               {
-                       return Parse (s, NumberStyles.Integer, fp);
-               }
-
-               public static ulong Parse (string s, NumberStyles style)
-               {
-                       return Parse (s, style, null);
-               }
-
-               public static ulong Parse (string s, NumberStyles style, IFormatProvider fp)
-               {
-                       ulong val = 0;
-                       int j;
-                       for (j = 0; j < s.Length; ++j) {
-                               if (s [j] >= '0' && s [j] <= '9')
-                                       val = val * 10 + s [j] - '0';
-                               else
-                                       break;
+                       if (i < len) {
+                               if ((style & NumberStyles.AllowTrailingWhite) != 0 && Char.IsWhiteSpace (s [i])){
+                                       for (i++; i < len; i++){
+                                               if (!Char.IsWhiteSpace (s [i]))
+                                                       throw new FormatException ();
+                                       }
+                               } else
+                                       throw new FormatException ();
                        }
+       
                        return val;
+
                }
 
                public override string ToString ()