Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Unified Diff: third_party/icu38/source/common/ucnvmbcs.c

Issue 52030: Apply ICU patches for ICU tickets 6175 (ISO-2022 and ... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/icu38/source/common/ucnvmbcs.h ('k') | third_party/icu38/source/common/uset_imp.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/icu38/source/common/ucnvmbcs.c
===================================================================
--- third_party/icu38/source/common/ucnvmbcs.c (revision 10949)
+++ third_party/icu38/source/common/ucnvmbcs.c (working copy)
@@ -485,9 +485,23 @@
if(mbcsTable->outputType==MBCS_OUTPUT_1) {
const uint16_t *stage2, *stage3, *results;
+ uint16_t minValue;
results=(const uint16_t *)mbcsTable->fromUnicodeBytes;
+ /*
+ * Set a threshold variable for selecting which mappings to use.
+ * See ucnv_MBCSSingleFromBMPWithOffsets() and
+ * MBCS_SINGLE_RESULT_FROM_U() for details.
+ */
+ if(which==UCNV_ROUNDTRIP_SET) {
+ /* use only roundtrips */
+ minValue=0xf00;
+ } else /* UCNV_ROUNDTRIP_AND_FALLBACK_SET */ {
+ /* use all roundtrip and fallback results */
+ minValue=0x800;
+ }
+
for(st1=0; st1<maxStage1; ++st1) {
st2=table[st1];
if(st2>maxStage1) {
@@ -497,15 +511,8 @@
/* read the stage 3 block */
stage3=results+st3;
- /*
- * Add code points for which the roundtrip flag is set.
- * Once we get a set for fallback mappings, we have to use
- * a threshold variable with a value of 0x800.
- * See ucnv_MBCSSingleFromBMPWithOffsets() and
- * MBCS_SINGLE_RESULT_FROM_U() for details.
- */
do {
- if(*stage3++>=0xf00) {
+ if(*stage3++>=minValue) {
sa->add(sa->set, c);
}
} while((++c&0xf)!=0);
@@ -522,9 +529,12 @@
const uint8_t *stage3, *bytes;
uint32_t st3Multiplier;
uint32_t value;
+ UBool useFallback;
bytes=mbcsTable->fromUnicodeBytes;
+ useFallback=(UBool)(which==UCNV_ROUNDTRIP_AND_FALLBACK_SET);
+
switch(mbcsTable->outputType) {
case MBCS_OUTPUT_3:
case MBCS_OUTPUT_4_EUC:
@@ -551,9 +561,8 @@
st3>>=16;
/*
- * Add code points for which the roundtrip flag is set.
- * Once we get a set for fallback mappings, we have to check
- * non-roundtrip stage 3 results for whether they are 0.
+ * Add code points for which the roundtrip flag is set,
+ * or which map to non-zero bytes if we use fallbacks.
* See ucnv_MBCSFromUnicodeWithOffsets() for details.
*/
switch(filter) {
@@ -561,6 +570,23 @@
do {
if(st3&1) {
sa->add(sa->set, c);
+ stage3+=st3Multiplier;
+ } else if(useFallback) {
+ uint8_t b=0;
+ switch(st3Multiplier) {
+ case 4:
+ b|=*stage3++;
+ case 3:
+ b|=*stage3++;
+ case 2:
+ b|=stage3[0]|stage3[1];
+ stage3+=2;
+ default:
+ break;
+ }
+ if(b!=0) {
+ sa->add(sa->set, c);
+ }
}
st3>>=1;
} while((++c&0xf)!=0);
@@ -568,7 +594,7 @@
case UCNV_SET_FILTER_DBCS_ONLY:
/* Ignore single-byte results (<0x100). */
do {
- if((st3&1)!=0 && *((const uint16_t *)stage3)>=0x100) {
+ if(((st3&1)!=0 || useFallback) && *((const uint16_t *)stage3)>=0x100) {
sa->add(sa->set, c);
}
st3>>=1;
@@ -578,7 +604,7 @@
case UCNV_SET_FILTER_2022_CN:
/* Only add code points that map to CNS 11643 planes 1 & 2 for non-EXT ISO-2022-CN. */
do {
- if((st3&1)!=0 && ((value=*stage3)==0x81 || value==0x82)) {
+ if(((st3&1)!=0 || useFallback) && ((value=*stage3)==0x81 || value==0x82)) {
sa->add(sa->set, c);
}
st3>>=1;
@@ -588,13 +614,39 @@
case UCNV_SET_FILTER_SJIS:
/* Only add code points that map to Shift-JIS codes corresponding to JIS X 0208. */
do {
- if((st3&1)!=0 && (value=*((const uint16_t *)stage3))>=0x8140 && value<=0xeffc) {
+ if(((st3&1)!=0 || useFallback) && (value=*((const uint16_t *)stage3))>=0x8140 && value<=0xeffc) {
sa->add(sa->set, c);
}
st3>>=1;
stage3+=2; /* +=st3Multiplier */
} while((++c&0xf)!=0);
break;
+ case UCNV_SET_FILTER_GR94DBCS:
+ /* Only add code points that map to ISO 2022 GR 94 DBCS codes (each byte A1..FE). */
+ do {
+ if( ((st3&1)!=0 || useFallback) &&
+ (uint16_t)((value=*((const uint16_t *)stage3)) - 0xa1a1)<=(0xfefe - 0xa1a1) &&
+ (uint8_t)(value-0xa1)<=(0xfe - 0xa1)
+ ) {
+ sa->add(sa->set, c);
+ }
+ st3>>=1;
+ stage3+=2; /* +=st3Multiplier */
+ } while((++c&0xf)!=0);
+ break;
+ case UCNV_SET_FILTER_HZ:
+ /* Only add code points that are suitable for HZ DBCS (lead byte A1..FD). */
+ do {
+ if( ((st3&1)!=0 || useFallback) &&
+ (uint16_t)((value=*((const uint16_t *)stage3))-0xa1a1)<=(0xfdfe - 0xa1a1) &&
+ (uint8_t)(value-0xa1)<=(0xfe - 0xa1)
+ ) {
+ sa->add(sa->set, c);
+ }
+ st3>>=1;
+ stage3+=2; /* +=st3Multiplier */
+ } while((++c&0xf)!=0);
+ break;
default:
*pErrorCode=U_INTERNAL_PROGRAM_ERROR;
return;
@@ -609,7 +661,7 @@
}
}
- ucnv_extGetUnicodeSet(sharedData, sa, which, pErrorCode);
+ ucnv_extGetUnicodeSet(sharedData, sa, which, filter, pErrorCode);
}
U_CFUNC void
@@ -1694,7 +1746,7 @@
cnv->toUBytes[0]=*(source-1);
cnv->toULength=_extToU(cnv, cnv->sharedData,
1, &source, sourceLimit,
- &target, target+targetCapacity,
+ &target, pArgs->targetLimit,
&offsets, sourceIndex,
pArgs->flush,
pErrorCode);
@@ -3346,7 +3398,7 @@
lastSource=source;
c=_extFromU(cnv, cnv->sharedData,
c, &source, sourceLimit,
- &target, target+targetCapacity,
+ &target, (const uint8_t *)(pArgs->targetLimit),
&offsets, sourceIndex,
pArgs->flush,
pErrorCode);
« no previous file with comments | « third_party/icu38/source/common/ucnvmbcs.h ('k') | third_party/icu38/source/common/uset_imp.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698