2 // I18N.CJK.DbcsEncoding
5 // Alan Tam Siu Lung (Tam@SiuLung.com)
15 internal abstract class DbcsEncoding
: MonoEncoding
17 public DbcsEncoding (int codePage
) : this (codePage
, 0)
21 public DbcsEncoding (int codePage
, int windowsCodePage
)
22 : base (codePage
, windowsCodePage
)
26 internal abstract DbcsConvert
GetConvert ();
28 // Get the number of bytes needed to encode a character buffer.
29 public override int GetByteCount(char[] chars
, int index
, int count
)
32 throw new ArgumentNullException("chars");
33 if (index
< 0 || index
> chars
.Length
)
34 throw new ArgumentOutOfRangeException("index", Strings
.GetString("ArgRange_Array"));
35 if (count
< 0 || index
+ count
> chars
.Length
)
36 throw new ArgumentOutOfRangeException("count", Strings
.GetString("ArgRange_Array"));
37 byte[] buffer
= new byte[count
* 2];
38 return GetBytes(chars
, index
, count
, buffer
, 0);
42 // Get the bytes that result from encoding a character buffer.
43 public override int GetBytes(char[] chars, int charIndex, int charCount,
44 byte[] bytes, int byteIndex)
47 throw new ArgumentNullException("chars");
49 throw new ArgumentNullException("bytes");
50 if (charIndex < 0 || charIndex > chars.Length)
51 throw new ArgumentOutOfRangeException("charIndex", Strings.GetString("ArgRange_Array"));
52 if (charCount < 0 || charIndex + charCount > chars.Length)
53 throw new ArgumentOutOfRangeException("charCount", Strings.GetString("ArgRange_Array"));
54 if (byteIndex < 0 || byteIndex > bytes.Length)
55 throw new ArgumentOutOfRangeException("byteIndex", Strings.GetString("ArgRange_Array"));
56 return 0; // For subclasses to implement
60 // Get the number of characters needed to decode a byte buffer.
61 public override int GetCharCount(byte[] bytes
, int index
, int count
)
64 throw new ArgumentNullException("bytes");
65 if (index
< 0 || index
> bytes
.Length
)
66 throw new ArgumentOutOfRangeException("index", Strings
.GetString("ArgRange_Array"));
67 if (count
< 0 || index
+ count
> bytes
.Length
)
68 throw new ArgumentOutOfRangeException("count", Strings
.GetString("ArgRange_Array"));
69 char[] buffer
= new char[count
];
70 return GetChars(bytes
, index
, count
, buffer
, 0);
73 // Get the characters that result from decoding a byte buffer.
74 public override int GetChars(byte[] bytes
, int byteIndex
, int byteCount
,
75 char[] chars
, int charIndex
)
78 throw new ArgumentNullException("bytes");
80 throw new ArgumentNullException("chars");
81 if (byteIndex
< 0 || byteIndex
> bytes
.Length
)
82 throw new ArgumentOutOfRangeException("byteIndex", Strings
.GetString("ArgRange_Array"));
83 if (byteCount
< 0 || byteIndex
+ byteCount
> bytes
.Length
)
84 throw new ArgumentOutOfRangeException("byteCount", Strings
.GetString("ArgRange_Array"));
85 if (charIndex
< 0 || charIndex
> chars
.Length
)
86 throw new ArgumentOutOfRangeException("charIndex", Strings
.GetString("ArgRange_Array"));
87 return 0; // For subclasses to implement
90 // Get the maximum number of bytes needed to encode a
91 // specified number of characters.
92 public override int GetMaxByteCount(int charCount
)
95 throw new ArgumentOutOfRangeException("charCount", Strings
.GetString("ArgRange_NonNegative"));
99 // Get the maximum number of characters needed to decode a
100 // specified number of bytes.
101 public override int GetMaxCharCount(int byteCount
)
104 throw new ArgumentOutOfRangeException("byteCount", Strings
.GetString("ArgRange_NonNegative"));
109 // Determine if this encoding can be displayed in a Web browser.
110 public override bool IsBrowserDisplay
115 // Determine if this encoding can be saved from a Web browser.
116 public override bool IsBrowserSave
121 // Determine if this encoding can be displayed in a mail/news agent.
122 public override bool IsMailNewsDisplay
127 // Determine if this encoding can be saved from a mail/news agent.
128 public override bool IsMailNewsSave
133 // Decoder that handles a rolling state.
134 internal abstract class DbcsDecoder
: Decoder
136 protected DbcsConvert convert
;
139 public DbcsDecoder(DbcsConvert convert
)
141 this.convert
= convert
;
144 internal void CheckRange (byte[] bytes
, int index
, int count
)
147 throw new ArgumentNullException("bytes");
148 if (index
< 0 || index
> bytes
.Length
)
149 throw new ArgumentOutOfRangeException("index", Strings
.GetString("ArgRange_Array"));
150 if (count
< 0 || count
> (bytes
.Length
- index
))
151 throw new ArgumentOutOfRangeException("count", Strings
.GetString("ArgRange_Array"));
154 internal void CheckRange (byte[] bytes
, int byteIndex
, int byteCount
,
155 char[] chars
, int charIndex
)
158 throw new ArgumentNullException("bytes");
160 throw new ArgumentNullException("chars");
161 if (byteIndex
< 0 || byteIndex
> bytes
.Length
)
162 throw new ArgumentOutOfRangeException("byteIndex", Strings
.GetString("ArgRange_Array"));
163 if (byteCount
< 0 || byteIndex
+ byteCount
> bytes
.Length
)
164 throw new ArgumentOutOfRangeException("byteCount", Strings
.GetString("ArgRange_Array"));
165 if (charIndex
< 0 || charIndex
> chars
.Length
)
166 throw new ArgumentOutOfRangeException("charIndex", Strings
.GetString("ArgRange_Array"));