Author: raja
Date: 2007-11-07 22:31:44 -0500 (Wed, 07 Nov 2007)
New Revision: 89176
Modified:
trunk/mcs/class/System/System.Text.RegularExpressions/BaseMachine.cs
trunk/mcs/class/System/System.Text.RegularExpressions/ChangeLog
trunk/mcs/class/System/Test/System.Text.RegularExpressions/ChangeLog
trunk/mcs/class/System/Test/System.Text.RegularExpressions/RegexReplace.cs
Log:
Fix 324390
In System/System.Text.RegularExpressions:
* BaseMachine.cs (LTRReplace): Don't use non-advancement of 'ptr'
to deduce absence of matches -- a match can have length 0.
(RTLReplace): Likewise.
In System/Test/System.Text.RegularExpressions:
* RegexReplace.cs (tests): New test from #324390.
Modified: trunk/mcs/class/System/System.Text.RegularExpressions/BaseMachine.cs
===================================================================
--- trunk/mcs/class/System/System.Text.RegularExpressions/BaseMachine.cs
2007-11-08 02:36:02 UTC (rev 89175)
+++ trunk/mcs/class/System/System.Text.RegularExpressions/BaseMachine.cs
2007-11-08 03:31:44 UTC (rev 89176)
@@ -102,14 +102,17 @@
internal static string LTRReplace (Regex regex, string input,
MatchAppendEvaluator evaluator, int count, int startat)
{
+ Match m = regex.Match (input, startat);
+ if (!m.Success)
+ return input;
+
StringBuilder result = new StringBuilder ();
int ptr = startat;
int counter = count;
result.Append (input, 0, ptr);
- Match m = regex.Match (input, startat);
- while (m.Success) {
+ do {
if (count != -1)
if (counter-- <= 0)
break;
@@ -120,11 +123,8 @@
ptr = m.Index + m.Length;
m = m.NextMatch ();
- }
+ } while (m.Success);
- if (ptr == startat)
- return input;
-
result.Append (input, ptr, input.Length - ptr);
return result.ToString ();
@@ -132,14 +132,16 @@
internal static string RTLReplace (Regex regex, string input,
MatchEvaluator evaluator, int count, int startat)
{
+ Match m = regex.Match (input, startat);
+ if (!m.Success)
+ return input;
+
int ptr = startat;
int counter = count;
-
StringCollection pieces = new StringCollection ();
pieces.Add (input.Substring (ptr));
- Match m = regex.Match (input, startat);
- while (m.Success) {
+ do {
if (count != -1)
if (counter-- <= 0)
break;
@@ -150,11 +152,8 @@
ptr = m.Index;
m = m.NextMatch ();
- }
+ } while (m.Success);
- if (ptr == startat)
- return input;
-
StringBuilder result = new StringBuilder ();
result.Append (input, 0, ptr);
Modified: trunk/mcs/class/System/System.Text.RegularExpressions/ChangeLog
===================================================================
--- trunk/mcs/class/System/System.Text.RegularExpressions/ChangeLog
2007-11-08 02:36:02 UTC (rev 89175)
+++ trunk/mcs/class/System/System.Text.RegularExpressions/ChangeLog
2007-11-08 03:31:44 UTC (rev 89176)
@@ -1,3 +1,10 @@
+2007-11-08 Raja R Harinath <[EMAIL PROTECTED]>
+
+ Fix 324390
+ * BaseMachine.cs (LTRReplace): Don't use non-advancement of 'ptr'
+ to deduce absence of matches -- a match can have length 0.
+ (RTLReplace): Likewise.
+
2007-11-07 Raja R Harinath <[EMAIL PROTECTED]>
Support RegexOptions.RightToLeft in Replace().
Modified: trunk/mcs/class/System/Test/System.Text.RegularExpressions/ChangeLog
===================================================================
--- trunk/mcs/class/System/Test/System.Text.RegularExpressions/ChangeLog
2007-11-08 02:36:02 UTC (rev 89175)
+++ trunk/mcs/class/System/Test/System.Text.RegularExpressions/ChangeLog
2007-11-08 03:31:44 UTC (rev 89176)
@@ -1,3 +1,7 @@
+2007-11-08 Raja R Harinath <[EMAIL PROTECTED]>
+
+ * RegexReplace.cs (tests): New test from #324390.
+
2007-11-07 Raja R Harinath <[EMAIL PROTECTED]>
* MatchTest.cs (Match_Backref): New.
Modified:
trunk/mcs/class/System/Test/System.Text.RegularExpressions/RegexReplace.cs
===================================================================
--- trunk/mcs/class/System/Test/System.Text.RegularExpressions/RegexReplace.cs
2007-11-08 02:36:02 UTC (rev 89175)
+++ trunk/mcs/class/System/Test/System.Text.RegularExpressions/RegexReplace.cs
2007-11-08 03:31:44 UTC (rev 89176)
@@ -85,7 +85,8 @@
//new testcase ("F2345678910L71",
@"(F)(2)(3)(4)(5)(6)(?<S>7)(8)(9)(10)(L)\11", "${S}$11$1", "77F1" ),
new testcase ("F2345678910L71",
@"(F)(2)(3)(4)(5)(6)(7)(8)(9)(10)(L)\11", "${S}$11$1", "F2345678910L71"
),
new testcase ("F2345678910LL1",
@"(F)(2)(3)(4)(5)(6)(7)(8)(9)(10)(L)\11", "${S}$11$1", "${S}LF1",
/*FIXME: this should work in RTL direction too */ direction.LTR),
- new testcase ("a", "a", @"\\", @"\\"),
+ new testcase ("a", "a", @"\\", @"\\"), // bug #317092
+ new testcase ("a", "^", "x", "xa"), // bug #324390
};
[Test]
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches