Welcome to mirror list, hosted at ThFree Co, Russian Federation.

ASCIIEncoding.cs « System.Text « corlib « class « mcs - github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 82dc49002eeba6b8c5d95b7998c7425593228ce8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
//
// System.Text.ASCIIEncoding.cs
//
// Author:
//   Sean MacIsaac (macisaac@ximian.com)
//   Dietmar Maurer (dietmar@ximian.com)
//
// (C) Ximian, Inc.  http://www.ximian.com
//


namespace System.Text {
        
	[Serializable]
	public class ASCIIEncoding : Encoding
	{
		public ASCIIEncoding () : base ()
		{
			encoding_name = "US-ASCII";
			body_name = "us-ascii";
			header_name = "us-ascii";
			web_name = "us-ascii";
			is_browser_display = false;
			is_browser_save = false;
			is_mail_news_display = true;
			is_mail_news_save = true;
		}

		public override int GetByteCount (string chars)
		{
			if (chars == null) 
				throw new ArgumentNullException ();

			return chars.Length;
		}

		public override int GetByteCount (char[] chars)
		{
			if (chars == null) 
				throw new ArgumentNullException ();

			return chars.Length;
		}

		public override int GetByteCount (char[] chars, int index, int count)
		{
			if (chars == null) 
				throw new ArgumentNullException ();

			if ((index < 0) || (count <= 0) || ((index + count) > chars.Length))
				throw new ArgumentOutOfRangeException ();

			return count;
		}

		public override int GetBytes (char[] chars, int charIndex, int charCount,
					      byte[] bytes, int byteIndex)
		{
			if ((bytes == null) || (chars == null))
				throw new ArgumentNullException ();

			if ((byteIndex < 0) || (charIndex < 0) || (charCount < 0) ||
			    ((charIndex + charCount) > chars.Length) ||
			    (byteIndex >= bytes.Length))
				throw new ArgumentOutOfRangeException ();

			if ((bytes.Length - byteIndex) < charCount)
				throw new ArgumentException ();

			for (int i = 0; i < charCount; i++)
				if (chars[charIndex+i] > 0x7f)
					bytes[byteIndex+i] = (byte) '?';
				else
					bytes[byteIndex+i] = (byte) chars[charIndex+i];

			return charCount;
		}

		public override int GetBytes (string chars, int charIndex, int charCount,
					      byte[] bytes, int byteIndex)
		{
			return GetBytes (chars.ToCharArray (), charIndex, charCount,
					 bytes, byteIndex);
		}

		public override int GetCharCount (byte[] bytes)
		{
			if (bytes == null) 
				throw new ArgumentNullException ();

			return bytes.Length;
		}

		public override int GetCharCount (byte[] bytes, int index, int count)
		{
			if (bytes == null) 
				throw new ArgumentNullException ();

			if ((index < 0) || (count <= 0) || ((index + count) > bytes.Length))
				throw new ArgumentOutOfRangeException ();

			return count;
		}

		public override int GetChars (byte[] bytes, int byteIndex, int byteCount,
					      char[] chars, int charIndex)
		{
			if ((bytes == null) || (chars == null))
				throw new ArgumentNullException ();

			if ((byteIndex < 0) || (charIndex < 0) || (byteCount < 0) ||
			    ((byteIndex + byteCount) > bytes.Length) ||
			    (charIndex + byteCount > chars.Length))
				throw new ArgumentOutOfRangeException ();

			if ((chars.Length - charIndex) < byteCount)
				throw new ArgumentException ();

			for (int i = 0; i < byteCount; i++)
				if (bytes[byteIndex+i] > 0x7f)
					chars[charIndex+i] = '?';
				else
					chars[charIndex+i] = (char) bytes[byteIndex+i];

			return byteCount;
		}

		public override int GetMaxByteCount (int charCount)
		{
			if (charCount < 0) 
				throw new ArgumentOutOfRangeException ();

			return charCount;
		}

		public override int GetMaxCharCount (int byteCount)
		{
			if (byteCount < 0) 
				throw new ArgumentOutOfRangeException ();

			return byteCount;
		}

		public override string GetString (byte[] bytes)
		{
			if (bytes == null) 
				throw new ArgumentNullException ();

			return new String (GetChars (bytes, 0, bytes.Length));
		}

		public override string GetString (byte[] bytes, int byteIndex, int byteCount)
		{
			if (bytes == null) 
				throw new ArgumentNullException ();

			if ((byteIndex < 0) || (byteCount < 0) || 
			    ((byteIndex + byteCount) > bytes.Length))
				throw new ArgumentOutOfRangeException ();

			return new String (GetChars (bytes, byteIndex, byteCount));
		}

	}
}