diff options
Diffstat (limited to 'mcs/class/I18N/CJK/GB18030Encoding.cs')
-rw-r--r-- | mcs/class/I18N/CJK/GB18030Encoding.cs | 73 |
1 files changed, 31 insertions, 42 deletions
diff --git a/mcs/class/I18N/CJK/GB18030Encoding.cs b/mcs/class/I18N/CJK/GB18030Encoding.cs index 2cb1ff12152..fa761afeea5 100644 --- a/mcs/class/I18N/CJK/GB18030Encoding.cs +++ b/mcs/class/I18N/CJK/GB18030Encoding.cs @@ -25,7 +25,7 @@ namespace I18N.CJK { // Constructor. public GB18030Encoding () - : base (54936, 936) + : base (54936) { } @@ -33,34 +33,10 @@ namespace I18N.CJK get { return "Chinese Simplified (GB18030)"; } } - public override string HeaderName { - get { return "GB18030"; } - } - - public override string BodyName { - get { return "GB18030"; } - } - public override string WebName { get { return "GB18030"; } } - public override bool IsMailNewsDisplay { - get { return true; } - } - - public override bool IsMailNewsSave { - get { return true; } - } - - public override bool IsBrowserDisplay { - get { return true; } - } - - public override bool IsBrowserSave { - get { return true; } - } - public override int GetMaxByteCount (int len) { // non-GB2312 characters in \u0080 - \uFFFF @@ -77,11 +53,6 @@ namespace I18N.CJK return new GB18030Encoder (this).GetByteCount (chars, index, length, true); } - public unsafe override int GetByteCountImpl (char* chars, int count) - { - return new GB18030Encoder (this).GetByteCountImpl (chars, count, true); - } - public unsafe override int GetBytesImpl (char* chars, int charCount, byte* bytes, int byteCount) { return new GB18030Encoder (this).GetBytesImpl (chars, charCount, bytes, byteCount, true); @@ -108,20 +79,20 @@ namespace I18N.CJK } } - class GB18030Decoder : DbcsEncoding.DbcsDecoder + class GB18030Decoder : Decoder { static DbcsConvert gb2312 = DbcsConvert.Gb2312; // for now incomplete block is not supported - should we? // int incomplete1 = -1, incomplete2 = -1, incomplete3 = -1; - public GB18030Decoder () - : base (null) - { - } - public override int GetCharCount (byte [] bytes, int start, int len) { - CheckRange (bytes, start, len); + if (bytes == null) + throw new ArgumentNullException ("bytes"); + if (start < 0 || start > bytes.Length) + throw new ArgumentOutOfRangeException ("start"); + if (len < 0 || start + len > bytes.Length) + throw new ArgumentOutOfRangeException ("len"); int end = start + len; int ret = 0; @@ -195,7 +166,16 @@ namespace I18N.CJK public override int GetChars (byte [] bytes, int byteIndex, int byteCount, char [] chars, int charIndex) { - CheckRange (bytes, byteIndex, byteCount, chars, charIndex); + if (bytes == null) + throw new ArgumentNullException ("bytes"); + if (chars == null) + throw new ArgumentNullException ("chars"); + if (byteIndex < 0 || byteIndex > bytes.Length) + throw new ArgumentOutOfRangeException ("byteIndex"); + if (byteCount < 0 || byteIndex + byteCount > bytes.Length) + throw new ArgumentOutOfRangeException ("byteCount"); + if (charIndex < 0 || charIndex > chars.Length) + throw new ArgumentOutOfRangeException ("charIndex"); int byteEnd = byteIndex + byteCount; int charStart = charIndex; @@ -274,7 +254,7 @@ namespace I18N.CJK } } - class GB18030Encoder : MonoEncoder + class GB18030Encoder : MonoEncoding.MonoEncoder { static DbcsConvert gb2312 = DbcsConvert.Gb2312; @@ -286,10 +266,16 @@ namespace I18N.CJK char incomplete_byte_count; char incomplete_bytes; - public unsafe override int GetByteCountImpl (char* chars, int count, bool refresh) + public override int GetByteCount (char [] chars, int start, int len, bool refresh) { - int start = 0; - int end = count; + if (chars == null) + throw new ArgumentNullException ("chars"); + if (start < 0 || start > chars.Length) + throw new ArgumentOutOfRangeException ("index"); + if (len < 0 || start + len > chars.Length) + throw new ArgumentOutOfRangeException ("count"); + + int end = start + len; int ret = 0; while (start < end) { char ch = chars [start]; @@ -347,6 +333,9 @@ namespace I18N.CJK { int charIndex = 0; int byteIndex = 0; +#if NET_2_0 + EncoderFallbackBuffer buffer = null; +#endif int charEnd = charIndex + charCount; int byteStart = byteIndex; |