Lines Matching refs:mbcsData
72 MBCSStartMappings(MBCSData *mbcsData);
75 MBCSAddToUnicode(MBCSData *mbcsData,
85 MBCSSingleAddFromUnicode(MBCSData *mbcsData,
91 MBCSAddFromUnicode(MBCSData *mbcsData,
97 MBCSPostprocess(MBCSData *mbcsData, const UConverterStaticData *staticData);
155 MBCSInit(MBCSData *mbcsData, UCMFile *ucm) { in MBCSInit() argument
156 uprv_memset(mbcsData, 0, sizeof(MBCSData)); in MBCSInit()
158 mbcsData->ucm=ucm; /* aliased, not owned */ in MBCSInit()
160 mbcsData->newConverter.close=MBCSClose; in MBCSInit()
161 mbcsData->newConverter.isValid=MBCSIsValid; in MBCSInit()
162 mbcsData->newConverter.addTable=MBCSAddTable; in MBCSInit()
163 mbcsData->newConverter.write=MBCSWrite; in MBCSInit()
168 MBCSData *mbcsData=(MBCSData *)uprv_malloc(sizeof(MBCSData)); in MBCSOpen() local
169 if(mbcsData==NULL) { in MBCSOpen()
174 MBCSInit(mbcsData, ucm); in MBCSOpen()
175 return &mbcsData->newConverter; in MBCSOpen()
179 MBCSDestruct(MBCSData *mbcsData) { in MBCSDestruct() argument
180 uprv_free(mbcsData->unicodeCodeUnits); in MBCSDestruct()
181 uprv_free(mbcsData->fromUBytes); in MBCSDestruct()
187 MBCSData *mbcsData=(MBCSData *)cnvData; in MBCSClose() local
188 if(mbcsData!=NULL) { in MBCSClose()
189 MBCSDestruct(mbcsData); in MBCSClose()
190 uprv_free(mbcsData); in MBCSClose()
196 MBCSStartMappings(MBCSData *mbcsData) { in MBCSStartMappings() argument
204 sum=mbcsData->ucm->states.countToUCodeUnits; in MBCSStartMappings()
210 mbcsData->unicodeCodeUnits=(uint16_t *)uprv_malloc(sum*sizeof(uint16_t)); in MBCSStartMappings()
211 if(mbcsData->unicodeCodeUnits==NULL) { in MBCSStartMappings()
217 mbcsData->unicodeCodeUnits[i]=0xfffe; in MBCSStartMappings()
222 maxCharLength=mbcsData->ucm->states.maxCharLength; in MBCSStartMappings()
232 mbcsData->fromUBytes=(uint8_t *)uprv_malloc(sum); in MBCSStartMappings()
233 if(mbcsData->fromUBytes==NULL) { in MBCSStartMappings()
237 uprv_memset(mbcsData->fromUBytes, 0, sum); in MBCSStartMappings()
280 mbcsData->stage1[i]=sum; in MBCSStartMappings()
283 mbcsData->stage2Top=stage2NullLength+stage2AllocLength; /* ==sum */ in MBCSStartMappings()
294 mbcsData->stage2Single[mbcsData->stage1[0]+i]=sum; in MBCSStartMappings()
300 mbcsData->stage2[mbcsData->stage1[0]+i]=sum; in MBCSStartMappings()
307 mbcsData->stageUTF8[i]=sum; in MBCSStartMappings()
316 … mbcsData->stage3Top=(stage3NullLength+stage3AllocLength)*maxCharLength; /* ==sum*maxCharLength */ in MBCSStartMappings()
323 setFallback(MBCSData *mbcsData, uint32_t offset, UChar32 c) { in setFallback() argument
324 int32_t i=ucm_findFallback(mbcsData->toUFallbacks, mbcsData->countToUFallbacks, offset); in setFallback()
327 mbcsData->toUFallbacks[i].codePoint=c; in setFallback()
331 i=mbcsData->countToUFallbacks; in setFallback()
336 mbcsData->toUFallbacks[i].offset=offset; in setFallback()
337 mbcsData->toUFallbacks[i].codePoint=c; in setFallback()
338 mbcsData->countToUFallbacks=i+1; in setFallback()
346 removeFallback(MBCSData *mbcsData, uint32_t offset) { in removeFallback() argument
347 int32_t i=ucm_findFallback(mbcsData->toUFallbacks, mbcsData->countToUFallbacks, offset); in removeFallback()
352 toUFallbacks=mbcsData->toUFallbacks; in removeFallback()
353 limit=mbcsData->countToUFallbacks; in removeFallback()
359 mbcsData->countToUFallbacks=limit-1; in removeFallback()
373 MBCSAddToUnicode(MBCSData *mbcsData, in MBCSAddToUnicode() argument
382 if(mbcsData->ucm->states.countStates==0) { in MBCSAddToUnicode()
388 if(length==2 && mbcsData->ucm->states.outputType==MBCS_OUTPUT_2_SISO) { in MBCSAddToUnicode()
398 entry=mbcsData->ucm->states.stateTable[state][bytes[i++]]; in MBCSAddToUnicode()
459 mbcsData->ucm->states.stateTable[state][bytes[i-1]]=entry; in MBCSAddToUnicode()
466 …if((old=mbcsData->unicodeCodeUnits[offset])!=0xfffe || (old=removeFallback(mbcsData, offset))!=-1)… in MBCSAddToUnicode()
483 if(mbcsData->unicodeCodeUnits[offset]==0xfffe) { in MBCSAddToUnicode()
484 return setFallback(mbcsData, offset, c); in MBCSAddToUnicode()
487 mbcsData->unicodeCodeUnits[offset]=(uint16_t)c; in MBCSAddToUnicode()
495 old=mbcsData->unicodeCodeUnits[offset]; in MBCSAddToUnicode()
501 … real=0x10000+((old&0x3ff)<<10)+((mbcsData->unicodeCodeUnits[offset+1])&0x3ff); in MBCSAddToUnicode()
503 real=mbcsData->unicodeCodeUnits[offset+1]; in MBCSAddToUnicode()
520 mbcsData->unicodeCodeUnits[offset++]=0xe001; in MBCSAddToUnicode()
521 mbcsData->unicodeCodeUnits[offset]=(uint16_t)c; in MBCSAddToUnicode()
524 mbcsData->unicodeCodeUnits[offset++]=(uint16_t)(0xdbc0+(c>>10)); in MBCSAddToUnicode()
525 mbcsData->unicodeCodeUnits[offset]=(uint16_t)(0xdc00+(c&0x3ff)); in MBCSAddToUnicode()
530 mbcsData->unicodeCodeUnits[offset]=(uint16_t)c; in MBCSAddToUnicode()
533 mbcsData->unicodeCodeUnits[offset++]=0xe000; in MBCSAddToUnicode()
534 mbcsData->unicodeCodeUnits[offset]=(uint16_t)c; in MBCSAddToUnicode()
537 mbcsData->unicodeCodeUnits[offset++]=(uint16_t)(0xd7c0+(c>>10)); in MBCSAddToUnicode()
538 mbcsData->unicodeCodeUnits[offset]=(uint16_t)(0xdc00+(c&0x3ff)); in MBCSAddToUnicode()
559 MBCSData *mbcsData=(MBCSData *)cnvData; in MBCSIsValid() local
561 return (UBool)(1==ucm_countChars(&mbcsData->ucm->states, bytes, length)); in MBCSIsValid()
565 MBCSSingleAddFromUnicode(MBCSData *mbcsData, in MBCSSingleAddFromUnicode() argument
587 stage3=(uint16_t *)mbcsData->fromUBytes; in MBCSSingleAddFromUnicode()
592 if(mbcsData->utf8Friendly && c<=SBCS_UTF8_MAX) { in MBCSSingleAddFromUnicode()
597 if(mbcsData->stage1[idx]==MBCS_STAGE_2_ALL_UNASSIGNED_INDEX) { in MBCSSingleAddFromUnicode()
599 newBlock=mbcsData->stage2Top; in MBCSSingleAddFromUnicode()
600 if(mbcsData->utf8Friendly) { in MBCSSingleAddFromUnicode()
602 while(min<newBlock && mbcsData->stage2Single[newBlock-1]==0) { in MBCSSingleAddFromUnicode()
617 mbcsData->stage1[idx]=(uint16_t)newBlock; in MBCSSingleAddFromUnicode()
618 mbcsData->stage2Top=newTop; in MBCSSingleAddFromUnicode()
622 idx=mbcsData->stage1[idx]+nextOffset; in MBCSSingleAddFromUnicode()
623 if(mbcsData->utf8Friendly && c<=SBCS_UTF8_MAX) { in MBCSSingleAddFromUnicode()
631 if(mbcsData->stage2Single[idx]==0) { in MBCSSingleAddFromUnicode()
633 newBlock=mbcsData->stage3Top; in MBCSSingleAddFromUnicode()
634 if(mbcsData->utf8Friendly) { in MBCSSingleAddFromUnicode()
649 mbcsData->stage2Single[i++]=(uint16_t)newBlock; in MBCSSingleAddFromUnicode()
652 mbcsData->stage3Top=newTop; /* ==newBlock */ in MBCSSingleAddFromUnicode()
656 p=stage3+mbcsData->stage2Single[idx]+nextOffset; in MBCSSingleAddFromUnicode()
683 MBCSAddFromUnicode(MBCSData *mbcsData, in MBCSAddFromUnicode() argument
695 maxCharLength=mbcsData->ucm->states.maxCharLength; in MBCSAddFromUnicode()
697 if( mbcsData->ucm->states.outputType==MBCS_OUTPUT_2_SISO && in MBCSAddFromUnicode()
718 stage3=mbcsData->fromUBytes; in MBCSAddFromUnicode()
722 if(mbcsData->utf8Friendly && c<=mbcsData->utf8Max) { in MBCSAddFromUnicode()
727 if(mbcsData->stage1[idx]==MBCS_STAGE_2_ALL_UNASSIGNED_INDEX) { in MBCSAddFromUnicode()
729 newBlock=mbcsData->stage2Top; in MBCSAddFromUnicode()
730 if(mbcsData->utf8Friendly) { in MBCSAddFromUnicode()
732 while(min<newBlock && mbcsData->stage2[newBlock-1]==0) { in MBCSAddFromUnicode()
750 mbcsData->stage1[i++]=(uint16_t)newBlock; in MBCSAddFromUnicode()
753 mbcsData->stage2Top=newTop; /* ==newBlock */ in MBCSAddFromUnicode()
757 idx=mbcsData->stage1[idx]+nextOffset; in MBCSAddFromUnicode()
758 if(mbcsData->utf8Friendly && c<=mbcsData->utf8Max) { in MBCSAddFromUnicode()
766 if(mbcsData->stage2[idx]==0) { in MBCSAddFromUnicode()
768 newBlock=mbcsData->stage3Top; in MBCSAddFromUnicode()
769 if(mbcsData->utf8Friendly && nextOffset>=MBCS_STAGE_3_GRANULARITY) { in MBCSAddFromUnicode()
794 mbcsData->stage2[i++]=(newBlock/MBCS_STAGE_3_GRANULARITY)/maxCharLength; in MBCSAddFromUnicode()
797 mbcsData->stage3Top=newTop; /* ==newBlock */ in MBCSAddFromUnicode()
800 stage3Index=MBCS_STAGE_3_GRANULARITY*(uint32_t)(uint16_t)mbcsData->stage2[idx]; in MBCSAddFromUnicode()
803 if(mbcsData->utf8Friendly && c<=mbcsData->utf8Max) { in MBCSAddFromUnicode()
824 mbcsData->utf8Max=0xfeff; in MBCSAddFromUnicode()
830 mbcsData->stageUTF8[c>>MBCS_UTF8_STAGE_SHIFT]=(uint16_t)stage3Index; in MBCSAddFromUnicode()
880 if((mbcsData->stage2[idx+(nextOffset>>MBCS_STAGE_2_SHIFT)]&(1UL<<(16+(c&0xf))))!=0 || old!=0) { in MBCSAddFromUnicode()
894 mbcsData->stage2[idx+(nextOffset>>4)]|=(1UL<<(16+(c&0xf))); in MBCSAddFromUnicode()
901 MBCSOkForBaseFromUnicode(const MBCSData *mbcsData, in MBCSOkForBaseFromUnicode() argument
928 if(mbcsData->utf8Friendly && flag<=1 && c<=mbcsData->utf8Max && (bytes[0]==0 || flag==1)) { in MBCSOkForBaseFromUnicode()
937 if(mbcsData->omitFromU && flag!=0) { in MBCSOkForBaseFromUnicode()
949 MBCSData *mbcsData; in MBCSAddTable() local
964 mbcsData=(MBCSData *)cnvData; in MBCSAddTable()
965 maxCharLength=mbcsData->ucm->states.maxCharLength; in MBCSAddTable()
972 mbcsData->utf8Friendly=utf8Friendly=(UBool)((table->flagsType&UCM_FLAGS_EXPLICIT)!=0); in MBCSAddTable()
974 mbcsData->utf8Max=MBCS_UTF8_MAX; in MBCSAddTable()
976 mbcsData->omitFromU=TRUE; in MBCSAddTable()
979 mbcsData->utf8Max=0; in MBCSAddTable()
986 if(!MBCSStartMappings(mbcsData)) { in MBCSAddTable()
1015 if( mbcsData->omitFromU && f<=1 && in MBCSAddTable()
1016 mbcsData->utf8Max<c && c<=0xffff && in MBCSAddTable()
1017 mbcsData->utf8Max<0xfeff in MBCSAddTable()
1019 mbcsData->utf8Max=0xffff; in MBCSAddTable()
1029 isOK&=MBCSAddToUnicode(mbcsData, m->b.bytes, m->bLen, c, f); in MBCSAddTable()
1032 isOK&=MBCSSingleAddFromUnicode(mbcsData, m->b.bytes, m->bLen, c, f); in MBCSAddTable()
1033 } else if(MBCSOkForBaseFromUnicode(mbcsData, m->b.bytes, m->bLen, c, f)) { in MBCSAddTable()
1034 isOK&=MBCSAddFromUnicode(mbcsData, m->b.bytes, m->bLen, c, f); in MBCSAddTable()
1044 isOK&=MBCSSingleAddFromUnicode(mbcsData, m->b.bytes, m->bLen, c, f); in MBCSAddTable()
1045 } else if(MBCSOkForBaseFromUnicode(mbcsData, m->b.bytes, m->bLen, c, f)) { in MBCSAddTable()
1047 isOK&=MBCSAddFromUnicode(mbcsData, m->b.bytes, m->bLen, c, f); in MBCSAddTable()
1063 isOK&=MBCSAddToUnicode(mbcsData, m->b.bytes, m->bLen, c, f); in MBCSAddTable()
1077 MBCSPostprocess(mbcsData, staticData); in MBCSAddTable()
1083 transformEUC(MBCSData *mbcsData) { in transformEUC() argument
1088 oldLength=mbcsData->ucm->states.maxCharLength; in transformEUC()
1093 old3Top=mbcsData->stage3Top; in transformEUC()
1098 p8=mbcsData->fromUBytes; in transformEUC()
1114 p8=mbcsData->fromUBytes; in transformEUC()
1117 mbcsData->ucm->states.outputType=(int8_t)(MBCS_OUTPUT_3_EUC+oldLength-3); in transformEUC()
1118 mbcsData->stage3Top=(old3Top*(oldLength-1))/oldLength; in transformEUC()
1180 singleCompactStage2(MBCSData *mbcsData) { in singleCompactStage2() argument
1190 while(start<mbcsData->stage2Top) { in singleCompactStage2()
1194 …for(i=0; i<MBCS_STAGE_2_BLOCK_SIZE && mbcsData->stage2Single[start+i]==0 && mbcsData->stage2Single… in singleCompactStage2()
1202 mbcsData->stage2Single[newStart++]=mbcsData->stage2Single[start++]; in singleCompactStage2()
1208 mbcsData->stage2Single[newStart++]=mbcsData->stage2Single[start++]; in singleCompactStage2()
1217 if(VERBOSE && newStart<mbcsData->stage2Top) { in singleCompactStage2()
1219 (unsigned long)mbcsData->stage2Top, (unsigned long)newStart, in singleCompactStage2()
1220 (long)(mbcsData->stage2Top-newStart)*2); in singleCompactStage2()
1222 mbcsData->stage2Top=newStart; in singleCompactStage2()
1226 mbcsData->stage1[i]=map[mbcsData->stage1[i]>>MBCS_STAGE_2_BLOCK_SIZE_SHIFT]; in singleCompactStage2()
1232 singleCompactStage3(MBCSData *mbcsData) { in singleCompactStage3() argument
1233 uint16_t *stage3=(uint16_t *)mbcsData->fromUBytes; in singleCompactStage3()
1244 while(start<mbcsData->stage3Top) { in singleCompactStage3()
1271 if(VERBOSE && newStart<mbcsData->stage3Top) { in singleCompactStage3()
1273 (unsigned long)mbcsData->stage3Top, (unsigned long)newStart, in singleCompactStage3()
1274 (long)(mbcsData->stage3Top-newStart)*2); in singleCompactStage3()
1276 mbcsData->stage3Top=newStart; in singleCompactStage3()
1279 for(i=0; i<mbcsData->stage2Top; ++i) { in singleCompactStage3()
1280 mbcsData->stage2Single[i]=map[mbcsData->stage2Single[i]>>4]; in singleCompactStage3()
1292 compactStage2(MBCSData *mbcsData) { in compactStage2() argument
1302 while(start<mbcsData->stage2Top) { in compactStage2()
1306 …for(i=0; i<MBCS_STAGE_2_BLOCK_SIZE && mbcsData->stage2[start+i]==0 && mbcsData->stage2[prevEnd-i]=… in compactStage2()
1314 mbcsData->stage2[newStart++]=mbcsData->stage2[start++]; in compactStage2()
1320 mbcsData->stage2[newStart++]=mbcsData->stage2[start++]; in compactStage2()
1329 if(VERBOSE && newStart<mbcsData->stage2Top) { in compactStage2()
1331 (unsigned long)mbcsData->stage2Top, (unsigned long)newStart, in compactStage2()
1332 (long)(mbcsData->stage2Top-newStart)*4); in compactStage2()
1334 mbcsData->stage2Top=newStart; in compactStage2()
1338 mbcsData->stage1[i]=map[mbcsData->stage1[i]>>MBCS_STAGE_2_BLOCK_SIZE_SHIFT]; in compactStage2()
1343 MBCSPostprocess(MBCSData *mbcsData, const UConverterStaticData * /*staticData*/) { in MBCSPostprocess() argument
1347 states=&mbcsData->ucm->states; in MBCSPostprocess()
1351 &mbcsData->unicodeCodeUnits, in MBCSPostprocess()
1352 mbcsData->toUFallbacks, mbcsData->countToUFallbacks, in MBCSPostprocess()
1356 if(transformEUC(mbcsData)) { in MBCSPostprocess()
1370 if(!mbcsData->utf8Friendly) { in MBCSPostprocess()
1372 singleCompactStage3(mbcsData); in MBCSPostprocess()
1373 singleCompactStage2(mbcsData); in MBCSPostprocess()
1375 compactStage2(mbcsData); in MBCSPostprocess()
1384 (unsigned long)mbcsData->stage2Top, in MBCSPostprocess()
1385 (unsigned long)mbcsData->stage2Top); in MBCSPostprocess()
1388 (unsigned long)mbcsData->stage3Top/stage3Width, in MBCSPostprocess()
1389 (unsigned long)mbcsData->stage3Top/stage3Width); in MBCSPostprocess()
1393 i2=mbcsData->stage1[i1]; in MBCSPostprocess()
1400 i3=mbcsData->stage2Single[i2]; in MBCSPostprocess()
1402 i3=(uint16_t)mbcsData->stage2[i2]; in MBCSPostprocess()
1424 MBCSData *mbcsData=(MBCSData *)cnvData; in MBCSWrite() local
1432 stage2Length=mbcsData->stage2Top; in MBCSWrite()
1433 if(mbcsData->omitFromU) { in MBCSWrite()
1435 int32_t utf8Limit=(int32_t)mbcsData->utf8Max+1; in MBCSWrite()
1439 if((utf8Limit&((1<<MBCS_STAGE_1_SHIFT)-1))!=0 && (st2=mbcsData->stage1[i])!=0) { in MBCSWrite()
1444 while(i>0 && (st2=mbcsData->stage1[--i])==0) {} in MBCSWrite()
1454 (unsigned long)mbcsData->stage2Top, in MBCSWrite()
1455 (unsigned long)mbcsData->stage3Top); in MBCSWrite()
1456 … printf("+ total size savings: %lu bytes\n", (unsigned long)stage2Start*4+mbcsData->stage3Top); in MBCSWrite()
1469 if(mbcsData->ucm->states.maxCharLength==1) { in MBCSWrite()
1471 mbcsData->stage1[i]+=(uint16_t)stage1Top; in MBCSWrite()
1479 mbcsData->stage3Top*=2; in MBCSWrite()
1481 if(mbcsData->utf8Friendly) { in MBCSWrite()
1486 …mbcsData->stage1[i]+=(uint16_t)stage1Top/2; /* stage 2 contains 32-bit entries, stage 1 16-bit ent… in MBCSWrite()
1493 if(mbcsData->utf8Friendly) { in MBCSWrite()
1494 stageUTF8Length=(mbcsData->utf8Max+1)>>MBCS_UTF8_STAGE_SHIFT; in MBCSWrite()
1495 header.version[2]=(uint8_t)(mbcsData->utf8Max>>8); /* store 0xd7 for max==0xd7ff */ in MBCSWrite()
1502 mbcsData->stage3Top=(mbcsData->stage3Top+3)&~3; in MBCSWrite()
1521 header.countStates=mbcsData->ucm->states.countStates; in MBCSWrite()
1522 header.countToUFallbacks=mbcsData->countToUFallbacks; in MBCSWrite()
1526 mbcsData->ucm->states.countStates*1024+ in MBCSWrite()
1527 mbcsData->countToUFallbacks*sizeof(_MBCSToUFallback); in MBCSWrite()
1530 mbcsData->ucm->states.countToUCodeUnits*2; in MBCSWrite()
1535 header.fromUBytesLength=mbcsData->stage3Top; in MBCSWrite()
1542 header.flags=(uint8_t)(mbcsData->ucm->states.outputType); in MBCSWrite()
1555 udata_writeBlock(pData, mbcsData->ucm->states.stateTable, header.countStates*1024); in MBCSWrite()
1556 …udata_writeBlock(pData, mbcsData->toUFallbacks, mbcsData->countToUFallbacks*sizeof(_MBCSToUFallbac… in MBCSWrite()
1557 udata_writeBlock(pData, mbcsData->unicodeCodeUnits, mbcsData->ucm->states.countToUCodeUnits*2); in MBCSWrite()
1558 udata_writeBlock(pData, mbcsData->stage1, stage1Top*2); in MBCSWrite()
1559 if(mbcsData->ucm->states.maxCharLength==1) { in MBCSWrite()
1560 udata_writeBlock(pData, mbcsData->stage2Single+stage2Start, stage2Length); in MBCSWrite()
1562 udata_writeBlock(pData, mbcsData->stage2+stage2Start, stage2Length); in MBCSWrite()
1565 udata_writeBlock(pData, mbcsData->fromUBytes, mbcsData->stage3Top); in MBCSWrite()
1569 udata_writeBlock(pData, mbcsData->stageUTF8, stageUTF8Length*2); in MBCSWrite()