remove warning
[mono.git] / mcs / class / corlib / System / Double.cs
index f3e140f7ee18ce8ae8a1f15d3ada745fa5c32c0c..23198122acc40039ff119af139ebb7f3cfd0b7da 100644 (file)
@@ -42,6 +42,9 @@ using System.Runtime.ConstrainedExecution;
 namespace System {
        
        [Serializable]
+#if NET_2_0
+       [System.Runtime.InteropServices.ComVisible (true)]
+#endif
        public struct Double : IComparable, IFormattable, IConvertible
 #if NET_2_0
                , IComparable <double>, IEquatable <double>
@@ -197,6 +200,7 @@ namespace System {
                private const int State_ExponentSign = 4;
                private const int State_Exponent = 5;
                private const int State_ConsumeWhiteSpace = 6;
+               private const int State_Exit = 7;
                
                public static double Parse (string s, NumberStyles style, IFormatProvider provider)
                {
@@ -209,7 +213,7 @@ namespace System {
                        return result;
                }
                
-               [MonoTODO("check if digits are group in correct numbers between the group separators")]
+               // FIXME: check if digits are group in correct numbers between the group separators
                internal static bool Parse (string s, NumberStyles style, IFormatProvider provider, bool tryParse, out double result, out Exception exc)
                {
                        result = 0;
@@ -220,6 +224,11 @@ namespace System {
                                        exc = new ArgumentNullException ("s");
                                return false;
                        }
+                       if (s.Length == 0) {
+                               if (!tryParse)
+                                       exc = new FormatException ();
+                               return false;
+                       }
 #if NET_2_0
                        // yes it's counter intuitive (buggy?) but even TryParse actually throws in this case
                        if ((style & NumberStyles.AllowHexSpecifier) != 0) {
@@ -265,7 +274,7 @@ namespace System {
                                if (sidx == len) {
                                        if (!tryParse)
                                                exc = Int32.GetFormatException ();
-                                       return true;
+                                       return false;
                                }
                        }
 
@@ -281,8 +290,10 @@ namespace System {
                        //
                        string decimal_separator = null;
                        string group_separator = null;
+                       string currency_symbol = null;
                        int decimal_separator_len = 0;
                        int group_separator_len = 0;
+                       int currency_symbol_len = 0;
                        if ((style & NumberStyles.AllowDecimalPoint) != 0){
                                decimal_separator = format.NumberDecimalSeparator;
                                decimal_separator_len = decimal_separator.Length;
@@ -291,6 +302,10 @@ namespace System {
                                group_separator = format.NumberGroupSeparator;
                                group_separator_len = group_separator.Length;
                        }
+                       if ((style & NumberStyles.AllowCurrencySymbol) != 0){
+                               currency_symbol = format.CurrencySymbol;
+                               currency_symbol_len = currency_symbol.Length;
+                       }
                        string positive = format.PositiveSign;
                        string negative = format.NegativeSign;
                        
@@ -301,6 +316,7 @@ namespace System {
                                        sidx = len;
                                        continue;
                                }
+
                                switch (state){
                                case State_AllowSign:
                                        if ((style & NumberStyles.AllowLeadingSign) != 0){
@@ -331,9 +347,8 @@ namespace System {
                                                goto case State_Decimal;
                                        
                                        if (decimal_separator != null &&
-                                           decimal_separator [0] == c){
-                                               if (s.Substring (sidx, decimal_separator_len) ==
-                                                   decimal_separator){
+                                           decimal_separator [0] == c) {
+                                               if (String.CompareOrdinal (s, sidx, decimal_separator, 0, decimal_separator_len) == 0) {
                                                        b [didx++] = (byte) '.';
                                                        sidx += decimal_separator_len-1;
                                                        state = State_Decimal; 
@@ -349,6 +364,15 @@ namespace System {
                                                        break;
                                                }
                                        }
+                                       if (currency_symbol != null &&
+                                           currency_symbol [0] == c){
+                                               if (s.Substring (sidx, currency_symbol_len) ==
+                                                   currency_symbol){
+                                                       sidx += currency_symbol_len-1;
+                                                       state = State_Digits; 
+                                                       break;
+                                               }
+                                       }
                                        
                                        if (Char.IsWhiteSpace (c))
                                                goto case State_ConsumeWhiteSpace;
@@ -364,8 +388,11 @@ namespace System {
                                        }
 
                                        if (c == 'e' || c == 'E'){
-                                               if ((style & NumberStyles.AllowExponent) == 0)
-                                                       throw new FormatException ("Unknown char: " + c);
+                                               if ((style & NumberStyles.AllowExponent) == 0) {
+                                                       if (!tryParse)
+                                                               exc = new FormatException ("Unknown char: " + c);
+                                                       return false;
+                                               }
                                                b [didx++] = (byte) c;
                                                state = State_ExponentSign;
                                                break;
@@ -420,13 +447,18 @@ namespace System {
                                        return false;
 
                                case State_ConsumeWhiteSpace:
-                                       if (allow_trailing_white && Char.IsWhiteSpace (c))
+                                       if (allow_trailing_white && Char.IsWhiteSpace (c)) {
+                                               state = State_ConsumeWhiteSpace;
                                                break;
+                                       }
                                        
                                        if (!tryParse)
                                                exc = new FormatException ("Unknown char");
                                        return false;
                                }
+
+                               if (state == State_Exit)
+                                       break;
                        }
 
                        b [didx] = 0;