| OLD | NEW |
| 1 /* | 1 /* |
| 2 ****************************************************************************** | 2 ****************************************************************************** |
| 3 * | 3 * |
| 4 * Copyright (C) 2000-2008, International Business Machines | 4 * Copyright (C) 2000-2008, International Business Machines |
| 5 * Corporation and others. All Rights Reserved. | 5 * Corporation and others. All Rights Reserved. |
| 6 * | 6 * |
| 7 ****************************************************************************** | 7 ****************************************************************************** |
| 8 * file name: ucnvmbcs.c | 8 * file name: ucnvmbcs.c |
| 9 * encoding: US-ASCII | 9 * encoding: US-ASCII |
| 10 * tab size: 8 (not used) | 10 * tab size: 8 (not used) |
| (...skipping 467 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 478 if(mbcsTable->unicodeMask&UCNV_HAS_SUPPLEMENTARY) { | 478 if(mbcsTable->unicodeMask&UCNV_HAS_SUPPLEMENTARY) { |
| 479 maxStage1=0x440; | 479 maxStage1=0x440; |
| 480 } else { | 480 } else { |
| 481 maxStage1=0x40; | 481 maxStage1=0x40; |
| 482 } | 482 } |
| 483 | 483 |
| 484 c=0; /* keep track of the current code point while enumerating */ | 484 c=0; /* keep track of the current code point while enumerating */ |
| 485 | 485 |
| 486 if(mbcsTable->outputType==MBCS_OUTPUT_1) { | 486 if(mbcsTable->outputType==MBCS_OUTPUT_1) { |
| 487 const uint16_t *stage2, *stage3, *results; | 487 const uint16_t *stage2, *stage3, *results; |
| 488 uint16_t minValue; |
| 488 | 489 |
| 489 results=(const uint16_t *)mbcsTable->fromUnicodeBytes; | 490 results=(const uint16_t *)mbcsTable->fromUnicodeBytes; |
| 490 | 491 |
| 492 /* |
| 493 * Set a threshold variable for selecting which mappings to use. |
| 494 * See ucnv_MBCSSingleFromBMPWithOffsets() and |
| 495 * MBCS_SINGLE_RESULT_FROM_U() for details. |
| 496 */ |
| 497 if(which==UCNV_ROUNDTRIP_SET) { |
| 498 /* use only roundtrips */ |
| 499 minValue=0xf00; |
| 500 } else /* UCNV_ROUNDTRIP_AND_FALLBACK_SET */ { |
| 501 /* use all roundtrip and fallback results */ |
| 502 minValue=0x800; |
| 503 } |
| 504 |
| 491 for(st1=0; st1<maxStage1; ++st1) { | 505 for(st1=0; st1<maxStage1; ++st1) { |
| 492 st2=table[st1]; | 506 st2=table[st1]; |
| 493 if(st2>maxStage1) { | 507 if(st2>maxStage1) { |
| 494 stage2=table+st2; | 508 stage2=table+st2; |
| 495 for(st2=0; st2<64; ++st2) { | 509 for(st2=0; st2<64; ++st2) { |
| 496 if((st3=stage2[st2])!=0) { | 510 if((st3=stage2[st2])!=0) { |
| 497 /* read the stage 3 block */ | 511 /* read the stage 3 block */ |
| 498 stage3=results+st3; | 512 stage3=results+st3; |
| 499 | 513 |
| 500 /* | |
| 501 * Add code points for which the roundtrip flag is set. | |
| 502 * Once we get a set for fallback mappings, we have to u
se | |
| 503 * a threshold variable with a value of 0x800. | |
| 504 * See ucnv_MBCSSingleFromBMPWithOffsets() and | |
| 505 * MBCS_SINGLE_RESULT_FROM_U() for details. | |
| 506 */ | |
| 507 do { | 514 do { |
| 508 if(*stage3++>=0xf00) { | 515 if(*stage3++>=minValue) { |
| 509 sa->add(sa->set, c); | 516 sa->add(sa->set, c); |
| 510 } | 517 } |
| 511 } while((++c&0xf)!=0); | 518 } while((++c&0xf)!=0); |
| 512 } else { | 519 } else { |
| 513 c+=16; /* empty stage 3 block */ | 520 c+=16; /* empty stage 3 block */ |
| 514 } | 521 } |
| 515 } | 522 } |
| 516 } else { | 523 } else { |
| 517 c+=1024; /* empty stage 2 block */ | 524 c+=1024; /* empty stage 2 block */ |
| 518 } | 525 } |
| 519 } | 526 } |
| 520 } else { | 527 } else { |
| 521 const uint32_t *stage2; | 528 const uint32_t *stage2; |
| 522 const uint8_t *stage3, *bytes; | 529 const uint8_t *stage3, *bytes; |
| 523 uint32_t st3Multiplier; | 530 uint32_t st3Multiplier; |
| 524 uint32_t value; | 531 uint32_t value; |
| 532 UBool useFallback; |
| 525 | 533 |
| 526 bytes=mbcsTable->fromUnicodeBytes; | 534 bytes=mbcsTable->fromUnicodeBytes; |
| 527 | 535 |
| 536 useFallback=(UBool)(which==UCNV_ROUNDTRIP_AND_FALLBACK_SET); |
| 537 |
| 528 switch(mbcsTable->outputType) { | 538 switch(mbcsTable->outputType) { |
| 529 case MBCS_OUTPUT_3: | 539 case MBCS_OUTPUT_3: |
| 530 case MBCS_OUTPUT_4_EUC: | 540 case MBCS_OUTPUT_4_EUC: |
| 531 st3Multiplier=3; | 541 st3Multiplier=3; |
| 532 break; | 542 break; |
| 533 case MBCS_OUTPUT_4: | 543 case MBCS_OUTPUT_4: |
| 534 st3Multiplier=4; | 544 st3Multiplier=4; |
| 535 break; | 545 break; |
| 536 default: | 546 default: |
| 537 st3Multiplier=2; | 547 st3Multiplier=2; |
| 538 break; | 548 break; |
| 539 } | 549 } |
| 540 | 550 |
| 541 for(st1=0; st1<maxStage1; ++st1) { | 551 for(st1=0; st1<maxStage1; ++st1) { |
| 542 st2=table[st1]; | 552 st2=table[st1]; |
| 543 if(st2>(maxStage1>>1)) { | 553 if(st2>(maxStage1>>1)) { |
| 544 stage2=(const uint32_t *)table+st2; | 554 stage2=(const uint32_t *)table+st2; |
| 545 for(st2=0; st2<64; ++st2) { | 555 for(st2=0; st2<64; ++st2) { |
| 546 if((st3=stage2[st2])!=0) { | 556 if((st3=stage2[st2])!=0) { |
| 547 /* read the stage 3 block */ | 557 /* read the stage 3 block */ |
| 548 stage3=bytes+st3Multiplier*16*(uint32_t)(uint16_t)st3; | 558 stage3=bytes+st3Multiplier*16*(uint32_t)(uint16_t)st3; |
| 549 | 559 |
| 550 /* get the roundtrip flags for the stage 3 block */ | 560 /* get the roundtrip flags for the stage 3 block */ |
| 551 st3>>=16; | 561 st3>>=16; |
| 552 | 562 |
| 553 /* | 563 /* |
| 554 * Add code points for which the roundtrip flag is set. | 564 * Add code points for which the roundtrip flag is set, |
| 555 * Once we get a set for fallback mappings, we have to c
heck | 565 * or which map to non-zero bytes if we use fallbacks. |
| 556 * non-roundtrip stage 3 results for whether they are 0. | |
| 557 * See ucnv_MBCSFromUnicodeWithOffsets() for details. | 566 * See ucnv_MBCSFromUnicodeWithOffsets() for details. |
| 558 */ | 567 */ |
| 559 switch(filter) { | 568 switch(filter) { |
| 560 case UCNV_SET_FILTER_NONE: | 569 case UCNV_SET_FILTER_NONE: |
| 561 do { | 570 do { |
| 562 if(st3&1) { | 571 if(st3&1) { |
| 563 sa->add(sa->set, c); | 572 sa->add(sa->set, c); |
| 573 stage3+=st3Multiplier; |
| 574 } else if(useFallback) { |
| 575 uint8_t b=0; |
| 576 switch(st3Multiplier) { |
| 577 case 4: |
| 578 b|=*stage3++; |
| 579 case 3: |
| 580 b|=*stage3++; |
| 581 case 2: |
| 582 b|=stage3[0]|stage3[1]; |
| 583 stage3+=2; |
| 584 default: |
| 585 break; |
| 586 } |
| 587 if(b!=0) { |
| 588 sa->add(sa->set, c); |
| 589 } |
| 564 } | 590 } |
| 565 st3>>=1; | 591 st3>>=1; |
| 566 } while((++c&0xf)!=0); | 592 } while((++c&0xf)!=0); |
| 567 break; | 593 break; |
| 568 case UCNV_SET_FILTER_DBCS_ONLY: | 594 case UCNV_SET_FILTER_DBCS_ONLY: |
| 569 /* Ignore single-byte results (<0x100). */ | 595 /* Ignore single-byte results (<0x100). */ |
| 570 do { | 596 do { |
| 571 if((st3&1)!=0 && *((const uint16_t *)stage3)>=0x
100) { | 597 if(((st3&1)!=0 || useFallback) && *((const uint1
6_t *)stage3)>=0x100) { |
| 572 sa->add(sa->set, c); | 598 sa->add(sa->set, c); |
| 573 } | 599 } |
| 574 st3>>=1; | 600 st3>>=1; |
| 575 stage3+=2; /* +=st3Multiplier */ | 601 stage3+=2; /* +=st3Multiplier */ |
| 576 } while((++c&0xf)!=0); | 602 } while((++c&0xf)!=0); |
| 577 break; | 603 break; |
| 578 case UCNV_SET_FILTER_2022_CN: | 604 case UCNV_SET_FILTER_2022_CN: |
| 579 /* Only add code points that map to CNS 11643 plane
s 1 & 2 for non-EXT ISO-2022-CN. */ | 605 /* Only add code points that map to CNS 11643 plane
s 1 & 2 for non-EXT ISO-2022-CN. */ |
| 580 do { | 606 do { |
| 581 if((st3&1)!=0 && ((value=*stage3)==0x81 || value
==0x82)) { | 607 if(((st3&1)!=0 || useFallback) && ((value=*stage
3)==0x81 || value==0x82)) { |
| 582 sa->add(sa->set, c); | 608 sa->add(sa->set, c); |
| 583 } | 609 } |
| 584 st3>>=1; | 610 st3>>=1; |
| 585 stage3+=3; /* +=st3Multiplier */ | 611 stage3+=3; /* +=st3Multiplier */ |
| 586 } while((++c&0xf)!=0); | 612 } while((++c&0xf)!=0); |
| 587 break; | 613 break; |
| 588 case UCNV_SET_FILTER_SJIS: | 614 case UCNV_SET_FILTER_SJIS: |
| 589 /* Only add code points that map to Shift-JIS codes
corresponding to JIS X 0208. */ | 615 /* Only add code points that map to Shift-JIS codes
corresponding to JIS X 0208. */ |
| 590 do { | 616 do { |
| 591 if((st3&1)!=0 && (value=*((const uint16_t *)stag
e3))>=0x8140 && value<=0xeffc) { | 617 if(((st3&1)!=0 || useFallback) && (value=*((cons
t uint16_t *)stage3))>=0x8140 && value<=0xeffc) { |
| 618 sa->add(sa->set, c); |
| 619 } |
| 620 st3>>=1; |
| 621 stage3+=2; /* +=st3Multiplier */ |
| 622 } while((++c&0xf)!=0); |
| 623 break; |
| 624 case UCNV_SET_FILTER_GR94DBCS: |
| 625 /* Only add code points that map to ISO 2022 GR 94 D
BCS codes (each byte A1..FE). */ |
| 626 do { |
| 627 if( ((st3&1)!=0 || useFallback) && |
| 628 (uint16_t)((value=*((const uint16_t *)stage3
)) - 0xa1a1)<=(0xfefe - 0xa1a1) && |
| 629 (uint8_t)(value-0xa1)<=(0xfe - 0xa1) |
| 630 ) { |
| 631 sa->add(sa->set, c); |
| 632 } |
| 633 st3>>=1; |
| 634 stage3+=2; /* +=st3Multiplier */ |
| 635 } while((++c&0xf)!=0); |
| 636 break; |
| 637 case UCNV_SET_FILTER_HZ: |
| 638 /* Only add code points that are suitable for HZ DBC
S (lead byte A1..FD). */ |
| 639 do { |
| 640 if( ((st3&1)!=0 || useFallback) && |
| 641 (uint16_t)((value=*((const uint16_t *)stage3
))-0xa1a1)<=(0xfdfe - 0xa1a1) && |
| 642 (uint8_t)(value-0xa1)<=(0xfe - 0xa1) |
| 643 ) { |
| 592 sa->add(sa->set, c); | 644 sa->add(sa->set, c); |
| 593 } | 645 } |
| 594 st3>>=1; | 646 st3>>=1; |
| 595 stage3+=2; /* +=st3Multiplier */ | 647 stage3+=2; /* +=st3Multiplier */ |
| 596 } while((++c&0xf)!=0); | 648 } while((++c&0xf)!=0); |
| 597 break; | 649 break; |
| 598 default: | 650 default: |
| 599 *pErrorCode=U_INTERNAL_PROGRAM_ERROR; | 651 *pErrorCode=U_INTERNAL_PROGRAM_ERROR; |
| 600 return; | 652 return; |
| 601 } | 653 } |
| 602 } else { | 654 } else { |
| 603 c+=16; /* empty stage 3 block */ | 655 c+=16; /* empty stage 3 block */ |
| 604 } | 656 } |
| 605 } | 657 } |
| 606 } else { | 658 } else { |
| 607 c+=1024; /* empty stage 2 block */ | 659 c+=1024; /* empty stage 2 block */ |
| 608 } | 660 } |
| 609 } | 661 } |
| 610 } | 662 } |
| 611 | 663 |
| 612 ucnv_extGetUnicodeSet(sharedData, sa, which, pErrorCode); | 664 ucnv_extGetUnicodeSet(sharedData, sa, which, filter, pErrorCode); |
| 613 } | 665 } |
| 614 | 666 |
| 615 U_CFUNC void | 667 U_CFUNC void |
| 616 ucnv_MBCSGetUnicodeSetForUnicode(const UConverterSharedData *sharedData, | 668 ucnv_MBCSGetUnicodeSetForUnicode(const UConverterSharedData *sharedData, |
| 617 const USetAdder *sa, | 669 const USetAdder *sa, |
| 618 UConverterUnicodeSet which, | 670 UConverterUnicodeSet which, |
| 619 UErrorCode *pErrorCode) { | 671 UErrorCode *pErrorCode) { |
| 620 ucnv_MBCSGetFilteredUnicodeSetForUnicode( | 672 ucnv_MBCSGetFilteredUnicodeSetForUnicode( |
| 621 sharedData, sa, which, | 673 sharedData, sa, which, |
| 622 sharedData->mbcs.outputType==MBCS_OUTPUT_DBCS_ONLY ? | 674 sharedData->mbcs.outputType==MBCS_OUTPUT_DBCS_ONLY ? |
| (...skipping 1064 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1687 | 1739 |
| 1688 if(U_FAILURE(*pErrorCode)) { | 1740 if(U_FAILURE(*pErrorCode)) { |
| 1689 /* callback(illegal) */ | 1741 /* callback(illegal) */ |
| 1690 break; | 1742 break; |
| 1691 } else /* unassigned sequences indicated with byteIndex>0 */ { | 1743 } else /* unassigned sequences indicated with byteIndex>0 */ { |
| 1692 /* try an extension mapping */ | 1744 /* try an extension mapping */ |
| 1693 lastSource=source; | 1745 lastSource=source; |
| 1694 cnv->toUBytes[0]=*(source-1); | 1746 cnv->toUBytes[0]=*(source-1); |
| 1695 cnv->toULength=_extToU(cnv, cnv->sharedData, | 1747 cnv->toULength=_extToU(cnv, cnv->sharedData, |
| 1696 1, &source, sourceLimit, | 1748 1, &source, sourceLimit, |
| 1697 &target, target+targetCapacity, | 1749 &target, pArgs->targetLimit, |
| 1698 &offsets, sourceIndex, | 1750 &offsets, sourceIndex, |
| 1699 pArgs->flush, | 1751 pArgs->flush, |
| 1700 pErrorCode); | 1752 pErrorCode); |
| 1701 sourceIndex+=1+(int32_t)(source-lastSource); | 1753 sourceIndex+=1+(int32_t)(source-lastSource); |
| 1702 | 1754 |
| 1703 if(U_FAILURE(*pErrorCode)) { | 1755 if(U_FAILURE(*pErrorCode)) { |
| 1704 /* not mappable or buffer overflow */ | 1756 /* not mappable or buffer overflow */ |
| 1705 break; | 1757 break; |
| 1706 } | 1758 } |
| 1707 | 1759 |
| (...skipping 1631 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3339 *offsets++=sourceIndex++; | 3391 *offsets++=sourceIndex++; |
| 3340 --count; | 3392 --count; |
| 3341 } | 3393 } |
| 3342 /* offsets and sourceIndex are now set for the current character */ | 3394 /* offsets and sourceIndex are now set for the current character */ |
| 3343 } | 3395 } |
| 3344 | 3396 |
| 3345 /* try an extension mapping */ | 3397 /* try an extension mapping */ |
| 3346 lastSource=source; | 3398 lastSource=source; |
| 3347 c=_extFromU(cnv, cnv->sharedData, | 3399 c=_extFromU(cnv, cnv->sharedData, |
| 3348 c, &source, sourceLimit, | 3400 c, &source, sourceLimit, |
| 3349 &target, target+targetCapacity, | 3401 &target, (const uint8_t *)(pArgs->targetLimit), |
| 3350 &offsets, sourceIndex, | 3402 &offsets, sourceIndex, |
| 3351 pArgs->flush, | 3403 pArgs->flush, |
| 3352 pErrorCode); | 3404 pErrorCode); |
| 3353 sourceIndex+=length+(int32_t)(source-lastSource); | 3405 sourceIndex+=length+(int32_t)(source-lastSource); |
| 3354 lastSource=source; | 3406 lastSource=source; |
| 3355 | 3407 |
| 3356 if(U_FAILURE(*pErrorCode)) { | 3408 if(U_FAILURE(*pErrorCode)) { |
| 3357 /* not mappable or buffer overflow */ | 3409 /* not mappable or buffer overflow */ |
| 3358 break; | 3410 break; |
| 3359 } else { | 3411 } else { |
| (...skipping 1720 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5080 * converters. Be sure to update it as well. | 5132 * converters. Be sure to update it as well. |
| 5081 */ | 5133 */ |
| 5082 | 5134 |
| 5083 const UConverterSharedData _MBCSData={ | 5135 const UConverterSharedData _MBCSData={ |
| 5084 sizeof(UConverterSharedData), 1, | 5136 sizeof(UConverterSharedData), 1, |
| 5085 NULL, NULL, NULL, FALSE, &_MBCSImpl, | 5137 NULL, NULL, NULL, FALSE, &_MBCSImpl, |
| 5086 0 | 5138 0 |
| 5087 }; | 5139 }; |
| 5088 | 5140 |
| 5089 #endif /* #if !UCONFIG_NO_LEGACY_CONVERSION */ | 5141 #endif /* #if !UCONFIG_NO_LEGACY_CONVERSION */ |
| OLD | NEW |