Author: atsushi
Date: 2006-01-16 05:24:12 -0500 (Mon, 16 Jan 2006)
New Revision: 55627
Modified:
trunk/mcs/class/I18N/CJK/CP936.cs
trunk/mcs/class/I18N/CJK/ChangeLog
trunk/mcs/class/I18N/CJK/Test/ChangeLog
trunk/mcs/class/I18N/CJK/Test/I18N.CJK.Test.cs
Log:
2006-01-16 Atsushi Enomoto <[EMAIL PROTECTED]>
* CP936.cs :
Implement GetCharCount(); it is too costy to use GetChars()
in GetCharCount(). Removed extra code in GetChars(). Check table
index range before accessing it by index.
* I18N.CJK.Test.cs : added test for bug #77238.
Modified: trunk/mcs/class/I18N/CJK/CP936.cs
===================================================================
--- trunk/mcs/class/I18N/CJK/CP936.cs 2006-01-16 09:41:40 UTC (rev 55626)
+++ trunk/mcs/class/I18N/CJK/CP936.cs 2006-01-16 10:24:12 UTC (rev 55627)
@@ -60,6 +60,41 @@
}
// Get the characters that result from decoding a byte buffer.
+ public override int GetCharCount (byte [] bytes, int index, int
count)
+ {
+ if (bytes == null)
+ throw new ArgumentNullException("bytes");
+ if (index < 0 || index > bytes.Length)
+ throw new ArgumentOutOfRangeException("index",
Strings.GetString("ArgRange_Array"));
+ if (count < 0 || index + count > bytes.Length)
+ throw new ArgumentOutOfRangeException("count",
Strings.GetString("ArgRange_Array"));
+
+ int lastByte = 0;
+ int length = 0;
+ while (count-- > 0) {
+ int b = bytes [index++];
+ if (lastByte == 0) {
+ if (b <= 0x80 || b == 0xFF) { // ASCII
+ length++;
+ continue;
+ } else {
+ lastByte = b;
+ continue;
+ }
+ }
+ length++;
+ lastByte = 0;
+ }
+
+#if NET_2_0
+ if (lastByte != 0)
+ length++;
+#endif
+
+ return length;
+ }
+
+ // Get the characters that result from decoding a byte buffer.
public override int GetChars(byte[] bytes, int byteIndex, int
byteCount,
char[] chars, int charIndex)
{
@@ -73,15 +108,14 @@
if (b <= 0x80 || b == 0xFF) { // ASCII
chars[charIndex++] = (char)b;
continue;
- } else if (b < 0x81 || b >= 0xFF) {
- continue;
} else {
lastByte = b;
continue;
}
}
int ord = ((lastByte - 0x81) * 191 + b - 0x40)
* 2;
- char c1 = (char)(gb2312.n2u[ord] +
gb2312.n2u[ord + 1] * 256);
+ char c1 = (ord < 0 || ord + 1 >=
gb2312.n2u.Length) ?
+ '\0' : (char)(gb2312.n2u[ord] +
gb2312.n2u[ord + 1] * 256);
if (c1 == 0)
chars[charIndex++] = '?';
else
Modified: trunk/mcs/class/I18N/CJK/ChangeLog
===================================================================
--- trunk/mcs/class/I18N/CJK/ChangeLog 2006-01-16 09:41:40 UTC (rev 55626)
+++ trunk/mcs/class/I18N/CJK/ChangeLog 2006-01-16 10:24:12 UTC (rev 55627)
@@ -1,5 +1,12 @@
2006-01-16 Atsushi Enomoto <[EMAIL PROTECTED]>
+ * CP936.cs :
+ Implement GetCharCount(); it is too costy to use GetChars()
+ in GetCharCount(). Removed extra code in GetChars(). Check table
+ index range before accessing it by index.
+
+2006-01-16 Atsushi Enomoto <[EMAIL PROTECTED]>
+
* CP51932.cs :
In GetChars(), insufficient byte is not preserved.
Under 1.x profile it is just discarded.
Modified: trunk/mcs/class/I18N/CJK/Test/ChangeLog
===================================================================
--- trunk/mcs/class/I18N/CJK/Test/ChangeLog 2006-01-16 09:41:40 UTC (rev
55626)
+++ trunk/mcs/class/I18N/CJK/Test/ChangeLog 2006-01-16 10:24:12 UTC (rev
55627)
@@ -1,7 +1,11 @@
2006-01-16 Atsushi Enomoto <[EMAIL PROTECTED]>
- * I18N.CJK.Test.cs : added test for bug #77223, #77224 and #77238.
+ * I18N.CJK.Test.cs : added test for bug #77238.
+2006-01-16 Atsushi Enomoto <[EMAIL PROTECTED]>
+
+ * I18N.CJK.Test.cs : added test for bug #77223, #77224 and #77222.
+
2005-12-06 Atsushi Enomoto <[EMAIL PROTECTED]>
* I18N.CJK.Test.cs : w00t, Now all test are working, including
Modified: trunk/mcs/class/I18N/CJK/Test/I18N.CJK.Test.cs
===================================================================
--- trunk/mcs/class/I18N/CJK/Test/I18N.CJK.Test.cs 2006-01-16 09:41:40 UTC
(rev 55626)
+++ trunk/mcs/class/I18N/CJK/Test/I18N.CJK.Test.cs 2006-01-16 10:24:12 UTC
(rev 55627)
@@ -209,7 +209,7 @@
}
[Test]
- public void Bug77238 ()
+ public void Bug77222 ()
{
Encoding e = Encoding.GetEncoding (51932);
byte [] bytes = new byte [2];
@@ -222,6 +222,20 @@
}
}
+ [Test]
+ public void Bug77238 ()
+ {
+ Encoding e = Encoding.GetEncoding(936);
+ byte [] bytes = new byte [2];
+ for (int i0 = 0; i0 < 0x100; i0++) {
+ bytes [0] = (byte) i0;
+ for (int i1 = 0; i1 < 0x100; i1++) {
+ bytes [1] = (byte) i1;
+ e.GetChars (bytes);
+ }
+ }
+ }
+
#endregion
#region Korean
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches