2 // System.Text.ASCIIEncoding.cs
5 // Sean MacIsaac (macisaac@ximian.com)
6 // Dietmar Maurer (dietmar@ximian.com)
8 // (C) Ximian, Inc. http://www.ximian.com
12 namespace System.Text {
14 public class ASCIIEncoding : Encoding
16 public ASCIIEncoding () : base ()
18 encoding_name = "US-ASCII";
19 body_name = "us-ascii";
20 header_name = "us-ascii";
21 web_name = "us-ascii";
22 is_browser_display = false;
23 is_browser_save = false;
24 is_mail_news_display = true;
25 is_mail_news_save = true;
28 public override int GetByteCount (string chars)
31 throw new ArgumentNullException ();
36 public override int GetByteCount (char[] chars)
39 throw new ArgumentNullException ();
44 public override int GetByteCount (char[] chars, int index, int count)
47 throw new ArgumentNullException ();
49 if ((index < 0) || (count <= 0) || ((index + count) >= chars.Length))
50 throw new ArgumentOutOfRangeException ();
55 public override int GetBytes (char[] chars, int charIndex, int charCount,
56 byte[] bytes, int byteIndex)
58 if ((bytes == null) || (chars == null))
59 throw new ArgumentNullException ();
61 if ((byteIndex < 0) || (charIndex < 0) || (charCount < 0) ||
62 ((charIndex + charCount) > chars.Length) ||
63 (byteIndex >= bytes.Length))
64 throw new ArgumentOutOfRangeException ();
66 if ((bytes.Length - byteIndex) < charCount)
67 throw new ArgumentException ();
69 for (int i = 0; i < charCount; i++)
70 if (chars[charIndex+i] > 0x7f)
71 bytes[byteIndex+i] = (byte) '?';
73 bytes[byteIndex+i] = (byte) chars[charIndex+i];
78 public override int GetBytes (string chars, int charIndex, int charCount,
79 byte[] bytes, int byteIndex)
81 return GetBytes (chars.ToCharArray (), charIndex, charCount,
85 public override int GetCharCount (byte[] bytes)
88 throw new ArgumentNullException ();
93 public override int GetCharCount (byte[] bytes, int index, int count)
96 throw new ArgumentNullException ();
98 if ((index < 0) || (count <= 0) || ((index + count) >= bytes.Length))
99 throw new ArgumentOutOfRangeException ();
104 public override int GetChars (byte[] bytes, int byteIndex, int byteCount,
105 char[] chars, int charIndex)
107 if ((bytes == null) || (chars == null))
108 throw new ArgumentNullException ();
110 if ((byteIndex < 0) || (charIndex < 0) || (byteCount < 0) ||
111 ((byteIndex + byteCount) > bytes.Length) ||
112 (charIndex >= chars.Length))
113 throw new ArgumentOutOfRangeException ();
115 if ((chars.Length - charIndex) < byteCount)
116 throw new ArgumentException ();
118 for (int i = 0; i < byteCount; i++)
119 if (bytes[byteIndex+i] > 0x7f)
120 chars[charIndex+i] = '?';
122 chars[charIndex+i] = (char) bytes[byteIndex+i];
127 public override int GetMaxByteCount (int charCount)
130 throw new ArgumentOutOfRangeException ();
135 public override int GetMaxCharCount (int byteCount)
138 throw new ArgumentOutOfRangeException ();
143 public override string GetString (byte[] bytes)
146 throw new ArgumentNullException ();
148 return new String (GetChars (bytes, 0, bytes.Length));
151 public override string GetString (byte[] bytes, int byteIndex, int byteCount)
154 throw new ArgumentNullException ();
156 if ((byteIndex < 0) || (byteCount <= 0) ||
157 ((byteIndex + byteCount) >= bytes.Length))
158 throw new ArgumentOutOfRangeException ();
160 return new String (GetChars (bytes, byteIndex, byteCount));