| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
using System; |
| 9 |
using System.Text; |
| 10 |
using I18N.Common; |
| 11 |
|
| 12 |
#if DISABLE_UNSAFE |
| 13 |
using MonoEncoder = I18N.Common.MonoSafeEncoder; |
| 14 |
using MonoEncoding = I18N.Common.MonoSafeEncoding; |
| 15 |
#endif |
| 16 |
|
| 17 |
namespace I18N.CJK |
| 18 |
{ |
| 19 |
[Serializable] |
| 20 |
internal abstract class DbcsEncoding : MonoEncoding |
| 21 |
{ |
| 22 |
public DbcsEncoding (int codePage) : this (codePage, 0) |
| 23 |
{ |
| 24 |
} |
| 25 |
|
| 26 |
public DbcsEncoding (int codePage, int windowsCodePage) |
| 27 |
: base (codePage, windowsCodePage) |
| 28 |
{ |
| 29 |
} |
| 30 |
|
| 31 |
internal abstract DbcsConvert GetConvert (); |
| 32 |
|
| 33 |
|
| 34 |
public override int GetByteCount(char[] chars, int index, int count) |
| 35 |
{ |
| 36 |
if (chars == null) |
| 37 |
throw new ArgumentNullException("chars"); |
| 38 |
if (index < 0 || index > chars.Length) |
| 39 |
throw new ArgumentOutOfRangeException("index", Strings.GetString("ArgRange_Array")); |
| 40 |
if (count < 0 || index + count > chars.Length) |
| 41 |
throw new ArgumentOutOfRangeException("count", Strings.GetString("ArgRange_Array")); |
| 42 |
byte[] buffer = new byte[count * 2]; |
| 43 |
return GetBytes(chars, index, count, buffer, 0); |
| 44 |
} |
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
public override int GetCharCount(byte[] bytes, int index, int count) |
| 67 |
{ |
| 68 |
if (bytes == null) |
| 69 |
throw new ArgumentNullException("bytes"); |
| 70 |
if (index < 0 || index > bytes.Length) |
| 71 |
throw new ArgumentOutOfRangeException("index", Strings.GetString("ArgRange_Array")); |
| 72 |
if (count < 0 || index + count > bytes.Length) |
| 73 |
throw new ArgumentOutOfRangeException("count", Strings.GetString("ArgRange_Array")); |
| 74 |
char[] buffer = new char[count]; |
| 75 |
return GetChars(bytes, index, count, buffer, 0); |
| 76 |
} |
| 77 |
|
| 78 |
|
| 79 |
public override int GetChars(byte[] bytes, int byteIndex, int byteCount, |
| 80 |
char[] chars, int charIndex) |
| 81 |
{ |
| 82 |
if (bytes == null) |
| 83 |
throw new ArgumentNullException("bytes"); |
| 84 |
if (chars == null) |
| 85 |
throw new ArgumentNullException("chars"); |
| 86 |
if (byteIndex < 0 || byteIndex > bytes.Length) |
| 87 |
throw new ArgumentOutOfRangeException("byteIndex", Strings.GetString("ArgRange_Array")); |
| 88 |
if (byteCount < 0 || byteIndex + byteCount > bytes.Length) |
| 89 |
throw new ArgumentOutOfRangeException("byteCount", Strings.GetString("ArgRange_Array")); |
| 90 |
if (charIndex < 0 || charIndex > chars.Length) |
| 91 |
throw new ArgumentOutOfRangeException("charIndex", Strings.GetString("ArgRange_Array")); |
| 92 |
return 0; |
| 93 |
} |
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
public override int GetMaxByteCount(int charCount) |
| 98 |
{ |
| 99 |
if (charCount < 0) |
| 100 |
throw new ArgumentOutOfRangeException("charCount", Strings.GetString("ArgRange_NonNegative")); |
| 101 |
return charCount * 2; |
| 102 |
} |
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
public override int GetMaxCharCount(int byteCount) |
| 107 |
{ |
| 108 |
if (byteCount < 0) { |
| 109 |
throw new ArgumentOutOfRangeException("byteCount", Strings.GetString("ArgRange_NonNegative")); |
| 110 |
} |
| 111 |
return byteCount; |
| 112 |
} |
| 113 |
|
| 114 |
|
| 115 |
public override bool IsBrowserDisplay |
| 116 |
{ |
| 117 |
get { return true; } |
| 118 |
} |
| 119 |
|
| 120 |
|
| 121 |
public override bool IsBrowserSave |
| 122 |
{ |
| 123 |
get { return true; } |
| 124 |
} |
| 125 |
|
| 126 |
|
| 127 |
public override bool IsMailNewsDisplay |
| 128 |
{ |
| 129 |
get { return true; } |
| 130 |
} |
| 131 |
|
| 132 |
|
| 133 |
public override bool IsMailNewsSave |
| 134 |
{ |
| 135 |
get { return true; } |
| 136 |
} |
| 137 |
|
| 138 |
|
| 139 |
internal abstract class DbcsDecoder : Decoder |
| 140 |
{ |
| 141 |
protected DbcsConvert convert; |
| 142 |
|
| 143 |
|
| 144 |
public DbcsDecoder(DbcsConvert convert) |
| 145 |
{ |
| 146 |
this.convert = convert; |
| 147 |
} |
| 148 |
|
| 149 |
internal void CheckRange (byte[] bytes, int index, int count) |
| 150 |
{ |
| 151 |
if (bytes == null) |
| 152 |
throw new ArgumentNullException("bytes"); |
| 153 |
if (index < 0 || index > bytes.Length) |
| 154 |
throw new ArgumentOutOfRangeException("index", Strings.GetString("ArgRange_Array")); |
| 155 |
if (count < 0 || count > (bytes.Length - index)) |
| 156 |
throw new ArgumentOutOfRangeException("count", Strings.GetString("ArgRange_Array")); |
| 157 |
} |
| 158 |
|
| 159 |
internal void CheckRange (byte[] bytes, int byteIndex, int byteCount, |
| 160 |
char[] chars, int charIndex) |
| 161 |
{ |
| 162 |
if (bytes == null) |
| 163 |
throw new ArgumentNullException("bytes"); |
| 164 |
if (chars == null) |
| 165 |
throw new ArgumentNullException("chars"); |
| 166 |
if (byteIndex < 0 || byteIndex > bytes.Length) |
| 167 |
throw new ArgumentOutOfRangeException("byteIndex", Strings.GetString("ArgRange_Array")); |
| 168 |
if (byteCount < 0 || byteIndex + byteCount > bytes.Length) |
| 169 |
throw new ArgumentOutOfRangeException("byteCount", Strings.GetString("ArgRange_Array")); |
| 170 |
if (charIndex < 0 || charIndex > chars.Length) |
| 171 |
throw new ArgumentOutOfRangeException("charIndex", Strings.GetString("ArgRange_Array")); |
| 172 |
} |
| 173 |
} |
| 174 |
} |
| 175 |
} |