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

Decoder.cs « System.Text « corlib « class « mcs - github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: b133c1240467edc65c9f316dae17579acbf192ad (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
//
// System.Text.Decoder.cs
//
// Authors:
//   Dietmar Maurer (dietmar@ximian.com)
//
// (C) 2001 Ximian, Inc.  http://www.ximian.com
//

namespace System.Text
{

	[Serializable]
	public abstract class Decoder
	{
		
		protected Decoder ()
		{
			// fixme: dont know what do do here
		}

		public abstract int GetCharCount (byte[] bytes, int index, int count);

		public abstract int GetChars (byte[] bytes, int byteIndex, int byteCount,
					      char[] chars, int charIndex);
	}

	internal class DefaultDecoder : Decoder {

		public Encoding encoding;

		public DefaultDecoder (Encoding enc)
		{
			encoding = enc;
		}

		public override int GetCharCount (byte[] bytes, int index, int count)
		{
			return encoding.GetCharCount (bytes, index, count);
		}

		public override int GetChars (byte[] bytes, int byteIndex, int byteCount,
					      char[] chars, int charIndex)
		{
			return encoding.GetChars (bytes, byteIndex, byteCount, chars, charIndex);
		}

	}
	
	internal class IConvDecoder : Decoder {
		
		private IntPtr converter;

		public IConvDecoder (string name, bool big_endian)
		{
			converter = Encoding.IConvNewDecoder (name, big_endian);
		}

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

			if (index + count > bytes.Length)
				throw new ArgumentOutOfRangeException ();

			return Encoding.IConvGetCharCount (converter, bytes, index, 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) || (byteCount < 0) || (charIndex < 0))
				throw new ArgumentOutOfRangeException ();

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

			if (charIndex > chars.Length)
				throw new ArgumentOutOfRangeException ();

			return Encoding.IConvGetChars (converter, bytes, byteIndex, byteCount,
						       chars, charIndex);
		}
	}	
}