+//
+// 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
{
[Serializable]
public class ISO2022JPEncoding : MonoEncoding
{
- static JISConvert convert = JISConvert.Convert;
-
public ISO2022JPEncoding (int codePage, bool allow1ByteKana, bool allowShiftIO)
- : base (codePage)
+ : base (codePage, 932)
{
this.allow_1byte_kana = allow1ByteKana;
this.allow_shift_io = allowShiftIO;
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);
JISX0201
}
- internal class ISO2022JPEncoder : MonoEncoding.MonoEncoder
+ internal class ISO2022JPEncoder : MonoEncoder
{
static JISConvert convert = JISConvert.Convert;
readonly bool allow_1byte_kana, allow_shift_io;
ISO2022JPMode m = ISO2022JPMode.ASCII;
- bool shifted_in;
+ bool shifted_in_count, shifted_in_conv;
public ISO2022JPEncoder (MonoEncoding owner, bool allow1ByteKana, bool allowShiftIO)
: base (owner)
this.allow_shift_io = allowShiftIO;
}
- public override int GetByteCount (char [] chars, int charIndex, int charCount, bool flush)
+ public unsafe override int GetByteCountImpl (char* chars, int charCount, bool flush)
{
- int end = charIndex + charCount;
+ int charIndex = 0;
+ int end = charCount;
int value;
int byteCount = 0;
if (ch >= 0x2010 && ch <= 0x9FA5)
{
- if (shifted_in) {
- shifted_in = false;
+ if (shifted_in_count) {
+ shifted_in_count = false;
byteCount++; // shift_out
}
if (m != ISO2022JPMode.JISX0208)
value = ((int)(convert.cjkToJis[value])) |
(((int)(convert.cjkToJis[value + 1])) << 8);
} else if (ch >= 0xFF01 && ch <= 0xFF60) {
- if (shifted_in) {
- shifted_in = false;
+ if (shifted_in_count) {
+ shifted_in_count = false;
byteCount++;
}
if (m != ISO2022JPMode.JISX0208)
(((int)(convert.extraToJis[value + 1])) << 8);
} else if(ch >= 0xFF60 && ch <= 0xFFA0) {
if (allow_shift_io) {
- if (!shifted_in) {
+ if (!shifted_in_count) {
byteCount++;
- shifted_in = true;
+ shifted_in_count = true;
}
}
else if (m != ISO2022JPMode.JISX0201) {
}
value = ch - 0xFF60 + 0xA0;
} else if (ch < 128) {
- if (shifted_in) {
- shifted_in = false;
+ if (shifted_in_count) {
+ shifted_in_count = false;
byteCount++;
}
if (m != ISO2022JPMode.ASCII)
}
// must end in ASCII mode
if (flush) {
- if (shifted_in) {
- shifted_in = false;
+ if (shifted_in_count) {
+ shifted_in_count = false;
byteCount++;
}
if (m != ISO2022JPMode.ASCII)
{
int charIndex = 0;
int byteIndex = 0;
-#if NET_2_0
- EncoderFallbackBuffer buffer = null;
-#endif
int start = byteIndex;
int end = charIndex + charCount;
if (ch >= 0x2010 && ch <= 0x9FA5)
{
- if (shifted_in) {
+ if (shifted_in_conv) {
bytes [byteIndex++] = 0x0F;
- shifted_in = false;
+ shifted_in_conv = false;
byteCount--;
}
switch (m) {
value = ((int)(convert.cjkToJis[value])) |
(((int)(convert.cjkToJis[value + 1])) << 8);
} else if (ch >= 0xFF01 && ch <= 0xFF60) {
- if (shifted_in) {
+ if (shifted_in_conv) {
bytes [byteIndex++] = 0x0F;
- shifted_in = false;
+ shifted_in_conv = false;
byteCount--;
}
switch (m) {
// so here we don't have to consider it.
if (allow_shift_io) {
- if (!shifted_in) {
+ if (!shifted_in_conv) {
bytes [byteIndex++] = 0x0E;
- shifted_in = true;
+ shifted_in_conv = true;
byteCount--;
}
} else {
}
value = ch - 0xFF40;
} else if (ch < 128) {
- if (shifted_in) {
+ if (shifted_in_conv) {
bytes [byteIndex++] = 0x0F;
- shifted_in = false;
+ shifted_in_conv = false;
byteCount--;
}
SwitchMode (bytes, ref byteIndex, ref byteCount, ref m, ISO2022JPMode.ASCII);
}
if (flush) {
// must end in ASCII mode
- if (shifted_in) {
+ if (shifted_in_conv) {
bytes [byteIndex++] = 0x0F;
- shifted_in = false;
+ shifted_in_conv = false;
byteCount--;
}
if (m != ISO2022JPMode.ASCII)
public override void Reset ()
{
m = ISO2022JPMode.ASCII;
- shifted_in = false;
+ shifted_in_conv = shifted_in_count = false;
}
#endif
}
readonly bool allow_shift_io;
ISO2022JPMode m = ISO2022JPMode.ASCII;
- bool shifted_in;
+ bool shifted_in_conv, shifted_in_count;
public ISO2022JPDecoder (bool allow1ByteKana, bool allowShiftIO)
{
if (allow_shift_io) {
switch (bytes [i]) {
case 0x0F:
- shifted_in = false;
+ shifted_in_count = false;
continue;
case 0x0E:
- shifted_in = true;
+ shifted_in_count = true;
continue;
}
}
if (bytes [i] != 0x1B) {
- if (!shifted_in && m == ISO2022JPMode.JISX0208) {
+ if (!shifted_in_count && m == ISO2022JPMode.JISX0208) {
if (i + 1 == end)
break; // incomplete head of wide char
else
if (allow_shift_io) {
switch (bytes [i]) {
case 0x0F:
- shifted_in = false;
+ shifted_in_conv = false;
continue;
case 0x0E:
- shifted_in = true;
+ shifted_in_conv = true;
continue;
}
}
if (bytes [i] != 0x1B) {
- if (shifted_in || m == ISO2022JPMode.JISX0201) {
+ if (shifted_in_conv || m == ISO2022JPMode.JISX0201) {
// half-kana
if (bytes [i] < 0x60)
chars [charIndex++] = (char) (bytes [i] + 0xFF40);
public override void Reset ()
{
m = ISO2022JPMode.ASCII;
- shifted_in = false;
+ shifted_in_count = shifted_in_conv = false;
}
#endif
}