(DISTFILES): Comment out a few missing files.
[mono-project.git] / mcs / class / I18N / CJK / CP950.cs
blob785b9cb412825ae9c99b434afad42c0a47cc4576
1 //
2 // I18N.CJK.CP950
3 //
4 // Author:
5 // Alan Tam Siu Lung (Tam@SiuLung.com)
6 //
8 using System;
9 using System.Text;
10 using I18N.Common;
12 namespace I18N.CJK
14 internal class CP950 : DbcsEncoding
16 // Magic number used by Windows for the Big5 code page.
17 private const int BIG5_CODE_PAGE = 950;
19 // Constructor.
20 public CP950() : base(BIG5_CODE_PAGE) {
21 convert = Big5Convert.Convert;
24 // Get the bytes that result from encoding a character buffer.
25 public override int GetBytes(char[] chars, int charIndex, int charCount,
26 byte[] bytes, int byteIndex)
28 // 00 00 - FF FF
29 base.GetBytes(chars, charIndex, charCount, bytes, byteIndex);
30 int origIndex = byteIndex;
31 while (charCount-- > 0) {
32 char c = chars[charIndex++];
33 if (c <= 0x80 || c == 0xFF) { // ASCII
34 bytes[byteIndex++] = (byte)c;
35 continue;
37 byte b1 = convert.u2n[((int)c) * 2 + 1];
38 byte b2 = convert.u2n[((int)c) * 2];
39 if (b1 == 0 && b2 == 0) {
40 bytes[byteIndex++] = (byte)'?';
41 } else {
42 bytes[byteIndex++] = b1;
43 bytes[byteIndex++] = b2;
46 return byteIndex - origIndex;
49 // Get the characters that result from decoding a byte buffer.
50 public override int GetChars(byte[] bytes, int byteIndex, int byteCount,
51 char[] chars, int charIndex)
53 // A1 40 - FA FF
54 base.GetChars(bytes, byteIndex, byteCount, chars, charIndex);
55 int origIndex = charIndex;
56 int lastByte = 0;
57 while (byteCount-- > 0) {
58 int b = bytes[byteIndex++];
59 if (lastByte == 0) {
60 if (b <= 0x80 || b == 0xFF) { // ASCII
61 chars[charIndex++] = (char)b;
62 continue;
63 } else if (b < 0xA1 || b >= 0xFA) {
64 continue;
65 } else {
66 lastByte = b;
67 continue;
70 int ord = ((lastByte - 0xA1) * 191 + b - 0x40) * 2;
71 char c1 = (char)(convert.n2u[ord] + convert.n2u[ord + 1] * 256);
72 if (c1 == 0)
73 chars[charIndex++] = '?';
74 else
75 chars[charIndex++] = c1;
76 lastByte = 0;
78 return charIndex - origIndex;
81 // Get a decoder that handles a rolling Big5 state.
82 public override Decoder GetDecoder()
84 return new CP950Decoder(convert);
87 // Get the mail body name for this encoding.
88 public override String BodyName
90 get { return "big5"; }
93 // Get the human-readable name for this encoding.
94 public override String EncodingName
96 get { return "Chinese Traditional (Big5)"; }
99 // Get the mail agent header name for this encoding.
100 public override String HeaderName
102 get { return "big5"; }
105 // Get the IANA-preferred Web name for this encoding.
106 public override String WebName
108 get { return "big5"; }
112 // Get the Windows code page represented by this object.
113 public override int WindowsCodePage
115 get { return BIG5_PAGE; }
119 // Decoder that handles a rolling Big5 state.
120 private sealed class CP950Decoder : DbcsDecoder
122 // Constructor.
123 public CP950Decoder(DbcsConvert convert) : base(convert) {}
125 public override int GetChars(byte[] bytes, int byteIndex, int byteCount,
126 char[] chars, int charIndex)
128 base.GetChars(bytes, byteIndex, byteCount, chars, charIndex);
129 int origIndex = charIndex;
130 while (byteCount-- > 0) {
131 int b = bytes[byteIndex++];
132 if (lastByte == 0) {
133 if (b <= 0x80 || b == 0xFF) { // ASCII
134 chars[charIndex++] = (char)b;
135 continue;
136 } else if (b < 0xA1 || b >= 0xFA) {
137 continue;
138 } else {
139 lastByte = b;
140 continue;
143 int ord = ((lastByte - 0xA1) * 191 + b - 0x40) * 2;
144 char c1 = (char)(convert.n2u[ord] + convert.n2u[ord + 1] * 256);
145 if (c1 == 0) {
146 chars[charIndex++] = '?';
147 } else {
148 chars[charIndex++] = c1;
150 lastByte = 0;
152 return charIndex - origIndex;
157 internal class ENCbig5 : CP950
159 public ENCbig5() {}