2 * CP57002.cs - ISCII code pages 57002-57011.
4 * Copyright (c) 2002 Southern Storm Software, Pty Ltd
6 * Permission is hereby granted, free of charge, to any person obtaining
7 * a copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22 * OTHER DEALINGS IN THE SOFTWARE.
32 // This class provides an abstract base for the ISCII encodings,
33 // which all have a similar pattern. Code points 0x00-0x7F are
34 // the standard ASCII character set, and code points 0x80-0xFF
35 // are a shifted version of the Unicode character set, starting
38 public abstract class ISCIIEncoding
: Encoding
42 protected String encodingName
;
43 protected String webName
;
46 protected ISCIIEncoding(int codePage
, int shift
,
47 String encodingName
, String webName
)
51 this.encodingName
= encodingName
;
52 this.webName
= webName
;
55 // Get the number of bytes needed to encode a character buffer.
56 public override int GetByteCount(char[] chars
, int index
, int count
)
60 throw new ArgumentNullException("chars");
62 if(index
< 0 || index
> chars
.Length
)
64 throw new ArgumentOutOfRangeException
65 ("index", Strings
.GetString("ArgRange_Array"));
67 if(count
< 0 || count
> (chars
.Length
- index
))
69 throw new ArgumentOutOfRangeException
70 ("count", Strings
.GetString("ArgRange_Array"));
75 // Convenience wrappers for "GetByteCount".
76 public override int GetByteCount(String s
)
80 throw new ArgumentNullException("s");
85 // Get the bytes that result from encoding a character buffer.
86 public override int GetBytes(char[] chars
, int charIndex
, int charCount
,
87 byte[] bytes
, int byteIndex
)
91 throw new ArgumentNullException("chars");
95 throw new ArgumentNullException("bytes");
97 if(charIndex
< 0 || charIndex
> chars
.Length
)
99 throw new ArgumentOutOfRangeException
100 ("charIndex", Strings
.GetString("ArgRange_Array"));
102 if(charCount
< 0 || charCount
> (chars
.Length
- charIndex
))
104 throw new ArgumentOutOfRangeException
105 ("charCount", Strings
.GetString("ArgRange_Array"));
107 if(byteIndex
< 0 || byteIndex
> bytes
.Length
)
109 throw new ArgumentOutOfRangeException
110 ("byteIndex", Strings
.GetString("ArgRange_Array"));
112 if((bytes
.Length
- byteIndex
) < charCount
)
114 throw new ArgumentException
115 (Strings
.GetString("Arg_InsufficientSpace"), "bytes");
118 // Convert the characters into bytes.
120 int posn
= byteIndex
;
121 char first
= (char)shift
;
122 char last
= (char)(shift
+ 0x7F);
123 while(charCount
-- > 0)
125 ch
= chars
[charIndex
++];
126 if(ch
< (char)0x0080)
128 // Regular ASCII subset.
129 bytes
[posn
++] = (byte)ch
;
131 else if(ch
>= first
&& ch
<= last
)
133 // ISCII range that we need to shift.
134 bytes
[posn
++] = (byte)(ch
- first
+ 0x80);
136 else if(ch
>= '\uFF01' && ch
<= '\uFF5E')
138 // ASCII full-width characters.
139 bytes
[posn
++] = (byte)(ch
- 0xFEE0);
143 bytes
[posn
++] = (byte)'?';
147 // Return the final length of the output.
148 return posn
- byteIndex
;
151 // Convenience wrappers for "GetBytes".
152 public override int GetBytes(String s
, int charIndex
, int charCount
,
153 byte[] bytes
, int byteIndex
)
155 // Validate the parameters.
158 throw new ArgumentNullException("s");
162 throw new ArgumentNullException("bytes");
164 if(charIndex
< 0 || charIndex
> s
.Length
)
166 throw new ArgumentOutOfRangeException
168 Strings
.GetString("ArgRange_StringIndex"));
170 if(charCount
< 0 || charCount
> (s
.Length
- charIndex
))
172 throw new ArgumentOutOfRangeException
174 Strings
.GetString("ArgRange_StringRange"));
176 if(byteIndex
< 0 || byteIndex
> bytes
.Length
)
178 throw new ArgumentOutOfRangeException
180 Strings
.GetString("ArgRange_Array"));
182 if((bytes
.Length
- byteIndex
) < charCount
)
184 throw new ArgumentException
185 (Strings
.GetString("Arg_InsufficientSpace"), "bytes");
188 // Convert the characters into bytes.
190 int posn
= byteIndex
;
191 char first
= (char)shift
;
192 char last
= (char)(shift
+ 0x7F);
193 while(charCount
-- > 0)
196 if(ch
< (char)0x0080)
198 // Regular ASCII subset.
199 bytes
[posn
++] = (byte)ch
;
201 else if(ch
>= first
&& ch
<= last
)
203 // ISCII range that we need to shift.
204 bytes
[posn
++] = (byte)(ch
- first
+ 0x80);
206 else if(ch
>= '\uFF01' && ch
<= '\uFF5E')
208 // ASCII full-width characters.
209 bytes
[posn
++] = (byte)(ch
- 0xFEE0);
213 bytes
[posn
++] = (byte)'?';
217 // Return the final length of the output.
218 return posn
- byteIndex
;
221 // Get the number of characters needed to decode a byte buffer.
222 public override int GetCharCount(byte[] bytes
, int index
, int count
)
226 throw new ArgumentNullException("bytes");
228 if(index
< 0 || index
> bytes
.Length
)
230 throw new ArgumentOutOfRangeException
231 ("index", Strings
.GetString("ArgRange_Array"));
233 if(count
< 0 || count
> (bytes
.Length
- index
))
235 throw new ArgumentOutOfRangeException
236 ("count", Strings
.GetString("ArgRange_Array"));
241 // Get the characters that result from decoding a byte buffer.
242 public override int GetChars(byte[] bytes
, int byteIndex
, int byteCount
,
243 char[] chars
, int charIndex
)
245 // Validate the parameters.
248 throw new ArgumentNullException("bytes");
252 throw new ArgumentNullException("chars");
254 if(byteIndex
< 0 || byteIndex
> bytes
.Length
)
256 throw new ArgumentOutOfRangeException
257 ("byteIndex", Strings
.GetString("ArgRange_Array"));
259 if(byteCount
< 0 || byteCount
> (bytes
.Length
- byteIndex
))
261 throw new ArgumentOutOfRangeException
262 ("byteCount", Strings
.GetString("ArgRange_Array"));
264 if(charIndex
< 0 || charIndex
> chars
.Length
)
266 throw new ArgumentOutOfRangeException
267 ("charIndex", Strings
.GetString("ArgRange_Array"));
269 if((chars
.Length
- charIndex
) < byteCount
)
271 throw new ArgumentException
272 (Strings
.GetString("Arg_InsufficientSpace"), "chars");
275 // Convert the bytes into characters.
276 int count
= byteCount
;
278 int shift
= this.shift
- 0x80;
281 byteval
= (int)(bytes
[byteIndex
++]);
284 // Ordinary ASCII character.
285 chars
[charIndex
++] = (char)byteval
;
289 // Shift the ISCII character into the Unicode page.
290 chars
[charIndex
++] = (char)(byteval
+ shift
);
296 // Get the maximum number of bytes needed to encode a
297 // specified number of characters.
298 public override int GetMaxByteCount(int charCount
)
302 throw new ArgumentOutOfRangeException
304 Strings
.GetString("ArgRange_NonNegative"));
309 // Get the maximum number of characters needed to decode a
310 // specified number of bytes.
311 public override int GetMaxCharCount(int byteCount
)
315 throw new ArgumentOutOfRangeException
317 Strings
.GetString("ArgRange_NonNegative"));
324 // Get the mail body name for this encoding.
325 public override String BodyName
333 // Get the human-readable name for this encoding.
334 public override String EncodingName
342 // Get the mail agent header name for this encoding.
343 public override String HeaderName
351 // Get the IANA-preferred Web name for this encoding.
352 public override String WebName
360 #endif // !ECMA_COMPAT
362 }; // class ISCIIEncoding
364 // Define the ISCII code pages as subclasses of "ISCIIEncoding".
366 public class CP57002
: ISCIIEncoding
368 public CP57002() : base(57002, 0x0900, "ISCII Devanagari", "x-iscii-de") {}
372 public class CP57003
: ISCIIEncoding
374 public CP57003() : base(57003, 0x0980, "ISCII Bengali", "x-iscii-be") {}
378 public class CP57004
: ISCIIEncoding
380 public CP57004() : base(57004, 0x0B80, "ISCII Tamil", "x-iscii-ta") {}
384 public class CP57005
: ISCIIEncoding
386 public CP57005() : base(57005, 0x0B80, "ISCII Telugu", "x-iscii-te") {}
390 public class CP57006
: ISCIIEncoding
392 // Note: Unicode has a "Sinhala" page, but no "Assamese" page.
393 // Until I hear otherwise, I will assume that they are the same
394 // thing with different names - Rhys Weatherley, 16 April 2002.
395 public CP57006() : base(57006, 0x0D80, "ISCII Assamese", "x-iscii-as") {}
399 public class CP57007
: ISCIIEncoding
401 public CP57007() : base(57007, 0x0B00, "ISCII Oriya", "x-iscii-or") {}
405 public class CP57008
: ISCIIEncoding
407 public CP57008() : base(57008, 0x0C80, "ISCII Kannada", "x-iscii-ka") {}
411 public class CP57009
: ISCIIEncoding
413 public CP57009() : base(57009, 0x0D00, "ISCII Malayalam", "x-iscii-ma") {}
417 public class CP57010
: ISCIIEncoding
419 public CP57010() : base(57010, 0x0A80, "ISCII Gujarati", "x-iscii-gu") {}
423 public class CP57011
: ISCIIEncoding
425 // Note: Unicode has a "Gurmukhi" page, but no "Punjabi" page.
426 // Other ISCII-related information on the Internet seems to
427 // indicate that they are the same. Until I hear otherwise,
428 // I will assume that they are the same thing with different
429 // names - Rhys Weatherley, 16 April 2002.
430 public CP57011() : base(57011, 0x0A00, "ISCII Punjabi", "x-iscii-pa") {}
434 // Define the web encoding name aliases for the above code pages.
436 public class ENCx_iscii_de
: CP57002
438 public ENCx_iscii_de() : base() {}
440 }; // class ENCx_iscii_de
442 public class ENCx_iscii_be
: CP57003
444 public ENCx_iscii_be() : base() {}
446 }; // class ENCx_iscii_be
448 public class ENCx_iscii_ta
: CP57004
450 public ENCx_iscii_ta() : base() {}
452 }; // class ENCx_iscii_ta
454 public class ENCx_iscii_te
: CP57005
456 public ENCx_iscii_te() : base() {}
458 }; // class ENCx_iscii_te
460 public class ENCx_iscii_as
: CP57006
462 public ENCx_iscii_as() : base() {}
464 }; // class ENCx_iscii_as
466 public class ENCx_iscii_or
: CP57007
468 public ENCx_iscii_or() : base() {}
470 }; // class ENCx_iscii_or
472 public class ENCx_iscii_ka
: CP57008
474 public ENCx_iscii_ka() : base() {}
476 }; // class ENCx_iscii_ka
478 public class ENCx_iscii_ma
: CP57009
480 public ENCx_iscii_ma() : base() {}
482 }; // class ENCx_iscii_ma
484 public class ENCx_iscii_gu
: CP57010
486 public ENCx_iscii_gu() : base() {}
488 }; // class ENCx_iscii_gu
490 public class ENCx_iscii_pa
: CP57011
492 public ENCx_iscii_pa() : base() {}
494 }; // class ENCx_iscii_pa
496 }; // namespace I18N.Other