2002-01-14 Miguel de Icaza <miguel@ximian.com>
[mono.git] / mcs / class / corlib / System.Text / Decoder.cs
1 //
2 // System.Text.Decoder.cs
3 //
4 // Authors:
5 //   Dietmar Maurer (dietmar@ximian.com)
6 //
7 // (C) 2001 Ximian, Inc.  http://www.ximian.com
8 //
9
10 namespace System.Text
11 {
12
13         public abstract class Decoder
14         {
15                 
16                 protected Decoder ()
17                 {
18                         // fixme: dont know what do do here
19                 }
20
21                 public abstract int GetCharCount (byte[] bytes, int index, int count);
22
23                 public abstract int GetChars (byte[] bytes, int byteIndex, int byteCount,
24                                               char[] chars, int charIndex);
25         }
26
27         internal class DefaultDecoder : Decoder {
28
29                 public Encoding encoding;
30
31                 public DefaultDecoder (Encoding enc)
32                 {
33                         encoding = enc;
34                 }
35
36                 public override int GetCharCount (byte[] bytes, int index, int count)
37                 {
38                         return encoding.GetCharCount (bytes, index, count);
39                 }
40
41                 public override int GetChars (byte[] bytes, int byteIndex, int byteCount,
42                                               char[] chars, int charIndex)
43                 {
44                         return encoding.GetChars (bytes, byteIndex, byteCount, chars, charIndex);
45                 }
46
47         }
48         
49         internal class IConvDecoder : Decoder {
50                 
51                 private IntPtr converter;
52
53                 public IConvDecoder (string name, bool big_endian)
54                 {
55                         converter = Encoding.IConvNewDecoder (name, big_endian);
56                 }
57
58                 public override int GetCharCount (byte[] bytes, int index, int count)
59                 {
60                         return Encoding.IConvGetCharCount (converter, bytes, index, count);
61                 }
62
63                 public override int GetChars (byte[] bytes, int byteIndex, int byteCount,
64                                               char[] chars, int charIndex)
65                 {
66                         return Encoding.IConvGetChars (converter, bytes, byteIndex, byteCount,
67                                                        chars, charIndex);
68                 }
69         }       
70 }