Przeglądaj źródła

In Test/System.Text:
2005-06-21 Ben Maurer <[email protected]>

* StringBuilderTest.cs: Test replacing with a longer string.

In System.Text:
2005-06-21 Ben Maurer <[email protected]>

* StringBuilder.cs (Replace): Do the correct thing when we replace
with a longer string. Thanks to Vorobiev Maksim
<[email protected]>.


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

Ben Maurer 20 lat temu
rodzic
commit
0301dca423

+ 6 - 0
mcs/class/corlib/System.Text/ChangeLog

@@ -1,3 +1,9 @@
+2005-06-21  Ben Maurer  <[email protected]>
+
+	* StringBuilder.cs (Replace): Do the correct thing when we replace
+	with a longer string. Thanks to Vorobiev Maksim
+	<[email protected]>.
+
 2005-05-26  Ben Maurer  <[email protected]>
 
 	* Encoding.cs: Use static object for locking. `volatile' to

+ 3 - 0
mcs/class/corlib/System.Text/StringBuilder.cs

@@ -296,7 +296,10 @@ namespace System.Text {
 
 			InternalEnsureCapacity (replace.Length + (_length - count));
 
+			string end = _str.Substring (startIndex + count, _length - startIndex - count );
+
 			String.InternalStrcpy (_str, startIndex, replace);
+			String.InternalStrcpy (_str, startIndex + replace.Length, end);
 			
 			_length = replace.Length + (_length - count);
 

+ 4 - 0
mcs/class/corlib/Test/System.Text/ChangeLog

@@ -1,3 +1,7 @@
+2005-06-21  Ben Maurer  <[email protected]>
+
+	* StringBuilderTest.cs: Test replacing with a longer string.
+
 2005-05-06  Ben Maurer  <[email protected]>
 
 	* StringBuilderTest.cs (MaxCapacity_Overflow3): Test for #72244.

+ 9 - 0
mcs/class/corlib/Test/System.Text/StringBuilderTest.cs

@@ -460,6 +460,15 @@ namespace MonoTests.System.Text {
 		StringBuilder sb = new StringBuilder ("hola").Append ("lala");
 		AssertEquals ("#01", "holalala", sb.ToString ());
 	}
+
+	[Test]
+	public void ReplaceWithLargerString ()
+	{
+		StringBuilder sb = new StringBuilder ("ABCDE");
+		AssertEquals ("#1", "ABCDE", sb.ToString ());
+		sb.Replace ("ABC", "abcaa", 0, 3);
+		AssertEquals ("#2", "abcaaDE", sb.ToString ());
+	}
 }
 
 }