[corlib] Fixes custom formatter with ";" section separator and zero values
authorMarek Safar <marek.safar@gmail.com>
Wed, 15 Mar 2017 16:45:28 +0000 (17:45 +0100)
committerMarek Safar <marek.safar@gmail.com>
Thu, 16 Mar 2017 09:02:04 +0000 (10:02 +0100)
mcs/class/corlib/System/NumberFormatter.cs
mcs/class/corlib/Test/System/Int32Test.cs

index 72276936b08d43266180a2f39e868edb16ffb7ec..3e3d0d3e8f0e716708dd91edbe4a40e9f7c97e22 100644 (file)
@@ -1813,54 +1813,42 @@ namespace System
                                                return;
                                        }
                                }
-                               if (index == 2) {
-                                       if (zero) {
-                                               offset = lens [0] + lens [1] + 2;
-                                               length = format.Length - offset;
-                                               return;
-                                       }
-                                       if (positive) {
-                                               offset = 0;
-                                               length = lens [0];
-                                               return;
-                                       }
-                                       if (lens [1] > 0) {
-                                               positive = true;
-                                               offset = lens [0] + 1;
-                                               length = lens [1];
+                               if (zero) {
+                                       if (index == 2) {
+                                               if (format.Length - lastPos == 0) {
+                                                       offset = 0;
+                                                       length = lens [0];
+                                               } else {
+                                                       offset = lens [0] + lens [1] + 2;
+                                                       length = format.Length - offset;
+                                               }
                                                return;
                                        }
-                                       else {
+
+                                       if (lens [2] == 0) {
                                                offset = 0;
                                                length = lens [0];
-                                               return;
-                                       }
-                               }
-                               if (index == 3) {
-                                       if (zero) {
+                                       } else {
                                                offset = lens [0] + lens [1] + 2;
                                                length = lens [2];
-                                               return;
-                                       }
-                                       if (positive) {
-                                               offset = 0;
-                                               length = lens [0];
-                                               return;
-                                       }
-                                       if (lens [1] > 0) {
-                                               positive = true;
-                                               offset = lens [0] + 1;
-                                               length = lens [1];
-                                               return;
-                                       }
-                                       else {
-                                               offset = 0;
-                                               length = lens [0];
-                                               return;
                                        }
-                               }
 
-                               throw new ArgumentException ();
+                                       return;
+
+                               }
+                               if (positive) {
+                                       offset = 0;
+                                       length = lens [0];
+                                       return;
+                               }
+                               if (lens [1] > 0) {
+                                       positive = true;
+                                       offset = lens [0] + 1;
+                                       length = lens [1];
+                                       return;
+                               }
+                               offset = 0;
+                               length = lens [0];
                        }
 
                        public static CustomInfo Parse (string format, int offset, int length, NumberFormatInfo nfi)
index 8d9a7fb03a02aa9bdcf2a1aff83ab6d1949fcaf3..d9cf780bb22140695c1f2ac537fd82af9eb7d363 100644 (file)
@@ -467,10 +467,14 @@ public class Int32Test
                int hundred = 100;
                int neghund = -100;
                
-               Assert.IsTrue ( hundred.ToString ("#;#") == "100", "#TS1");
-               Assert.IsTrue ( hundred.ToString ("-#;#") == "-100", "#TS2");
-               Assert.IsTrue ( neghund.ToString ("#;#") == "100", "#TS3");
-               Assert.IsTrue ( neghund.ToString ("#;-#") == "-100", "#TS3");
+               Assert.AreEqual ("100", hundred.ToString ("#;#"), "#TS1");
+               Assert.AreEqual ("-100", hundred.ToString ("-#;#"), "#TS2");
+               Assert.AreEqual ("100", neghund.ToString ("#;#"), "#TS3");
+               Assert.AreEqual ("-100", neghund.ToString ("#;-#"), "#TS4");
+               Assert.AreEqual ("3", 0.ToString ("3;;"), "#TS5");
+               Assert.AreEqual ("3", 0.ToString ("3;2;"), "#TS6");
+               Assert.AreEqual ("3", 0.ToString ("3;"), "#TS7");
+               Assert.AreEqual ("3", 0.ToString ("3;;;;;;;"), "#TS8");
        }
        
        [Test]