Sfoglia il codice sorgente

2004-03-19 Dick Porter <[email protected]>

	* UnicodeEncoding.cs: GetCharCount(), GetChars(): Check for the
	BOM at the beginning of the range of characters we're interested
	in, not at the beginning of the array.  Fixes bug 51531.

2004-03-19  Dick Porter  <[email protected]>

	* UnicodeEncodingTest.cs: Test for character counts on subranges
	of arrays with a BOM at the start of the array.

svn path=/trunk/mcs/; revision=24328
Dick Porter 22 anni fa
parent
commit
d339f0349e

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

@@ -1,3 +1,9 @@
+2004-03-19  Dick Porter  <[email protected]>
+
+	* UnicodeEncoding.cs: GetCharCount(), GetChars(): Check for the
+	BOM at the beginning of the range of characters we're interested
+	in, not at the beginning of the array.  Fixes bug 51531.
+
 2004-03-10  Juraj Skripsky <[email protected]>
 
 	* StringBuilder.cs

+ 4 - 4
mcs/class/corlib/System.Text/UnicodeEncoding.cs

@@ -198,8 +198,8 @@ public class UnicodeEncoding : Encoding
 			throw new ArgumentOutOfRangeException ("count", _("ArgRange_Array"));
 		}
 		if (count >= 2) {
-			if ((bytes[0] == (byte)0xFE && bytes[1] == (byte)0xFF) ||
-					(bytes[0] == (byte)0xFF && bytes[1] == (byte)0xFE)) {
+			if ((bytes[index] == (byte)0xFE && bytes[index + 1] == (byte)0xFF) ||
+					(bytes[index] == (byte)0xFF && bytes[index + 1] == (byte)0xFE)) {
 				return ((count - 1) / 2);
 			}
 		}
@@ -229,11 +229,11 @@ public class UnicodeEncoding : Encoding
 		// Determine the byte order in the incoming buffer.
 		bool isBigEndian;
 		if (byteCount >= 2) {
-			if (bytes[0] == (byte)0xFE && bytes[1] == (byte)0xFF) {
+			if (bytes[byteIndex] == (byte)0xFE && bytes[byteIndex + 1] == (byte)0xFF) {
 				isBigEndian = true;
 				byteCount -= 2;
 				byteIndex += 2;
-			} else if (bytes[0] == (byte)0xFF && bytes[1] == (byte)0xFE) {
+			} else if (bytes[byteIndex] == (byte)0xFF && bytes[byteIndex + 1] == (byte)0xFE) {
 				isBigEndian = false;
 				byteCount -= 2;
 				byteIndex += 2;

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

@@ -1,3 +1,8 @@
+2004-03-19  Dick Porter  <[email protected]>
+
+	* UnicodeEncodingTest.cs: Test for character counts on subranges
+	of arrays with a BOM at the start of the array.
+
 2004-03-10  Juraj Skripsky <[email protected]>
 
 	* StringBuilderTest.cs: added new test for bug in Insert.

+ 12 - 0
mcs/class/corlib/Test/System.Text/UnicodeEncodingTest.cs

@@ -97,6 +97,18 @@ namespace MonoTests.System.Text
                         
                         Assertion.AssertEquals ("Uni #1", Unicode, Result);
                 }
+
+		[Test]
+		public void TestEncodingGetCharCount ()
+		{
+			byte[] b = new byte[] {255, 254, 115, 0, 104, 0, 105, 0};
+			UnicodeEncoding encoding = new UnicodeEncoding ();
+
+			Assertion.AssertEquals ("GetCharCount #1", 3,
+				encoding.GetCharCount (b, 2, b.Length - 2));
+		}
+
+	
                 
                 [Test]
                 public void TestPreamble1()