/* we do not expect this to be called */ static UBool
CnvExtIsValid(NewConverter *cnvData, const uint8_t *bytes, int32_t length) { // suppress compiler warnings about unused variables
(void)cnvData;
(void)bytes;
(void)length; returnfalse;
}
/* write the header and base table name for an extension-only table */
length=(int32_t)uprv_strlen(extData->ucm->baseName)+1; while(length&3) { /* add padding */
extData->ucm->baseName[length++]=0;
}
headerSize=MBCS_HEADER_V4_LENGTH*4+length;
/* fill the header */
header.version[0]=4;
header.version[1]=2;
header.flags=(uint32_t)((headerSize<<8)|MBCS_OUTPUT_EXT_ONLY);
/* write the header and the base table name */
udata_writeBlock(pData, &header, MBCS_HEADER_V4_LENGTH*4);
udata_writeBlock(pData, extData->ucm->baseName, length);
}
/* fill indexes[] - offsets/indexes are in units of the target array */
top=0;
/* write the Unicode result code point or string index */ if(m->uLen==1) {
u16Length=U16_LENGTH(m->u);
value=(uint32_t)(UCNV_EXT_TO_U_MIN_CODE_POINT+m->u);
} else { /* the parser enforces m->uLen<=UCNV_EXT_MAX_UCHARS */
/* get the result code point string and its 16-bit string length */
u32=UCM_GET_CODE_POINTS(table, m);
errorCode=U_ZERO_ERROR;
u_strFromUTF32(NULL, 0, &u16Length, u32, m->uLen, &errorCode); if(U_FAILURE(errorCode) && errorCode!=U_BUFFER_OVERFLOW_ERROR) { exit(errorCode);
}
/* allocate it and put its length and index into the value */
value=
(((uint32_t)u16Length+UCNV_EXT_TO_U_LENGTH_OFFSET)<<UCNV_EXT_TO_U_LENGTH_SHIFT)|
((uint32_t)utm_countItems(extData->toUUChars));
u=utm_allocN(extData->toUUChars, u16Length);
/* allocate the section: 1 entry for the header + count for the items */
section=(uint32_t *)utm_allocN(extData->toUTable, 1+count);
/* write the section header */
*section++=((uint32_t)count<<UCNV_EXT_TO_U_BYTE_SHIFT)|defaultValue;
/* step 3: write temporary section table with subsection starts */
prev=low-1; /* just before low to prevent empty subsections before low */
j=0; /* section table index */ for(i=start; i<limit; ++i) {
m=mappings+map[i];
bytes=UCM_GET_BYTES(table, m);
high=bytes[unitIndex];
if(high!=prev) { /* start of a new subsection for unit high */ if(count>uniqueCount) { /* write empty subsections for unused units in a linear table */ while(++prev<high) {
section[j++]=((uint32_t)prev<<UCNV_EXT_TO_U_BYTE_SHIFT)|(uint32_t)i;
}
} else {
prev=high;
}
/* write the entry with the subsection start */
section[j++]=((uint32_t)high<<UCNV_EXT_TO_U_BYTE_SHIFT)|(uint32_t)i;
}
} /* assert(j==count) */
/* remove the subStart temporary value */
section[j]&=~UCNV_EXT_TO_U_VALUE_MASK;
if(subStart==subLimit) { /* leave the value zero: empty subsection for unused unit in a linear table */ continue;
}
/* see if there is exactly one input unit sequence of length unitIndex+1 */
defaultValue=0;
m=mappings+map[subStart]; if(m->bLen==unitIndex+1) { /* do not include this in generateToUTable() */
++subStart;
if(subStart<subLimit && mappings[map[subStart]].bLen==unitIndex+1) { /* print error for multiple same-input-sequence mappings */
fprintf(stderr, "error: multiple mappings from same bytes\n");
ucm_printMapping(table, m, stderr);
ucm_printMapping(table, mappings+map[subStart], stderr); returnfalse;
}
if(subStart==subLimit) { /* write the result for the input sequence ending here */
section[j]|=defaultValue;
} else { /* write the index to the subsection table */
section[j]|=(uint32_t)utm_countItems(extData->toUTable);
bytes=UCM_GET_BYTES(table, m);
value=0; switch(m->bLen) { /* 1..3: store the bytes in the value word */ case3:
value=((uint32_t)*bytes++)<<16;
U_FALLTHROUGH; case2:
value|=((uint32_t)*bytes++)<<8;
U_FALLTHROUGH; case1:
value|=*bytes; break; default: /* the parser enforces m->bLen<=UCNV_EXT_MAX_BYTES */ /* store the bytes in fromUBytes[] and the index in the value word */
value=(uint32_t)utm_countItems(extData->fromUBytes);
resultBytes=utm_allocN(extData->fromUBytes, m->bLen);
uprv_memcpy(resultBytes, bytes, m->bLen); break;
}
value|=(uint32_t)m->bLen<<UCNV_EXT_FROM_U_LENGTH_SHIFT; if(m->f==0) {
value|=UCNV_EXT_FROM_U_ROUNDTRIP_FLAG;
} elseif(m->f==4) {
value|=UCNV_EXT_FROM_U_GOOD_ONE_WAY_FLAG;
}
/* calculate the real UTF-16 length (see recoding in prepareFromUMappings()) */ if(m->uLen==1) {
u16Length=U16_LENGTH(m->u);
} else {
u16Length=U16_LENGTH(UCM_GET_CODE_POINTS(table, m)[0])+(m->uLen-2);
}
/* step 2: allocate the section; set count, section */ /* the fromUTable always stores for access via binary search */
count=uniqueCount;
/* allocate the section: 1 entry for the header + count for the items */
sectionUChars=(UChar *)utm_allocN(extData->fromUTableUChars, 1+count);
sectionValues=(uint32_t *)utm_allocN(extData->fromUTableValues, 1+count);
/* write the section header */
*sectionUChars++=(UChar)count;
*sectionValues++=defaultValue;
/* step 3: write temporary section table with subsection starts */
prev=low-1; /* just before low to prevent empty subsections before low */
j=0; /* section table index */ for(i=start; i<limit; ++i) {
m=mappings+map[i];
uchars=(UChar *)UCM_GET_CODE_POINTS(table, m);
high=uchars[unitIndex];
if(high!=prev) { /* start of a new subsection for unit high */
prev=high;
/* write the entry with the subsection start */
sectionUChars[j]=(UChar)high;
sectionValues[j]=(uint32_t)i;
++j;
}
} /* assert(j==count) */
/* see if there is exactly one input unit sequence of length unitIndex+1 */
defaultValue=0;
m=mappings+map[subStart]; if(m->uLen==unitIndex+1) { /* do not include this in generateToUTable() */
++subStart;
if(subStart<subLimit && mappings[map[subStart]].uLen==unitIndex+1) { /* print error for multiple same-input-sequence mappings */
fprintf(stderr, "error: multiple mappings from same Unicode code points\n");
ucm_printMapping(table, m, stderr);
ucm_printMapping(table, mappings+map[subStart], stderr); returnfalse;
}
if(subStart==subLimit) { /* write the result for the input sequence ending here */
sectionValues[j]=defaultValue;
} else { /* write the index to the subsection table */
sectionValues[j]=(uint32_t)utm_countItems(extData->fromUTableValues);
if(extData->stage2[i2]==0) { /* allocate another block in stage 3; overlap with the previous block */
newBlock=extData->stage3Top;
min=newBlock-nextOffset; /* minimum block start with overlap */ while(min<newBlock && extData->stage3[newBlock-1]==0) {
--newBlock;
}
/* round up to a multiple of stage 3 granularity >1 (similar to utrie.c) */
newBlock=(newBlock+(UCNV_EXT_STAGE_3_GRANULARITY-1))&~(UCNV_EXT_STAGE_3_GRANULARITY-1);
extData->stage2[i2]=(uint16_t)(newBlock>>UCNV_EXT_STAGE_2_LEFT_SHIFT);
extData->stage3Top=newBlock+MBCS_STAGE_3_BLOCK_SIZE; if(extData->stage3Top>UPRV_LENGTHOF(extData->stage3)) {
fprintf(stderr, "error: too many stage 3 entries at U+%04x\n", (int)c); exit(U_MEMORY_ALLOCATION_ERROR);
}
}
/* is the entire block filled with <subchar1> |2 mappings? */ if(nextOffset==MBCS_STAGE_3_BLOCK_SIZE-1) { for(min=i3-nextOffset;
min<i3 && extData->stage3[min]==1;
++min) {}
if(min==i3) { /* the entire block is filled with these mappings */ if(extData->stage3Sub1Block!=0) { /* point to the previous such block and remove this block from stage3 */
extData->stage2[i2]=extData->stage3Sub1Block;
extData->stage3Top-=MBCS_STAGE_3_BLOCK_SIZE;
uprv_memset(extData->stage3+extData->stage3Top, 0, MBCS_STAGE_3_BLOCK_SIZE*2);
} else { /* remember this block's stage2 entry */
extData->stage3Sub1Block=extData->stage2[i2];
}
}
}
} else { if((i3b=extData->stage3bTop++)>=UPRV_LENGTHOF(extData->stage3b)) {
fprintf(stderr, "error: too many stage 3b entries at U+%04x\n", (int)c); exit(U_MEMORY_ALLOCATION_ERROR);
}
/* roundtrip or fallback mapping */
extData->stage3[i3]=(uint16_t)i3b;
extData->stage3b[i3b]=value;
}
}
/* *iterateoversame-initial-codepointmappings, *entertheinitialcodepointintothetrie, *andstartarecursiononthecorrespondingmappingssection *withgenerateFromUTable()
*/
m=mappings+map[0];
codePoints=UCM_GET_CODE_POINTS(table, m);
next=codePoints[0];
subLimit=0; while(subLimit<mapLength) { /* get a new subsection of mappings starting with the same code point */
subStart=subLimit;
c=next; while(next==c && ++subLimit<mapLength) {
m=mappings+map[subLimit];
codePoints=UCM_GET_CODE_POINTS(table, m);
next=codePoints[0];
}
/* *computethevalueforthiscodepoint; *ifthereisamappingforthiscodepointalone,itisatsubStart *becausethetableissortedlexically
*/
value=0;
m=mappings+map[subStart];
codePoints=UCM_GET_CODE_POINTS(table, m); if(m->uLen==1) { /* do not include this in generateFromUTable() */
++subStart;
if(subStart<subLimit && mappings[map[subStart]].uLen==1) { /* print error for multiple same-input-sequence mappings */
fprintf(stderr, "error: multiple mappings from same Unicode code points\n");
ucm_printMapping(table, m, stderr);
ucm_printMapping(table, mappings+map[subStart], stderr); returnfalse;
}
value=getFromUBytesValue(extData, table, m);
}
if(subStart==subLimit) { /* write the result for this one code point */
addFromUTrieEntry(extData, c, value);
} else { /* write the index to the subsection table */
addFromUTrieEntry(extData, c, (uint32_t)utm_countItems(extData->fromUTableValues));
/* recurse, starting from 16-bit-unit index 2, the first 16-bit unit after c */ if(!generateFromUTable(extData, table, subStart, subLimit, 2, value)) { returnfalse;
}
}
} returntrue;
}
/* allocate the first entry in the fromUTable because index 0 means "no result" */
utm_alloc(extData->fromUTableUChars);
utm_alloc(extData->fromUTableValues);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.