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;
ptr = m.Index + m.Length;
m = m.NextMatch ();
- }
-
- if (ptr == startat)
- return input;
+ } while (m.Success);
result.Append (input, ptr, input.Length - ptr);
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;
ptr = m.Index;
m = m.NextMatch ();
- }
-
- if (ptr == startat)
- return input;
+ } while (m.Success);
StringBuilder result = new StringBuilder ();
+2007-11-08 Raja R Harinath <harinath@gmail.com>
+
+ 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 <harinath@gmail.com>
Support RegexOptions.RightToLeft in Replace().
+2007-11-08 Raja R Harinath <harinath@gmail.com>
+
+ * RegexReplace.cs (tests): New test from #324390.
+
2007-11-07 Raja R Harinath <harinath@gmail.com>
* MatchTest.cs (Match_Backref): New.
//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]