diff options
Diffstat (limited to 'mcs/class/I18N/CJK/ISO2022JP.cs')
-rw-r--r-- | mcs/class/I18N/CJK/ISO2022JP.cs | 88 |
1 files changed, 42 insertions, 46 deletions
diff --git a/mcs/class/I18N/CJK/ISO2022JP.cs b/mcs/class/I18N/CJK/ISO2022JP.cs index 4447a796399..fea787bfb90 100644 --- a/mcs/class/I18N/CJK/ISO2022JP.cs +++ b/mcs/class/I18N/CJK/ISO2022JP.cs @@ -1,15 +1,12 @@ -// -// ISO2022JP.cs -// -// Author: -// Atsushi Enomoto <atsushi@ximian.com> -// using System; using System.Text; using I18N.Common; namespace I18N.CJK { + // FIXME: + // find out what is the difference between 50220, 50221 and 50222. + [Serializable] public class CP50220 : ISO2022JPEncoding { @@ -52,8 +49,10 @@ namespace I18N.CJK [Serializable] public class ISO2022JPEncoding : MonoEncoding { + static JISConvert convert = JISConvert.Convert; + public ISO2022JPEncoding (int codePage, bool allow1ByteKana, bool allowShiftIO) - : base (codePage, 932) + : base (codePage) { this.allow_1byte_kana = allow1ByteKana; this.allow_shift_io = allowShiftIO; @@ -90,11 +89,6 @@ namespace I18N.CJK return new ISO2022JPEncoder (this, allow_1byte_kana, allow_shift_io).GetByteCount (chars, charIndex, charCount, true); } - public unsafe override int GetByteCountImpl (char* chars, int count) - { - return new ISO2022JPEncoder (this, allow_1byte_kana, allow_shift_io).GetByteCountImpl (chars, count, true); - } - public unsafe override int GetBytesImpl (char* chars, int charCount, byte* bytes, int byteCount) { return new ISO2022JPEncoder (this, allow_1byte_kana, allow_shift_io).GetBytesImpl (chars, charCount, bytes, byteCount, true); @@ -117,14 +111,14 @@ namespace I18N.CJK JISX0201 } - internal class ISO2022JPEncoder : MonoEncoder + internal class ISO2022JPEncoder : MonoEncoding.MonoEncoder { static JISConvert convert = JISConvert.Convert; readonly bool allow_1byte_kana, allow_shift_io; ISO2022JPMode m = ISO2022JPMode.ASCII; - bool shifted_in_count, shifted_in_conv; + bool shifted_in; public ISO2022JPEncoder (MonoEncoding owner, bool allow1ByteKana, bool allowShiftIO) : base (owner) @@ -133,10 +127,9 @@ namespace I18N.CJK this.allow_shift_io = allowShiftIO; } - public unsafe override int GetByteCountImpl (char* chars, int charCount, bool flush) + public override int GetByteCount (char [] chars, int charIndex, int charCount, bool flush) { - int charIndex = 0; - int end = charCount; + int end = charIndex + charCount; int value; int byteCount = 0; @@ -151,8 +144,8 @@ namespace I18N.CJK if (ch >= 0x2010 && ch <= 0x9FA5) { - if (shifted_in_count) { - shifted_in_count = false; + if (shifted_in) { + shifted_in = false; byteCount++; // shift_out } if (m != ISO2022JPMode.JISX0208) @@ -163,8 +156,8 @@ namespace I18N.CJK value = ((int)(convert.cjkToJis[value])) | (((int)(convert.cjkToJis[value + 1])) << 8); } else if (ch >= 0xFF01 && ch <= 0xFF60) { - if (shifted_in_count) { - shifted_in_count = false; + if (shifted_in) { + shifted_in = false; byteCount++; } if (m != ISO2022JPMode.JISX0208) @@ -177,9 +170,9 @@ namespace I18N.CJK (((int)(convert.extraToJis[value + 1])) << 8); } else if(ch >= 0xFF60 && ch <= 0xFFA0) { if (allow_shift_io) { - if (!shifted_in_count) { + if (!shifted_in) { byteCount++; - shifted_in_count = true; + shifted_in = true; } } else if (m != ISO2022JPMode.JISX0201) { @@ -188,8 +181,8 @@ namespace I18N.CJK } value = ch - 0xFF60 + 0xA0; } else if (ch < 128) { - if (shifted_in_count) { - shifted_in_count = false; + if (shifted_in) { + shifted_in = false; byteCount++; } if (m != ISO2022JPMode.ASCII) @@ -207,8 +200,8 @@ namespace I18N.CJK } // must end in ASCII mode if (flush) { - if (shifted_in_count) { - shifted_in_count = false; + if (shifted_in) { + shifted_in = false; byteCount++; } if (m != ISO2022JPMode.ASCII) @@ -253,6 +246,9 @@ namespace I18N.CJK { int charIndex = 0; int byteIndex = 0; +#if NET_2_0 + EncoderFallbackBuffer buffer = null; +#endif int start = byteIndex; int end = charIndex + charCount; @@ -270,9 +266,9 @@ namespace I18N.CJK if (ch >= 0x2010 && ch <= 0x9FA5) { - if (shifted_in_conv) { + if (shifted_in) { bytes [byteIndex++] = 0x0F; - shifted_in_conv = false; + shifted_in = false; byteCount--; } switch (m) { @@ -287,9 +283,9 @@ namespace I18N.CJK value = ((int)(convert.cjkToJis[value])) | (((int)(convert.cjkToJis[value + 1])) << 8); } else if (ch >= 0xFF01 && ch <= 0xFF60) { - if (shifted_in_conv) { + if (shifted_in) { bytes [byteIndex++] = 0x0F; - shifted_in_conv = false; + shifted_in = false; byteCount--; } switch (m) { @@ -310,9 +306,9 @@ namespace I18N.CJK // so here we don't have to consider it. if (allow_shift_io) { - if (!shifted_in_conv) { + if (!shifted_in) { bytes [byteIndex++] = 0x0E; - shifted_in_conv = true; + shifted_in = true; byteCount--; } } else { @@ -326,9 +322,9 @@ namespace I18N.CJK } value = ch - 0xFF40; } else if (ch < 128) { - if (shifted_in_conv) { + if (shifted_in) { bytes [byteIndex++] = 0x0F; - shifted_in_conv = false; + shifted_in = false; byteCount--; } SwitchMode (bytes, ref byteIndex, ref byteCount, ref m, ISO2022JPMode.ASCII); @@ -357,9 +353,9 @@ namespace I18N.CJK } if (flush) { // must end in ASCII mode - if (shifted_in_conv) { + if (shifted_in) { bytes [byteIndex++] = 0x0F; - shifted_in_conv = false; + shifted_in = false; byteCount--; } if (m != ISO2022JPMode.ASCII) @@ -372,7 +368,7 @@ namespace I18N.CJK public override void Reset () { m = ISO2022JPMode.ASCII; - shifted_in_conv = shifted_in_count = false; + shifted_in = false; } #endif } @@ -383,7 +379,7 @@ namespace I18N.CJK readonly bool allow_shift_io; ISO2022JPMode m = ISO2022JPMode.ASCII; - bool shifted_in_conv, shifted_in_count; + bool shifted_in; public ISO2022JPDecoder (bool allow1ByteKana, bool allowShiftIO) { @@ -400,15 +396,15 @@ namespace I18N.CJK if (allow_shift_io) { switch (bytes [i]) { case 0x0F: - shifted_in_count = false; + shifted_in = false; continue; case 0x0E: - shifted_in_count = true; + shifted_in = true; continue; } } if (bytes [i] != 0x1B) { - if (!shifted_in_count && m == ISO2022JPMode.JISX0208) { + if (!shifted_in && m == ISO2022JPMode.JISX0208) { if (i + 1 == end) break; // incomplete head of wide char else @@ -457,16 +453,16 @@ namespace I18N.CJK if (allow_shift_io) { switch (bytes [i]) { case 0x0F: - shifted_in_conv = false; + shifted_in = false; continue; case 0x0E: - shifted_in_conv = true; + shifted_in = true; continue; } } if (bytes [i] != 0x1B) { - if (shifted_in_conv || m == ISO2022JPMode.JISX0201) { + if (shifted_in || m == ISO2022JPMode.JISX0201) { // half-kana if (bytes [i] < 0x60) chars [charIndex++] = (char) (bytes [i] + 0xFF40); @@ -528,7 +524,7 @@ namespace I18N.CJK public override void Reset () { m = ISO2022JPMode.ASCII; - shifted_in_count = shifted_in_conv = false; + shifted_in = false; } #endif } |