2 * CP57002.cs - ISCII code pages 57002-57011.
4 * Atsushi Enomoto <atsushi@ximian.com> (C) 2005 Novell, Inc.
8 * Copyright (c) 2002 Southern Storm Software, Pty Ltd
10 * Permission is hereby granted, free of charge, to any person obtaining
11 * a copy of this software and associated documentation files (the "Software"),
12 * to deal in the Software without restriction, including without limitation
13 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
14 * and/or sell copies of the Software, and to permit persons to whom the
15 * Software is furnished to do so, subject to the following conditions:
17 * The above copyright notice and this permission notice shall be included
18 * in all copies or substantial portions of the Software.
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
24 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
25 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
26 * OTHER DEALINGS IN THE SOFTWARE.
36 // This class provides an abstract base for the ISCII encodings,
37 // which all have a similar pattern. Code points 0x00-0x7F are
38 // the standard ASCII character set, and code points 0x80-0xFF
39 // are a shifted version of the Unicode character set, starting
43 public abstract class ISCIIEncoding
: MonoEncoding
51 protected ISCIIEncoding(int codePage
, int shift
,
52 String encodingName
, String webName
)
56 this.encodingName
= encodingName
;
57 this.webName
= webName
;
60 // Get the number of bytes needed to encode a character buffer.
61 public override int GetByteCount(char[] chars
, int index
, int count
)
65 throw new ArgumentNullException("chars");
67 if(index
< 0 || index
> chars
.Length
)
69 throw new ArgumentOutOfRangeException
70 ("index", Strings
.GetString("ArgRange_Array"));
72 if(count
< 0 || count
> (chars
.Length
- index
))
74 throw new ArgumentOutOfRangeException
75 ("count", Strings
.GetString("ArgRange_Array"));
80 // Convenience wrappers for "GetByteCount".
81 public override int GetByteCount(String s
)
85 throw new ArgumentNullException("s");
90 public unsafe override int GetByteCountImpl (char* chars
, int count
)
95 char first
= (char)shift
;
96 char last
= (char)(shift
+ 0x7F);
101 if(ch
< (char)0x0080)
103 // Regular ASCII subset.
106 else if(ch
>= first
&& ch
<= last
)
108 // ISCII range that we need to shift.
111 else if(ch
>= '\uFF01' && ch
<= '\uFF5E')
113 // ASCII full-width characters.
118 // FIXME: implement fallback support for GetByteCountImpl().
124 // Return the final length of the output.
128 public unsafe override int GetBytesImpl (char* chars
, int charCount
, byte* bytes
, int byteCount
)
130 EncoderFallbackBuffer buffer
= null;
137 throw new ArgumentNullException("chars");
141 throw new ArgumentNullException("bytes");
144 // Convert the characters into bytes.
146 int posn
= byteIndex
;
147 char first
= (char)shift
;
148 char last
= (char)(shift
+ 0x7F);
150 for (int i
= 0; i
< end
; i
++, charCount
--)
153 if(ch
< (char)0x0080)
155 // Regular ASCII subset.
156 bytes
[posn
++] = (byte)ch
;
158 else if(ch
>= first
&& ch
<= last
)
160 // ISCII range that we need to shift.
161 bytes
[posn
++] = (byte)(ch
- first
+ 0x80);
163 else if(ch
>= '\uFF01' && ch
<= '\uFF5E')
165 // ASCII full-width characters.
166 bytes
[posn
++] = (byte)(ch
- 0xFEE0);
170 HandleFallback (ref buffer
, chars
, ref i
, ref charCount
, bytes
, ref posn
, ref byteCount
);
176 // Return the final length of the output.
177 return posn
- byteIndex
;
181 // Convenience wrappers for "GetBytes".
182 public override int GetBytes(String s, int charIndex, int charCount,
183 byte[] bytes, int byteIndex)
185 // Validate the parameters.
188 throw new ArgumentNullException("s");
192 throw new ArgumentNullException("bytes");
194 if(charIndex < 0 || charIndex > s.Length)
196 throw new ArgumentOutOfRangeException
198 Strings.GetString("ArgRange_StringIndex"));
200 if(charCount < 0 || charCount > (s.Length - charIndex))
202 throw new ArgumentOutOfRangeException
204 Strings.GetString("ArgRange_StringRange"));
206 if(byteIndex < 0 || byteIndex > bytes.Length)
208 throw new ArgumentOutOfRangeException
210 Strings.GetString("ArgRange_Array"));
212 if((bytes.Length - byteIndex) < charCount)
214 throw new ArgumentException
215 (Strings.GetString("Arg_InsufficientSpace"), "bytes");
218 // Convert the characters into bytes.
220 int posn = byteIndex;
221 char first = (char)shift;
222 char last = (char)(shift + 0x7F);
223 while(charCount-- > 0)
226 if(ch < (char)0x0080)
228 // Regular ASCII subset.
229 bytes[posn++] = (byte)ch;
231 else if(ch >= first && ch <= last)
233 // ISCII range that we need to shift.
234 bytes[posn++] = (byte)(ch - first + 0x80);
236 else if(ch >= '\uFF01' && ch <= '\uFF5E')
238 // ASCII full-width characters.
239 bytes[posn++] = (byte)(ch - 0xFEE0);
243 bytes[posn++] = (byte)'?';
247 // Return the final length of the output.
248 return posn - byteIndex;
252 // Get the number of characters needed to decode a byte buffer.
253 public override int GetCharCount(byte[] bytes
, int index
, int count
)
257 throw new ArgumentNullException("bytes");
259 if(index
< 0 || index
> bytes
.Length
)
261 throw new ArgumentOutOfRangeException
262 ("index", Strings
.GetString("ArgRange_Array"));
264 if(count
< 0 || count
> (bytes
.Length
- index
))
266 throw new ArgumentOutOfRangeException
267 ("count", Strings
.GetString("ArgRange_Array"));
272 // Get the characters that result from decoding a byte buffer.
273 public override int GetChars(byte[] bytes
, int byteIndex
, int byteCount
,
274 char[] chars
, int charIndex
)
276 // Validate the parameters.
279 throw new ArgumentNullException("bytes");
283 throw new ArgumentNullException("chars");
285 if(byteIndex
< 0 || byteIndex
> bytes
.Length
)
287 throw new ArgumentOutOfRangeException
288 ("byteIndex", Strings
.GetString("ArgRange_Array"));
290 if(byteCount
< 0 || byteCount
> (bytes
.Length
- byteIndex
))
292 throw new ArgumentOutOfRangeException
293 ("byteCount", Strings
.GetString("ArgRange_Array"));
295 if(charIndex
< 0 || charIndex
> chars
.Length
)
297 throw new ArgumentOutOfRangeException
298 ("charIndex", Strings
.GetString("ArgRange_Array"));
300 if((chars
.Length
- charIndex
) < byteCount
)
302 throw new ArgumentException
303 (Strings
.GetString("Arg_InsufficientSpace"), "chars");
306 // Convert the bytes into characters.
307 int count
= byteCount
;
309 int shift
= this.shift
- 0x80;
312 byteval
= (int)(bytes
[byteIndex
++]);
315 // Ordinary ASCII character.
316 chars
[charIndex
++] = (char)byteval
;
320 // Shift the ISCII character into the Unicode page.
321 chars
[charIndex
++] = (char)(byteval
+ shift
);
327 // Get the maximum number of bytes needed to encode a
328 // specified number of characters.
329 public override int GetMaxByteCount(int charCount
)
333 throw new ArgumentOutOfRangeException
335 Strings
.GetString("ArgRange_NonNegative"));
340 // Get the maximum number of characters needed to decode a
341 // specified number of bytes.
342 public override int GetMaxCharCount(int byteCount
)
346 throw new ArgumentOutOfRangeException
348 Strings
.GetString("ArgRange_NonNegative"));
355 // Get the mail body name for this encoding.
356 public override String BodyName
364 // Get the human-readable name for this encoding.
365 public override String EncodingName
373 // Get the mail agent header name for this encoding.
374 public override String HeaderName
382 // Get the IANA-preferred Web name for this encoding.
383 public override String WebName
391 #endif // !ECMA_COMPAT
393 }; // class ISCIIEncoding
395 // Define the ISCII code pages as subclasses of "ISCIIEncoding".
398 public class CP57002
: ISCIIEncoding
400 public CP57002() : base(57002, 0x0900, "ISCII Devanagari", "x-iscii-de") {}
405 public class CP57003
: ISCIIEncoding
407 public CP57003() : base(57003, 0x0980, "ISCII Bengali", "x-iscii-be") {}
412 public class CP57004
: ISCIIEncoding
414 public CP57004() : base(57004, 0x0B80, "ISCII Tamil", "x-iscii-ta") {}
419 public class CP57005
: ISCIIEncoding
421 public CP57005() : base(57005, 0x0B80, "ISCII Telugu", "x-iscii-te") {}
426 public class CP57006
: ISCIIEncoding
428 // Note: Unicode has a "Sinhala" page, but no "Assamese" page.
429 // Until I hear otherwise, I will assume that they are the same
430 // thing with different names - Rhys Weatherley, 16 April 2002.
431 public CP57006() : base(57006, 0x0D80, "ISCII Assamese", "x-iscii-as") {}
436 public class CP57007
: ISCIIEncoding
438 public CP57007() : base(57007, 0x0B00, "ISCII Oriya", "x-iscii-or") {}
443 public class CP57008
: ISCIIEncoding
445 public CP57008() : base(57008, 0x0C80, "ISCII Kannada", "x-iscii-ka") {}
450 public class CP57009
: ISCIIEncoding
452 public CP57009() : base(57009, 0x0D00, "ISCII Malayalam", "x-iscii-ma") {}
457 public class CP57010
: ISCIIEncoding
459 public CP57010() : base(57010, 0x0A80, "ISCII Gujarati", "x-iscii-gu") {}
464 public class CP57011
: ISCIIEncoding
466 // Note: Unicode has a "Gurmukhi" page, but no "Punjabi" page.
467 // Other ISCII-related information on the Internet seems to
468 // indicate that they are the same. Until I hear otherwise,
469 // I will assume that they are the same thing with different
470 // names - Rhys Weatherley, 16 April 2002.
471 public CP57011() : base(57011, 0x0A00, "ISCII Punjabi", "x-iscii-pa") {}
475 // Define the web encoding name aliases for the above code pages.
478 public class ENCx_iscii_de
: CP57002
480 public ENCx_iscii_de() : base() {}
482 }; // class ENCx_iscii_de
485 public class ENCx_iscii_be
: CP57003
487 public ENCx_iscii_be() : base() {}
489 }; // class ENCx_iscii_be
492 public class ENCx_iscii_ta
: CP57004
494 public ENCx_iscii_ta() : base() {}
496 }; // class ENCx_iscii_ta
499 public class ENCx_iscii_te
: CP57005
501 public ENCx_iscii_te() : base() {}
503 }; // class ENCx_iscii_te
506 public class ENCx_iscii_as
: CP57006
508 public ENCx_iscii_as() : base() {}
510 }; // class ENCx_iscii_as
513 public class ENCx_iscii_or
: CP57007
515 public ENCx_iscii_or() : base() {}
517 }; // class ENCx_iscii_or
520 public class ENCx_iscii_ka
: CP57008
522 public ENCx_iscii_ka() : base() {}
524 }; // class ENCx_iscii_ka
527 public class ENCx_iscii_ma
: CP57009
529 public ENCx_iscii_ma() : base() {}
531 }; // class ENCx_iscii_ma
534 public class ENCx_iscii_gu
: CP57010
536 public ENCx_iscii_gu() : base() {}
538 }; // class ENCx_iscii_gu
541 public class ENCx_iscii_pa
: CP57011
543 public ENCx_iscii_pa() : base() {}
545 }; // class ENCx_iscii_pa
547 }; // namespace I18N.Other