Author: atsushi
Date: 2005-12-05 23:54:35 -0500 (Mon, 05 Dec 2005)
New Revision: 53968
Modified:
trunk/mcs/class/I18N/CJK/CP936.cs
trunk/mcs/class/I18N/CJK/ChangeLog
trunk/mcs/class/I18N/CJK/GB18030Encoding.cs
trunk/mcs/class/I18N/CJK/GB18030Source.cs
Log:
2005-12-06 Atsushi Enomoto <[EMAIL PROTECTED]>
* CP936.cs,
GB18030Encoding.cs,
GB18030Source.cs : conversion from Encoding to MonoEncoding and
added fallback support in GEtBytes(Impl), as well as others.
Modified: trunk/mcs/class/I18N/CJK/CP936.cs
===================================================================
--- trunk/mcs/class/I18N/CJK/CP936.cs 2005-12-06 04:24:37 UTC (rev 53967)
+++ trunk/mcs/class/I18N/CJK/CP936.cs 2005-12-06 04:54:35 UTC (rev 53968)
@@ -16,7 +16,7 @@
namespace I18N.CJK
{
- internal class CP936 : Encoding
+ internal class CP936 : MonoEncoding
{
// Magic number used by Windows for the GB2312 code page.
private const int GB2312_CODE_PAGE = 936;
@@ -47,28 +47,17 @@
}
// Get the bytes that result from encoding a character buffer.
- public override int GetBytes(char[] chars, int charIndex,
- int charCount, byte[] bytes,
- int byteIndex)
+ public unsafe override int GetBytesImpl (
+ char* chars, int charCount, byte* bytes, int byteCount)
{
- if (chars == null) {
- throw new ArgumentNullException("chars");
- }
- if (bytes == null) {
- throw new ArgumentNullException("bytes");
- }
- if (charIndex < 0 || charIndex > chars.Length) {
- throw new
ArgumentOutOfRangeException("charIndex", Strings.GetString("ArgRange_Array"));
- }
- if (charCount < 0 || charIndex + charCount >
chars.Length) {
- throw new
ArgumentOutOfRangeException("charCount", Strings.GetString("ArgRange_Array"));
- }
- if (byteIndex < 0 || byteIndex > bytes.Length) {
- throw new
ArgumentOutOfRangeException("byteIndex", Strings.GetString("ArgRange_Array"));
- }
+ int charIndex = 0;
+ int byteIndex = 0;
+#if NET_2_0
+ EncoderFallbackBuffer buffer = null;
+#endif
int posn = byteIndex;
- int byteLength = bytes.Length;
+ int byteLength = byteCount;
int ch;
while(charCount-- > 0) {
@@ -277,7 +266,13 @@
throw new ArgumentException ("bytes",
(Strings.GetString ("Arg_InsufficientSpace")));
int val = convert.UcsToGbk (ch);
if (val < 0)
+#if NET_2_0
+ HandleFallback (ref buffer,
+ chars, ref charIndex, ref
charCount,
+ bytes, ref posn, ref byteCount);
+#else
bytes [posn++] = (byte) '?';
+#endif
else {
bytes [posn++] = (byte) (val / 0x100);
bytes [posn++] = (byte) (val % 0x100);
Modified: trunk/mcs/class/I18N/CJK/ChangeLog
===================================================================
--- trunk/mcs/class/I18N/CJK/ChangeLog 2005-12-06 04:24:37 UTC (rev 53967)
+++ trunk/mcs/class/I18N/CJK/ChangeLog 2005-12-06 04:54:35 UTC (rev 53968)
@@ -1,3 +1,10 @@
+2005-12-06 Atsushi Enomoto <[EMAIL PROTECTED]>
+
+ * CP936.cs,
+ GB18030Encoding.cs,
+ GB18030Source.cs : conversion from Encoding to MonoEncoding and
+ added fallback support in GEtBytes(Impl), as well as others.
+
2005-12-05 Atsushi Enomoto <[EMAIL PROTECTED]>
* big5-table-generator.cs : new file to generate "big5.table".
Modified: trunk/mcs/class/I18N/CJK/GB18030Encoding.cs
===================================================================
--- trunk/mcs/class/I18N/CJK/GB18030Encoding.cs 2005-12-06 04:24:37 UTC (rev
53967)
+++ trunk/mcs/class/I18N/CJK/GB18030Encoding.cs 2005-12-06 04:54:35 UTC (rev
53968)
@@ -7,6 +7,7 @@
using System;
using System.Reflection;
using System.Text;
+using I18N.Common;
namespace I18N.CJK
{
@@ -17,7 +18,7 @@
public class CP54936 : GB18030Encoding { }
- public class GB18030Encoding : Encoding
+ public class GB18030Encoding : MonoEncoding
{
// Constructor.
public GB18030Encoding ()
@@ -46,12 +47,12 @@
public override int GetByteCount (char [] chars, int index, int
length)
{
- return new GB18030Encoder ().GetByteCount (chars,
index, length, true);
+ return new GB18030Encoder (this).GetByteCount (chars,
index, length, true);
}
- public override int GetBytes (char [] chars, int charIdx, int
srclen, byte [] bytes, int byteIdx)
+ public unsafe override int GetBytesImpl (char* chars, int
charCount, byte* bytes, int byteCount)
{
- return new GB18030Encoder ().GetBytes (chars, charIdx,
srclen, bytes, byteIdx, true);
+ return new GB18030Encoder (this).GetBytesImpl (chars,
charCount, bytes, byteCount, true);
}
public override int GetCharCount (byte [] bytes, int start, int
len)
@@ -237,8 +238,13 @@
}
}
- class GB18030Encoder : Encoder
+ class GB18030Encoder : MonoEncoding.MonoEncoder
{
+ public GB18030Encoder (MonoEncoding owner)
+ : base (owner)
+ {
+ }
+
Gb2312Convert gb2312 = Gb2312Convert.Convert;
char incomplete;
@@ -293,18 +299,13 @@
return ret;
}
- public override int GetBytes (char [] chars, int charIndex, int
charCount, byte [] bytes, int byteIndex, bool refresh)
+ public unsafe override int GetBytesImpl (char* chars, int
charCount, byte* bytes, int byteCount, bool flush)
{
- if (chars == null)
- throw new ArgumentNullException ("chars");
- if (bytes == null)
- throw new ArgumentNullException ("bytes");
- if (charIndex < 0 || charIndex > chars.Length)
- throw new ArgumentOutOfRangeException
("charIndex");
- if (charCount < 0 || charIndex + charCount >
chars.Length)
- throw new ArgumentOutOfRangeException
("charCount");
- if (byteIndex < 0 || byteIndex > bytes.Length)
- throw new ArgumentOutOfRangeException
("byteIndex");
+ int charIndex = 0;
+ int byteIndex = 0;
+#if NET_2_0
+ EncoderFallbackBuffer buffer = null;
+#endif
int charEnd = charIndex + charCount;
int byteStart = byteIndex;
@@ -329,11 +330,17 @@
char ch2 = chars [charIndex++];
if (!Char.IsSurrogate (ch2)) {
// invalid surrogate
+#if NET_2_0
+ HandleFallback (
+ chars, ref charIndex,
ref charCount,
+ bytes, ref byteIndex,
ref byteCount);
+#else
bytes [byteIndex++] = (byte)
'?';
+#endif
continue;
}
int cp = (ch - 0xD800) * 0x400 + ch2 -
0xDC00;
- GB18030Source.Unlinear (bytes,
byteIndex, GB18030Source.FromUCSSurrogate (cp));
+ GB18030Source.Unlinear (bytes +
byteIndex, GB18030Source.FromUCSSurrogate (cp));
byteIndex += 4;
continue;
}
@@ -354,7 +361,7 @@
value = GB18030Source.FromUCS (ch);
// non-GB2312
- GB18030Source.Unlinear (bytes, byteIndex,
value);
+ GB18030Source.Unlinear (bytes + byteIndex,
value);
byteIndex += 4;
}
return byteIndex - byteStart;
Modified: trunk/mcs/class/I18N/CJK/GB18030Source.cs
===================================================================
--- trunk/mcs/class/I18N/CJK/GB18030Source.cs 2005-12-06 04:24:37 UTC (rev
53967)
+++ trunk/mcs/class/I18N/CJK/GB18030Source.cs 2005-12-06 04:54:35 UTC (rev
53968)
@@ -108,13 +108,20 @@
public static void Unlinear (byte [] bytes, int start, long gbx)
{
- bytes [start + 3] = (byte) (gbx % 10 + 0x30);
+ fixed (byte* bptr = bytes) {
+ Unlinear (bptr + start, gbx);
+ }
+ }
+
+ public static unsafe void Unlinear (byte* bytes, long gbx)
+ {
+ bytes [3] = (byte) (gbx % 10 + 0x30);
gbx /= 10;
- bytes [start + 2] = (byte) (gbx % 126 + 0x81);
+ bytes [2] = (byte) (gbx % 126 + 0x81);
gbx /= 126;
- bytes [start + 1] = (byte) (gbx % 10 + 0x30);
+ bytes [1] = (byte) (gbx % 10 + 0x30);
gbx /= 10;
- bytes [start] = (byte) (gbx + 0x81);
+ bytes [0] = (byte) (gbx + 0x81);
}
// negative (invalid) or positive (valid)
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches