2004-10-18 Gonzalo Paniagua Javier <gonzalo@ximian.com>
authorGonzalo Paniagua Javier <gonzalo.mono@gmail.com>
Mon, 18 Oct 2004 22:11:21 +0000 (22:11 -0000)
committerGonzalo Paniagua Javier <gonzalo.mono@gmail.com>
Mon, 18 Oct 2004 22:11:21 +0000 (22:11 -0000)
* System.Text.RegularExpressions/regex.cs: in Replace, when count is
negative, replacement continues to the end of the string.

* Test/System.Text.RegularExpressions/RegexBugs.cs: added test for this
fix.

Fixes bug #68398. Patch by Jon Larimer.

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

mcs/class/System/System.Text.RegularExpressions/ChangeLog
mcs/class/System/System.Text.RegularExpressions/regex.cs
mcs/class/System/Test/System.Text.RegularExpressions/ChangeLog
mcs/class/System/Test/System.Text.RegularExpressions/RegexBugs.cs

index 1dc633af4f443c5eab09edf233bf4eee94c37e23..c2f823fb2d82c7b9aa77372f17e1793b8d2e8162 100644 (file)
@@ -1,3 +1,10 @@
+2004-10-18 Gonzalo Paniagua Javier <gonzalo@ximian.com>
+
+       * regex.cs: in Replace, when count is negative, replacement continues
+       to the end of the string.
+
+       Fixes bug #68398. Patch by Jon Larimer.
+
 2004-06-10  Gert Driesen <drieseng@users.sourceforge.net>
 
        * RegexRunner.cs: fixed case mismatch of methods
index d9523564ff5e250427231483337f5f0e5717b7ba..1c683866b107f396af5c5469521083e2c2c7129d 100644 (file)
@@ -354,9 +354,15 @@ namespace System.Text.RegularExpressions {
                {\r
                        StringBuilder result = new StringBuilder ();\r
                        int ptr = startat;\r
+                       int counter = count;
+
+                       result.Append (input.Substring (0, ptr));
 \r
                        Match m = Match (input, startat);\r
-                       while (m.Success && count -- > 0) {\r
+                       while (m.Success) {\r
+                               if (count != -1)
+                                       if(counter -- > 0)
+                                               break;
                                result.Append (input.Substring (ptr, m.Index - ptr));\r
                                result.Append (evaluator (m));\r
 \r
index 77b5f8acc13847768c6196f89be29c429c3be447..bff9309fd9a07d25076ad92641a6b5d6683144b7 100644 (file)
@@ -1,3 +1,8 @@
+2004-10-18 Gonzalo Paniagua Javier <gonzalo@ximian.com>
+
+       * System.Text.RegularExpressions/RegexBugs.cs: added test for bug
+       #68398.
+
 2004-07-05  Jackson Harper  <jackson@ximian.com>
 
        * RegexTest.cs: Add some simple tests for debugging/zen building.
index acd73dae1f172a4ad258146ad19dbfa4a34ada9d..26c8f2baf47a8aafa7f2c44843866ab6f7053631 100644 (file)
@@ -211,6 +211,15 @@ namespace MonoTests.System.Text.RegularExpressions
                        text = re.Replace(text, " ");
                        AssertEquals("#01", "Go, \bNo Go", text);
                }
+
+               [Test]
+               public void ReplaceNegOneAndStartat ()
+               {
+                       string text = "abcdeeee";
+                       Regex re = new Regex("e+");
+                       text = re.Replace(text, "e", -1, 4);
+                       AssertEquals("#01", "abcde", text);
+               }
        }
 }