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
|
//
// System.Text.Encoder.cs
//
// Authors:
// Dietmar Maurer (dietmar@ximian.com)
//
// (C) 2001 Ximian, Inc. http://www.ximian.com
//
namespace System.Text
{
[Serializable]
public abstract class Encoder
{
protected Encoder()
{
// fixme: dont know what do do here
}
public abstract int GetByteCount (char[] chars, int index, int count, bool flush);
public abstract int GetBytes (char[] chars, int charIndex, int charCount,
byte[] bytes, int byteIndex, bool flush);
}
internal class DefaultEncoder : Encoder {
public Encoding encoding;
public DefaultEncoder (Encoding enc)
{
encoding = enc;
}
public override int GetByteCount (char[] chars, int index, int count, bool flush)
{
return encoding.GetByteCount (chars, index, count);
}
public override int GetBytes (char[] chars, int charIndex, int charCount,
byte[] bytes, int byteIndex, bool flush)
{
return encoding.GetBytes (chars, charIndex, charCount, bytes, byteIndex);
}
}
internal class IConvEncoder : Encoder {
private IntPtr converter;
public IConvEncoder (string name, bool big_endian)
{
converter = Encoding.IConvNewEncoder (name, big_endian);
}
public override int GetByteCount (char[] chars, int index, int count, bool flush)
{
if (chars == null)
throw new ArgumentNullException ();
if (index + count > chars.Length)
throw new ArgumentOutOfRangeException ();
int res = Encoding.IConvGetByteCount (converter, chars, index, count);
if (flush)
Encoding.IConvReset (converter);
return res;
}
public override int GetBytes (char[] chars, int charIndex, int charCount,
byte[] bytes, int byteIndex, bool flush)
{
if ((chars == null) || (bytes == null))
throw new ArgumentNullException ();
if ((charIndex < 0) || (charCount < 0) || (byteIndex < 0))
throw new ArgumentOutOfRangeException ();
if (charIndex + charCount > chars.Length)
throw new ArgumentOutOfRangeException ();
if (byteIndex + charCount > bytes.Length)
throw new ArgumentOutOfRangeException ();
int res = Encoding.IConvGetBytes (converter, chars, charIndex, charCount,
bytes, byteIndex);
if (flush)
Encoding.IConvReset (converter);
return res;
}
}
}
|