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 {
15 public class ASCIIEncoding : Encoding
17 public ASCIIEncoding () : base ()
19 encoding_name = "US-ASCII";
20 body_name = "us-ascii";
21 header_name = "us-ascii";
22 web_name = "us-ascii";
23 is_browser_display = false;
24 is_browser_save = false;
25 is_mail_news_display = true;
26 is_mail_news_save = true;
29 public override int GetByteCount (string chars)
32 throw new ArgumentNullException ();
37 public override int GetByteCount (char[] chars)
40 throw new ArgumentNullException ();
45 public override int GetByteCount (char[] chars, int index, int count)
48 throw new ArgumentNullException ();
50 if ((index < 0) || (count <= 0) || ((index + count) > chars.Length))
51 throw new ArgumentOutOfRangeException ();
56 public override int GetBytes (char[] chars, int charIndex, int charCount,
57 byte[] bytes, int byteIndex)
59 if ((bytes == null) || (chars == null))
60 throw new ArgumentNullException ();
62 if ((byteIndex < 0) || (charIndex < 0) || (charCount < 0) ||
63 ((charIndex + charCount) > chars.Length) ||
64 (byteIndex >= bytes.Length))
65 throw new ArgumentOutOfRangeException ();
67 if ((bytes.Length - byteIndex) < charCount)
68 throw new ArgumentException ();
70 for (int i = 0; i < charCount; i++)
71 if (chars[charIndex+i] > 0x7f)
72 bytes[byteIndex+i] = (byte) '?';
74 bytes[byteIndex+i] = (byte) chars[charIndex+i];
79 public override int GetBytes (string chars, int charIndex, int charCount,
80 byte[] bytes, int byteIndex)
82 return GetBytes (chars.ToCharArray (), charIndex, charCount,
86 public override int GetCharCount (byte[] bytes)
89 throw new ArgumentNullException ();
94 public override int GetCharCount (byte[] bytes, int index, int count)
97 throw new ArgumentNullException ();
99 if ((index < 0) || (count <= 0) || ((index + count) > bytes.Length))
100 throw new ArgumentOutOfRangeException ();
105 public override int GetChars (byte[] bytes, int byteIndex, int byteCount,
106 char[] chars, int charIndex)
108 if ((bytes == null) || (chars == null))
109 throw new ArgumentNullException ();
111 if ((byteIndex < 0) || (charIndex < 0) || (byteCount < 0) ||
112 ((byteIndex + byteCount) > bytes.Length) ||
113 (charIndex + byteCount > chars.Length))
114 throw new ArgumentOutOfRangeException ();
116 if ((chars.Length - charIndex) < byteCount)
117 throw new ArgumentException ();
119 for (int i = 0; i < byteCount; i++)
120 if (bytes[byteIndex+i] > 0x7f)
121 chars[charIndex+i] = '?';
123 chars[charIndex+i] = (char) bytes[byteIndex+i];
128 public override int GetMaxByteCount (int charCount)
131 throw new ArgumentOutOfRangeException ();
136 public override int GetMaxCharCount (int byteCount)
139 throw new ArgumentOutOfRangeException ();
144 public override string GetString (byte[] bytes)
147 throw new ArgumentNullException ();
149 return new String (GetChars (bytes, 0, bytes.Length));
152 public override string GetString (byte[] bytes, int byteIndex, int byteCount)
155 throw new ArgumentNullException ();
157 if ((byteIndex < 0) || (byteCount < 0) ||
158 ((byteIndex + byteCount) > bytes.Length))
159 throw new ArgumentOutOfRangeException ();
161 return new String (GetChars (bytes, byteIndex, byteCount));