| 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 |
namespace I18N.Other |
| 30 |
{ |
| 31 |
|
| 32 |
using System; |
| 33 |
using System.Text; |
| 34 |
using I18N.Common; |
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
[Serializable] |
| 43 |
public abstract class ISCIIEncoding : MonoEncoding |
| 44 |
{ |
| 45 |
|
| 46 |
int shift; |
| 47 |
string encodingName; |
| 48 |
string webName; |
| 49 |
|
| 50 |
|
| 51 |
protected ISCIIEncoding(int codePage, int shift, |
| 52 |
String encodingName, String webName) |
| 53 |
: base(codePage) |
| 54 |
{ |
| 55 |
this.shift = shift; |
| 56 |
this.encodingName = encodingName; |
| 57 |
this.webName = webName; |
| 58 |
} |
| 59 |
|
| 60 |
|
| 61 |
public override int GetByteCount(char[] chars, int index, int count) |
| 62 |
{ |
| 63 |
if(chars == null) |
| 64 |
{ |
| 65 |
throw new ArgumentNullException("chars"); |
| 66 |
} |
| 67 |
if(index < 0 || index > chars.Length) |
| 68 |
{ |
| 69 |
throw new ArgumentOutOfRangeException |
| 70 |
("index", Strings.GetString("ArgRange_Array")); |
| 71 |
} |
| 72 |
if(count < 0 || count > (chars.Length - index)) |
| 73 |
{ |
| 74 |
throw new ArgumentOutOfRangeException |
| 75 |
("count", Strings.GetString("ArgRange_Array")); |
| 76 |
} |
| 77 |
return count; |
| 78 |
} |
| 79 |
|
| 80 |
|
| 81 |
public override int GetByteCount(String s) |
| 82 |
{ |
| 83 |
if(s == null) |
| 84 |
{ |
| 85 |
throw new ArgumentNullException("s"); |
| 86 |
} |
| 87 |
return s.Length; |
| 88 |
} |
| 89 |
|
| 90 |
public unsafe override int GetByteCountImpl (char* chars, int count) |
| 91 |
{ |
| 92 |
int index = 0; |
| 93 |
int length = 0; |
| 94 |
char ch; |
| 95 |
char first = (char)shift; |
| 96 |
char last = (char)(shift + 0x7F); |
| 97 |
|
| 98 |
while(count-- > 0) |
| 99 |
{ |
| 100 |
ch = chars[index++]; |
| 101 |
if(ch < (char)0x0080) |
| 102 |
{ |
| 103 |
|
| 104 |
length++; |
| 105 |
} |
| 106 |
else if(ch >= first && ch <= last) |
| 107 |
{ |
| 108 |
|
| 109 |
length++; |
| 110 |
} |
| 111 |
else if(ch >= '\uFF01' && ch <= '\uFF5E') |
| 112 |
{ |
| 113 |
|
| 114 |
length++; |
| 115 |
} |
| 116 |
else |
| 117 |
{ |
| 118 |
|
| 119 |
length++; |
| 120 |
} |
| 121 |
count--; |
| 122 |
} |
| 123 |
|
| 124 |
|
| 125 |
return length; |
| 126 |
} |
| 127 |
|
| 128 |
public unsafe override int GetBytesImpl (char* chars, int charCount, byte* bytes, int byteCount) |
| 129 |
{ |
| 130 |
EncoderFallbackBuffer buffer = null; |
| 131 |
|
| 132 |
int byteIndex = 0; |
| 133 |
int end = charCount; |
| 134 |
|
| 135 |
if(chars == null) |
| 136 |
{ |
| 137 |
throw new ArgumentNullException("chars"); |
| 138 |
} |
| 139 |
if(bytes == null) |
| 140 |
{ |
| 141 |
throw new ArgumentNullException("bytes"); |
| 142 |
} |
| 143 |
|
| 144 |
|
| 145 |
char ch; |
| 146 |
int posn = byteIndex; |
| 147 |
char first = (char)shift; |
| 148 |
char last = (char)(shift + 0x7F); |
| 149 |
|
| 150 |
for (int i = 0; i < end; i++, charCount--) |
| 151 |
{ |
| 152 |
ch = chars[i]; |
| 153 |
if(ch < (char)0x0080) |
| 154 |
{ |
| 155 |
|
| 156 |
bytes[posn++] = (byte)ch; |
| 157 |
} |
| 158 |
else if(ch >= first && ch <= last) |
| 159 |
{ |
| 160 |
|
| 161 |
bytes[posn++] = (byte)(ch - first + 0x80); |
| 162 |
} |
| 163 |
else if(ch >= '\uFF01' && ch <= '\uFF5E') |
| 164 |
{ |
| 165 |
|
| 166 |
bytes[posn++] = (byte)(ch - 0xFEE0); |
| 167 |
} |
| 168 |
else |
| 169 |
{ |
| 170 |
HandleFallback (ref buffer, chars, ref i, ref charCount, bytes, ref posn, ref byteCount); |
| 171 |
continue; |
| 172 |
} |
| 173 |
byteCount--; |
| 174 |
} |
| 175 |
|
| 176 |
|
| 177 |
return posn - byteIndex; |
| 178 |
} |
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
|
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
|
| 253 |
public override int GetCharCount(byte[] bytes, int index, int count) |
| 254 |
{ |
| 255 |
if(bytes == null) |
| 256 |
{ |
| 257 |
throw new ArgumentNullException("bytes"); |
| 258 |
} |
| 259 |
if(index < 0 || index > bytes.Length) |
| 260 |
{ |
| 261 |
throw new ArgumentOutOfRangeException |
| 262 |
("index", Strings.GetString("ArgRange_Array")); |
| 263 |
} |
| 264 |
if(count < 0 || count > (bytes.Length - index)) |
| 265 |
{ |
| 266 |
throw new ArgumentOutOfRangeException |
| 267 |
("count", Strings.GetString("ArgRange_Array")); |
| 268 |
} |
| 269 |
return count; |
| 270 |
} |
| 271 |
|
| 272 |
|
| 273 |
public override int GetChars(byte[] bytes, int byteIndex, int byteCount, |
| 274 |
char[] chars, int charIndex) |
| 275 |
{ |
| 276 |
|
| 277 |
if(bytes == null) |
| 278 |
{ |
| 279 |
throw new ArgumentNullException("bytes"); |
| 280 |
} |
| 281 |
if(chars == null) |
| 282 |
{ |
| 283 |
throw new ArgumentNullException("chars"); |
| 284 |
} |
| 285 |
if(byteIndex < 0 || byteIndex > bytes.Length) |
| 286 |
{ |
| 287 |
throw new ArgumentOutOfRangeException |
| 288 |
("byteIndex", Strings.GetString("ArgRange_Array")); |
| 289 |
} |
| 290 |
if(byteCount < 0 || byteCount > (bytes.Length - byteIndex)) |
| 291 |
{ |
| 292 |
throw new ArgumentOutOfRangeException |
| 293 |
("byteCount", Strings.GetString("ArgRange_Array")); |
| 294 |
} |
| 295 |
if(charIndex < 0 || charIndex > chars.Length) |
| 296 |
{ |
| 297 |
throw new ArgumentOutOfRangeException |
| 298 |
("charIndex", Strings.GetString("ArgRange_Array")); |
| 299 |
} |
| 300 |
if((chars.Length - charIndex) < byteCount) |
| 301 |
{ |
| 302 |
throw new ArgumentException |
| 303 |
(Strings.GetString("Arg_InsufficientSpace"), "chars"); |
| 304 |
} |
| 305 |
|
| 306 |
|
| 307 |
int count = byteCount; |
| 308 |
int byteval; |
| 309 |
int shift = this.shift - 0x80; |
| 310 |
while(count-- > 0) |
| 311 |
{ |
| 312 |
byteval = (int)(bytes[byteIndex++]); |
| 313 |
if(byteval < 0x80) |
| 314 |
{ |
| 315 |
|
| 316 |
chars[charIndex++] = (char)byteval; |
| 317 |
} |
| 318 |
else |
| 319 |
{ |
| 320 |
|
| 321 |
chars[charIndex++] = (char)(byteval + shift); |
| 322 |
} |
| 323 |
} |
| 324 |
return byteCount; |
| 325 |
} |
| 326 |
|
| 327 |
|
| 328 |
|
| 329 |
public override int GetMaxByteCount(int charCount) |
| 330 |
{ |
| 331 |
if(charCount < 0) |
| 332 |
{ |
| 333 |
throw new ArgumentOutOfRangeException |
| 334 |
("charCount", |
| 335 |
Strings.GetString("ArgRange_NonNegative")); |
| 336 |
} |
| 337 |
return charCount; |
| 338 |
} |
| 339 |
|
| 340 |
|
| 341 |
|
| 342 |
public override int GetMaxCharCount(int byteCount) |
| 343 |
{ |
| 344 |
if(byteCount < 0) |
| 345 |
{ |
| 346 |
throw new ArgumentOutOfRangeException |
| 347 |
("byteCount", |
| 348 |
Strings.GetString("ArgRange_NonNegative")); |
| 349 |
} |
| 350 |
return byteCount; |
| 351 |
} |
| 352 |
|
| 353 |
#if !ECMA_COMPAT |
| 354 |
|
| 355 |
|
| 356 |
public override String BodyName |
| 357 |
{ |
| 358 |
get |
| 359 |
{ |
| 360 |
return webName; |
| 361 |
} |
| 362 |
} |
| 363 |
|
| 364 |
|
| 365 |
public override String EncodingName |
| 366 |
{ |
| 367 |
get |
| 368 |
{ |
| 369 |
return encodingName; |
| 370 |
} |
| 371 |
} |
| 372 |
|
| 373 |
|
| 374 |
public override String HeaderName |
| 375 |
{ |
| 376 |
get |
| 377 |
{ |
| 378 |
return webName; |
| 379 |
} |
| 380 |
} |
| 381 |
|
| 382 |
|
| 383 |
public override String WebName |
| 384 |
{ |
| 385 |
get |
| 386 |
{ |
| 387 |
return webName; |
| 388 |
} |
| 389 |
} |
| 390 |
|
| 391 |
#endif |
| 392 |
|
| 393 |
}; |
| 394 |
|
| 395 |
|
| 396 |
|
| 397 |
[Serializable] |
| 398 |
public class CP57002 : ISCIIEncoding |
| 399 |
{ |
| 400 |
public CP57002() : base(57002, 0x0900, "ISCII Devanagari", "x-iscii-de") {} |
| 401 |
|
| 402 |
}; |
| 403 |
|
| 404 |
[Serializable] |
| 405 |
public class CP57003 : ISCIIEncoding |
| 406 |
{ |
| 407 |
public CP57003() : base(57003, 0x0980, "ISCII Bengali", "x-iscii-be") {} |
| 408 |
|
| 409 |
}; |
| 410 |
|
| 411 |
[Serializable] |
| 412 |
public class CP57004 : ISCIIEncoding |
| 413 |
{ |
| 414 |
public CP57004() : base(57004, 0x0B80, "ISCII Tamil", "x-iscii-ta") {} |
| 415 |
|
| 416 |
}; |
| 417 |
|
| 418 |
[Serializable] |
| 419 |
public class CP57005 : ISCIIEncoding |
| 420 |
{ |
| 421 |
public CP57005() : base(57005, 0x0B80, "ISCII Telugu", "x-iscii-te") {} |
| 422 |
|
| 423 |
}; |
| 424 |
|
| 425 |
[Serializable] |
| 426 |
public class CP57006 : ISCIIEncoding |
| 427 |
{ |
| 428 |
|
| 429 |
|
| 430 |
|
| 431 |
public CP57006() : base(57006, 0x0D80, "ISCII Assamese", "x-iscii-as") {} |
| 432 |
|
| 433 |
}; |
| 434 |
|
| 435 |
[Serializable] |
| 436 |
public class CP57007 : ISCIIEncoding |
| 437 |
{ |
| 438 |
public CP57007() : base(57007, 0x0B00, "ISCII Oriya", "x-iscii-or") {} |
| 439 |
|
| 440 |
}; |
| 441 |
|
| 442 |
[Serializable] |
| 443 |
public class CP57008 : ISCIIEncoding |
| 444 |
{ |
| 445 |
public CP57008() : base(57008, 0x0C80, "ISCII Kannada", "x-iscii-ka") {} |
| 446 |
|
| 447 |
}; |
| 448 |
|
| 449 |
[Serializable] |
| 450 |
public class CP57009 : ISCIIEncoding |
| 451 |
{ |
| 452 |
public CP57009() : base(57009, 0x0D00, "ISCII Malayalam", "x-iscii-ma") {} |
| 453 |
|
| 454 |
}; |
| 455 |
|
| 456 |
[Serializable] |
| 457 |
public class CP57010 : ISCIIEncoding |
| 458 |
{ |
| 459 |
public CP57010() : base(57010, 0x0A80, "ISCII Gujarati", "x-iscii-gu") {} |
| 460 |
|
| 461 |
}; |
| 462 |
|
| 463 |
[Serializable] |
| 464 |
public class CP57011 : ISCIIEncoding |
| 465 |
{ |
| 466 |
|
| 467 |
|
| 468 |
|
| 469 |
|
| 470 |
|
| 471 |
public CP57011() : base(57011, 0x0A00, "ISCII Punjabi", "x-iscii-pa") {} |
| 472 |
|
| 473 |
}; |
| 474 |
|
| 475 |
|
| 476 |
|
| 477 |
[Serializable] |
| 478 |
public class ENCx_iscii_de : CP57002 |
| 479 |
{ |
| 480 |
public ENCx_iscii_de() : base() {} |
| 481 |
|
| 482 |
}; |
| 483 |
|
| 484 |
[Serializable] |
| 485 |
public class ENCx_iscii_be : CP57003 |
| 486 |
{ |
| 487 |
public ENCx_iscii_be() : base() {} |
| 488 |
|
| 489 |
}; |
| 490 |
|
| 491 |
[Serializable] |
| 492 |
public class ENCx_iscii_ta : CP57004 |
| 493 |
{ |
| 494 |
public ENCx_iscii_ta() : base() {} |
| 495 |
|
| 496 |
}; |
| 497 |
|
| 498 |
[Serializable] |
| 499 |
public class ENCx_iscii_te : CP57005 |
| 500 |
{ |
| 501 |
public ENCx_iscii_te() : base() {} |
| 502 |
|
| 503 |
}; |
| 504 |
|
| 505 |
[Serializable] |
| 506 |
public class ENCx_iscii_as : CP57006 |
| 507 |
{ |
| 508 |
public ENCx_iscii_as() : base() {} |
| 509 |
|
| 510 |
}; |
| 511 |
|
| 512 |
[Serializable] |
| 513 |
public class ENCx_iscii_or : CP57007 |
| 514 |
{ |
| 515 |
public ENCx_iscii_or() : base() {} |
| 516 |
|
| 517 |
}; |
| 518 |
|
| 519 |
[Serializable] |
| 520 |
public class ENCx_iscii_ka : CP57008 |
| 521 |
{ |
| 522 |
public ENCx_iscii_ka() : base() {} |
| 523 |
|
| 524 |
}; |
| 525 |
|
| 526 |
[Serializable] |
| 527 |
public class ENCx_iscii_ma : CP57009 |
| 528 |
{ |
| 529 |
public ENCx_iscii_ma() : base() {} |
| 530 |
|
| 531 |
}; |
| 532 |
|
| 533 |
[Serializable] |
| 534 |
public class ENCx_iscii_gu : CP57010 |
| 535 |
{ |
| 536 |
public ENCx_iscii_gu() : base() {} |
| 537 |
|
| 538 |
}; |
| 539 |
|
| 540 |
[Serializable] |
| 541 |
public class ENCx_iscii_pa : CP57011 |
| 542 |
{ |
| 543 |
public ENCx_iscii_pa() : base() {} |
| 544 |
|
| 545 |
}; |
| 546 |
|
| 547 |
}; |