/* control optimizations according to the platform */ #define MBCS_UNROLL_SINGLE_TO_BMP 1 #define MBCS_UNROLL_SINGLE_FROM_BMP 0
/* * _MBCSHeader versions 5.3 & 4.3 * (Note that the _MBCSHeader version is in addition to the converter formatVersion.) * * This version is optional. Version 5 is used for incompatible data format changes. * makeconv will continue to generate version 4 files if possible. * * Changes from version 4: * * The main difference is an additional _MBCSHeader field with * - the length (number of uint32_t) of the _MBCSHeader * - flags for further incompatible data format changes * - flags for further, backward compatible data format changes * * The MBCS_OPT_FROM_U flag indicates that most of the fromUnicode data is omitted from * the file and needs to be reconstituted at load time. * This requires a utf8Friendly format with an additional mbcsIndex table for fast * (and UTF-8-friendly) fromUnicode conversion for Unicode code points up to maxFastUChar. * (For details about these structures see below, and see ucnvmbcs.h.) * * utf8Friendly also implies that the fromUnicode mappings are stored in ascending order * of the Unicode code points. (This requires that the .ucm file has the |0 etc. * precision markers for all mappings.) * * All fallbacks have been moved to the extension table, leaving only roundtrips in the * omitted data that can be reconstituted from the toUnicode data. * * Of the stage 2 table, the part corresponding to maxFastUChar and below is omitted. * With only roundtrip mappings in the base fromUnicode data, this part is fully * redundant with the mbcsIndex and will be reconstituted from that (also using the * stage 1 table which contains the information about how stage 2 was compacted). * * The rest of the stage 2 table, the part for code points above maxFastUChar, * is stored in the file and will be appended to the reconstituted part. * * The entire fromUBytes array is omitted from the file and will be reconstitued. * This is done by enumerating all toUnicode roundtrip mappings, performing * each mapping (using the stage 1 and reconstituted stage 2 tables) and * writing instead of reading the byte values. * * _MBCSHeader version 4.3 * * Change from version 4.2: * - Optional utf8Friendly data structures, with 64-entry stage 3 block * allocation for parts of the BMP, and an additional mbcsIndex in non-SBCS * files which can be used instead of stages 1 & 2. * Faster lookups for roundtrips from most commonly used characters, * and lookups from UTF-8 byte sequences with a natural bit distribution. * See ucnvmbcs.h for more details. * * Change from version 4.1: * - Added an optional extension table structure at the end of the .cnv file. * It is present if the upper bits of the header flags field contains a non-zero * byte offset to it. * Files that contain only a conversion table and no base table * use the special outputType MBCS_OUTPUT_EXT_ONLY. * These contain the base table name between the MBCS header and the extension * data. * * Change from version 4.0: * - Replace header.reserved with header.fromUBytesLength so that all * fields in the data have length. * * Changes from version 3 (for performance improvements): * - new bit distribution for state table entries * - reordered action codes * - new data structure for single-byte fromUnicode * + stage 2 only contains indexes * + stage 3 stores 16 bits per character with classification bits 15..8 * - no multiplier for stage 1 entries * - stage 2 for non-single-byte codepages contains the index and the flags in * one 32-bit value * - 2-byte and 4-byte fromUnicode results are stored directly as 16/32-bit integers * * For more details about old versions of the MBCS data structure, see * the corresponding versions of this file. * * Converting stateless codepage data ---------------------------------------*** * (or codepage data with simple states) to Unicode. * * Data structure and algorithm for converting from complex legacy codepages * to Unicode. (Designed before 2000-may-22.) * * The basic idea is that the structure of legacy codepages can be described * with state tables. * When reading a byte stream, each input byte causes a state transition. * Some transitions result in the output of a code point, some result in * "unassigned" or "illegal" output. * This is used here for character conversion. * * The data structure begins with a state table consisting of a row * per state, with 256 entries (columns) per row for each possible input * byte value. * Each entry is 32 bits wide, with two formats distinguished by * the sign bit (bit 31): * * One format for transitional entries (bit 31 not set) for non-final bytes, and * one format for final entries (bit 31 set). * Both formats contain the number of the next state in the same bit * positions. * State 0 is the initial state. * * Most of the time, the offset values of subsequent states are added * up to a scalar value. This value will eventually be the index of * the Unicode code point in a table that follows the state table. * The effect is that the code points for final state table rows * are contiguous. The code points of final state rows follow each other * in the order of the references to those final states by previous * states, etc. * * For some terminal states, the offset is itself the output Unicode * code point (16 bits for a BMP code point or 20 bits for a supplementary * code point (stored as code point minus 0x10000 so that 20 bits are enough). * For others, the code point in the Unicode table is stored with either * one or two code units: one for BMP code points, two for a pair of * surrogates. * All code points for a final state entry take up the same number of code * units, regardless of whether they all actually _use_ the same number * of code units. This is necessary for simple array access. * * An additional feature comes in with what in ICU is called "fallback" * mappings: * * In addition to round-trippable, precise, 1:1 mappings, there are often * mappings defined between similar, though not the same, characters. * Typically, such mappings occur only in fromUnicode mapping tables because * Unicode has a superset repertoire of most other codepages. However, it * is possible to provide such mappings in the toUnicode tables, too. * In this case, the fallback mappings are partly integrated into the * general state tables because the structure of the encoding includes their * byte sequences. * For final entries in an initial state, fallback mappings are stored in * the entry itself like with roundtrip mappings. * For other final entries, they are stored in the code units table if * the entry is for a pair of code units. * For single-unit results in the code units table, there is no space to * alternatively hold a fallback mapping; in this case, the code unit * is stored as U+fffe (unassigned), and the fallback mapping needs to * be looked up by the scalar offset value in a separate table. * * "Unassigned" state entries really mean "structurally unassigned", * i.e., such a byte sequence will never have a mapping result. * * The interpretation of the bits in each entry is as follows: * * Bit 31 not set, not a terminal entry ("transitional"): * 30..24 next state * 23..0 offset delta, to be added up * * Bit 31 set, terminal ("final") entry: * 30..24 next state (regardless of action code) * 23..20 action code: * action codes 0 and 1 result in precise-mapping Unicode code points * 0 valid byte sequence * 19..16 not used, 0 * 15..0 16-bit Unicode BMP code point * never U+fffe or U+ffff * 1 valid byte sequence * 19..0 20-bit Unicode supplementary code point * never U+fffe or U+ffff * * action codes 2 and 3 result in fallback (unidirectional-mapping) Unicode code points * 2 valid byte sequence (fallback) * 19..16 not used, 0 * 15..0 16-bit Unicode BMP code point as fallback result * 3 valid byte sequence (fallback) * 19..0 20-bit Unicode supplementary code point as fallback result * * action codes 4 and 5 may result in roundtrip/fallback/unassigned/illegal results * depending on the code units they result in * 4 valid byte sequence * 19..9 not used, 0 * 8..0 final offset delta * pointing to one 16-bit code unit which may be * fffe unassigned -- look for a fallback for this offset * ffff illegal * 5 valid byte sequence * 19..9 not used, 0 * 8..0 final offset delta * pointing to two 16-bit code units * (typically UTF-16 surrogates) * the result depends on the first code unit as follows: * 0000..d7ff roundtrip BMP code point (1st alone) * d800..dbff roundtrip surrogate pair (1st, 2nd) * dc00..dfff fallback surrogate pair (1st-400, 2nd) * e000 roundtrip BMP code point (2nd alone) * e001 fallback BMP code point (2nd alone) * fffe unassigned * ffff illegal * (the final offset deltas are at most 255 * 2, * times 2 because of storing code unit pairs) * * 6 unassigned byte sequence * 19..16 not used, 0 * 15..0 16-bit Unicode BMP code point U+fffe (new with version 2) * this does not contain a final offset delta because the main * purpose of this action code is to save scalar offset values; * therefore, fallback values cannot be assigned to byte * sequences that result in this action code * 7 illegal byte sequence * 19..16 not used, 0 * 15..0 16-bit Unicode BMP code point U+ffff (new with version 2) * 8 state change only * 19..0 not used, 0 * useful for state changes in simple stateful encodings, * at Shift-In/Shift-Out codes * * * 9..15 reserved for future use * current implementations will only perform a state change * and ignore bits 19..0 * * An encoding with contiguous ranges of unassigned byte sequences, like * Shift-JIS and especially EUC-TW, can be stored efficiently by having * at least two states for the trail bytes: * One trail byte state that results in code points, and one that only * has "unassigned" and "illegal" terminal states. * * Note: partly by accident, this data structure supports simple stateful * encodings without any additional logic. * Currently, only simple Shift-In/Shift-Out schemes are handled with * appropriate state tables (especially EBCDIC_STATEFUL!). * * MBCS version 2 added: * unassigned and illegal action codes have U+fffe and U+ffff * instead of unused bits; this is useful for _MBCS_SINGLE_SIMPLE_GET_NEXT_BMP() * * Converting from Unicode to codepage bytes --------------------------------*** * * The conversion data structure for fromUnicode is designed for the known * structure of Unicode. It maps from 21-bit code points (0..0x10ffff) to * a sequence of 1..4 bytes, in addition to a flag that indicates if there is * a roundtrip mapping. * * The lookup is done with a 3-stage trie, using 11/6/4 bits for stage 1/2/3 * like in the character properties table. * The beginning of the trie is at offsetFromUTable, the beginning of stage 3 * with the resulting bytes is at offsetFromUBytes. * * Beginning with version 4, single-byte codepages have a significantly different * trie compared to other codepages. * In all cases, the entry in stage 1 is directly the index of the block of * 64 entries in stage 2. * * Single-byte lookup: * * Stage 2 only contains 16-bit indexes directly to the 16-blocks in stage 3. * Stage 3 contains one 16-bit word per result: * Bits 15..8 indicate the kind of result: * f roundtrip result * c fallback result from private-use code point * 8 fallback result from other code points * 0 unassigned * Bits 7..0 contain the codepage byte. A zero byte is always possible. * * In version 4.3, the runtime code can build an sbcsIndex for a utf8Friendly * file. For 2-byte UTF-8 byte sequences and some 3-byte sequences the lookup * becomes a 2-stage (single-index) trie lookup with 6 bits for stage 3. * ASCII code points can be looked up with a linear array access into stage 3. * See maxFastUChar and other details in ucnvmbcs.h. * * Multi-byte lookup: * * Stage 2 contains a 32-bit word for each 16-block in stage 3: * Bits 31..16 contain flags for which stage 3 entries contain roundtrip results * test: MBCS_FROM_U_IS_ROUNDTRIP(stage2Entry, c) * If this test is false, then a non-zero result will be interpreted as * a fallback mapping. * Bits 15..0 contain the index to stage 3, which must be multiplied by 16*(bytes per char) * * Stage 3 contains 2, 3, or 4 bytes per result. * 2 or 4 bytes are stored as uint16_t/uint32_t in platform endianness, * while 3 bytes are stored as bytes in big-endian order. * Leading zero bytes are ignored, and the number of bytes is counted. * A zero byte mapping result is possible as a roundtrip result. * For some output types, the actual result is processed from this; * see ucnv_MBCSFromUnicodeWithOffsets(). * * Note that stage 1 always contains 0x440=1088 entries (0x440==0x110000>>10), * or (version 3 and up) for BMP-only codepages, it contains 64 entries. * * In version 4.3, a utf8Friendly file contains an mbcsIndex table. * For 2-byte UTF-8 byte sequences and most 3-byte sequences the lookup * becomes a 2-stage (single-index) trie lookup with 6 bits for stage 3. * ASCII code points can be looked up with a linear array access into stage 3. * See maxFastUChar, mbcsIndex and other details in ucnvmbcs.h. * * In version 3, stage 2 blocks may overlap by multiples of the multiplier * for compaction. * In version 4, stage 2 blocks (and for single-byte codepages, stage 3 blocks) * may overlap by any number of entries. * * MBCS version 2 added: * the converter checks for known output types, which allows * adding new ones without crashing an unaware converter
*/
/** * Callback from ucnv_MBCSEnumToUnicode(), takes 32 mappings from * consecutive sequences of bytes, starting from the one encoded in value, * to Unicode code points. (Multiple mappings to reduce per-function call overhead.) * Does not currently support m:n mappings or reverse fallbacks. * This function will not be called for sequences of bytes with leading zeros. * * @param context an opaque pointer, as passed into ucnv_MBCSEnumToUnicode() * @param value contains 1..4 bytes of the first byte sequence, right-aligned * @param codePoints resulting Unicode code points, or negative if a byte sequence does * not map to anything * @return true to continue enumeration, false to stop
*/ typedef UBool U_CALLCONV
UConverterEnumToUCallback(constvoid *context, uint32_t value, UChar32 codePoints[32]);
/* * Some ranges of GB 18030 where both the Unicode code points and the * GB four-byte sequences are contiguous and are handled algorithmically by * the special callback functions below. * The values are start & end of Unicode & GB codes. * * Note that single surrogates are not mapped by GB 18030 * as of the re-released mapping tables from 2000-nov-30.
*/ staticconst uint32_t
gb18030Ranges[14][4]={
{0x10000, 0x10FFFF, LINEAR(0x90308130), LINEAR(0xE3329A35)},
{0x9FA6, 0xD7FF, LINEAR(0x82358F33), LINEAR(0x8336C738)},
{0x0452, 0x1E3E, LINEAR(0x8130D330), LINEAR(0x8135F436)},
{0x1E40, 0x200F, LINEAR(0x8135F438), LINEAR(0x8136A531)},
{0xE865, 0xF92B, LINEAR(0x8336D030), LINEAR(0x84308534)},
{0x2643, 0x2E80, LINEAR(0x8137A839), LINEAR(0x8138FD38)},
{0xFA2A, 0xFE2F, LINEAR(0x84309C38), LINEAR(0x84318537)},
{0x3CE1, 0x4055, LINEAR(0x8231D438), LINEAR(0x8232AF32)},
{0x361B, 0x3917, LINEAR(0x8230A633), LINEAR(0x8230F237)},
{0x49B8, 0x4C76, LINEAR(0x8234A131), LINEAR(0x8234E733)},
{0x4160, 0x4336, LINEAR(0x8232C937), LINEAR(0x8232F837)},
{0x478E, 0x4946, LINEAR(0x8233E838), LINEAR(0x82349638)},
{0x44D7, 0x464B, LINEAR(0x8233A339), LINEAR(0x8233C931)},
{0xFFE6, 0xFFFF, LINEAR(0x8431A234), LINEAR(0x8431A439)}
};
/* bit flag for UConverter.options indicating GB 18030 special handling */ #define _MBCS_OPTION_GB18030 0x8000
/* bit flag for UConverter.options indicating KEIS,JEF,JIF special handling */ #define _MBCS_OPTION_KEIS 0x01000 #define _MBCS_OPTION_JEF 0x02000 #define _MBCS_OPTION_JIPS 0x04000
/* * Only called if stateProps[state]==-1. * A recursive call may do stateProps[state]|=0x40 if this state is the target of an * MBCS_STATE_CHANGE_ONLY.
*/ static int8_t
getStateProp(const int32_t (*stateTable)[256], int8_t stateProps[], int state) { const int32_t *row;
int32_t min, max, entry, nextState;
/* * Internal function enumerating the toUnicode data of an MBCS converter. * Currently only used for reconstituting data for a MBCS_OPT_NO_FROM_U * table, but could also be used for a future ucnv_getUnicodeSet() option * that includes reverse fallbacks (after updating this function's implementation). * Currently only handles roundtrip mappings. * Does not currently handle extensions.
*/ staticvoid
ucnv_MBCSEnumToUnicode(UConverterMBCSTable *mbcsTable,
UConverterEnumToUCallback *callback, constvoid *context,
UErrorCode *pErrorCode) { /* * Properties for each state, to speed up the enumeration. * Ignorable actions are unassigned/illegal/state-change-only: * They do not lead to mappings. * * Bits 7..6: * 1 direct/initial state (stateful converters have multiple) * 0 non-initial state with transitions or with non-ignorable result actions * -1 final state with only ignorable actions * * Bits 5..3: * The lowest byte value with non-ignorable actions is * value<<5 (rounded down). * * Bits 2..0: * The highest byte value with non-ignorable actions is * (value<<5)&0x1f (rounded up).
*/
int8_t stateProps[MBCS_MAX_STATE_COUNT];
int32_t state;
uprv_memset(stateProps, -1, sizeof(stateProps));
/* recurse from state 0 and set all stateProps */
getStateProp(mbcsTable->stateTable, stateProps, 0);
for(state=0; state<mbcsTable->countStates; ++state) { /*if(stateProps[state]==-1) { printf("unused/unreachable <icu:state> %d\n", state);
}*/ if(stateProps[state]>=0x40) { /* start from each direct state */
enumToU(
mbcsTable, stateProps, state, 0, 0,
callback, context,
pErrorCode);
}
}
}
/* * 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;
}
range=gb18030Ranges[0]; for(i=0; i<UPRV_LENGTHOF(gb18030Ranges); range+=4, ++i) { if (range[0] <= static_cast<uint32_t>(cp) && static_cast<uint32_t>(cp) <= range[1]) { /* found the Unicode code point, output the four-byte sequence for it */
uint32_t linear; char bytes[4];
/* get the linear value of the first GB 18030 code in this range */
linear=range[2]-LINEAR_18030_BASE;
/* add the offset from the beginning of the range */
linear += (static_cast<uint32_t>(cp) - range[0]);
/* turn this into a four-byte sequence */
bytes[3] = static_cast<char>(0x30 + linear % 10); linear /= 10;
bytes[2] = static_cast<char>(0x81 + linear % 126); linear /= 126;
bytes[1] = static_cast<char>(0x30 + linear % 10); linear /= 10;
bytes[0] = static_cast<char>(0x81 + linear);
linear=LINEAR_18030(cnv->toUBytes[0], cnv->toUBytes[1], cnv->toUBytes[2], cnv->toUBytes[3]);
range=gb18030Ranges[0]; for(i=0; i<UPRV_LENGTHOF(gb18030Ranges); range+=4, ++i) { if(range[2]<=linear && linear<=range[3]) { /* found the sequence, output the Unicode code point for it */
*pErrorCode=U_ZERO_ERROR;
/* add the linear difference between the input and start sequences to the start code point */
linear=range[0]+(linear-range[2]);
/* output this code point */
ucnv_toUWriteCodePoint(cnv, linear, target, targetLimit, offsets, sourceIndex, pErrorCode);
return 0;
}
}
}
/* no mapping */
*pErrorCode=U_INVALID_CHAR_FOUND; return length;
}
/* * This code modifies a standard EBCDIC<->Unicode mapping table for * OS/390 (z/OS) Unix System Services (Open Edition). * The difference is in the mapping of Line Feed and New Line control codes: * Standard EBCDIC maps * * <U000A> \x25 |0 * <U0085> \x15 |0 * * but OS/390 USS EBCDIC swaps the control codes for LF and NL, * mapping * * <U000A> \x15 |0 * <U0085> \x25 |0 * * This code modifies a loaded standard EBCDIC<->Unicode mapping table * by copying it into allocated memory and swapping the LF and NL values. * It allows to support the same EBCDIC charset in both versions without * duplicating the entire installed table.
*/
/* * Check that this is an EBCDIC table with SBCS portion - * SBCS or EBCDIC_STATEFUL with standard EBCDIC LF and NL mappings. * * If not, ignore the option. Options are always ignored if they do not apply.
*/ if(!(
(mbcsTable->outputType==MBCS_OUTPUT_1 || mbcsTable->outputType==MBCS_OUTPUT_2_SISO) &&
mbcsTable->stateTable[0][EBCDIC_LF]==MBCS_ENTRY_FINAL(0, MBCS_STATE_VALID_DIRECT_16, U_LF) &&
mbcsTable->stateTable[0][EBCDIC_NL]==MBCS_ENTRY_FINAL(0, MBCS_STATE_VALID_DIRECT_16, U_NL)
)) { returnfalse;
}
if(mbcsTable->fromUBytesLength>0) { /* * We _know_ the number of bytes in the fromUnicodeBytes array * starting with header.version 4.1.
*/
sizeofFromUBytes=mbcsTable->fromUBytesLength;
} else { /* * Otherwise: * There used to be code to enumerate the fromUnicode * trie and find the highest entry, but it was removed in ICU 3.2 * because it was not tested and caused a low code coverage number. * See Jitterbug 3674. * This affects only some .cnv file formats with a header.version * below 4.1, and only when swaplfnl is requested. * * ucnvmbcs.c revision 1.99 is the last one with the * ucnv_MBCSSizeofFromUBytes() function.
*/
*pErrorCode=U_INVALID_FORMAT_ERROR; returnfalse;
}
/* * The table has an appropriate format. * Allocate and build * - a modified to-Unicode state table * - a modified from-Unicode output array * - a converter name string with the swap option appended
*/
size=
mbcsTable->countStates*1024+
sizeofFromUBytes+
UCNV_MAX_CONVERTER_NAME_LENGTH+20;
p = static_cast<uint8_t*>(uprv_malloc(size)); if(p==nullptr) {
*pErrorCode=U_MEMORY_ALLOCATION_ERROR; returnfalse;
}
/* copy and modify the to-Unicode state table */
newStateTable = reinterpret_cast<int32_t(*)[256]>(p);
uprv_memcpy(newStateTable, mbcsTable->stateTable, mbcsTable->countStates*1024);
/* copy and modify the from-Unicode result table */
newResults = reinterpret_cast<uint16_t*>(newStateTable[mbcsTable->countStates]);
uprv_memcpy(newResults, bytes, sizeofFromUBytes);
/* conveniently, the table access macros work on the left side of expressions */ if(mbcsTable->outputType==MBCS_OUTPUT_1) {
MBCS_SINGLE_RESULT_FROM_U(table, newResults, U_LF)=EBCDIC_RT_NL;
MBCS_SINGLE_RESULT_FROM_U(table, newResults, U_NL)=EBCDIC_RT_LF;
} else/* MBCS_OUTPUT_2_SISO */ {
stage2Entry=MBCS_STAGE_2_FROM_U(table, U_LF);
MBCS_VALUE_2_FROM_STAGE_2(newResults, stage2Entry, U_LF)=EBCDIC_NL;
/* set the canonical converter name */
name = reinterpret_cast<char*>(newResults) + sizeofFromUBytes;
uprv_strcpy(name, sharedData->staticData->name);
uprv_strcat(name, UCNV_SWAP_LFNL_OPTION_STRING);
/* set the pointers */
icu::umtx_lock(nullptr); if(mbcsTable->swapLFNLStateTable==nullptr) {
mbcsTable->swapLFNLStateTable=newStateTable;
mbcsTable->swapLFNLFromUnicodeBytes = reinterpret_cast<uint8_t*>(newResults);
mbcsTable->swapLFNLName=name;
/* for EUC outputTypes, modify the value like genmbcs.c's transformEUC() */ switch(mbcsTable->outputType) { case MBCS_OUTPUT_3_EUC: if(value<=0xffff) { /* short sequences are stored directly */ /* code set 0 or 1 */
} elseif(value<=0x8effff) { /* code set 2 */
value&=0x7fff;
} else/* first byte is 0x8f */ { /* code set 3 */
value&=0xff7f;
} break; case MBCS_OUTPUT_4_EUC: if(value<=0xffffff) { /* short sequences are stored directly */ /* code set 0 or 1 */
} elseif(value<=0x8effffff) { /* code set 2 */
value&=0x7fffff;
} else/* first byte is 0x8f */ { /* code set 3 */
value&=0xff7fff;
} break; default: break;
}
/* copy existing data and reroute the pointers */
stage1 = reinterpret_cast<uint16_t*>(mbcsTable->reconstitutedData);
uprv_memcpy(stage1, mbcsTable->fromUnicodeTable, stage1Length*2);
/* indexes into stage 2 count from the bottom of the fromUnicodeTable */
stage2 = reinterpret_cast<uint32_t*>(stage1);
/* reconstitute the initial part of stage 2 from the mbcsIndex */
{
int32_t stageUTF8Length = (static_cast<int32_t>(mbcsTable->maxFastUChar) + 1) >> 6;
int32_t stageUTF8Index=0;
int32_t st1, st2, st3, i;
for(st1=0; stageUTF8Index<stageUTF8Length; ++st1) {
st2=stage1[st1]; if (st2 != static_cast<int32_t>(stage1Length) / 2) { /* each stage 2 block has 64 entries corresponding to 16 entries in the mbcsIndex */ for(i=0; i<16; ++i) {
st3=mbcsTable->mbcsIndex[stageUTF8Index++]; if(st3!=0) { /* an stage 2 entry's index is per stage 3 16-block, not per stage 3 entry */
st3>>=4; /* * 4 stage 2 entries point to 4 consecutive stage 3 16-blocks which are * allocated together as a single 64-block for access from the mbcsIndex
*/
stage2[st2++]=st3++;
stage2[st2++]=st3++;
stage2[st2++]=st3++;
stage2[st2++]=st3;
} else { /* no stage 3 block, skip */
st2+=4;
}
}
} else { /* no stage 2 block, skip */
stageUTF8Index+=16;
}
}
}
/* reconstitute fromUnicodeBytes with roundtrips from toUnicode data */
ucnv_MBCSEnumToUnicode(mbcsTable, writeStage3Roundtrip, mbcsTable, pErrorCode);
}
/* extension-only file, load the base table and set values appropriately */ if((extIndexes=mbcsTable->extIndexes)==nullptr) { /* extension-only file without extension */
*pErrorCode=U_INVALID_TABLE_FORMAT; return;
}
if(pArgs->nestedLoads!=1) { /* an extension table must not be loaded as a base table */
*pErrorCode=U_INVALID_TABLE_FILE; return;
}
/* load the base table */
baseName = reinterpret_cast<constchar*>(header) + headerLength * 4; if(0==uprv_strcmp(baseName, sharedData->staticData->name)) { /* forbid loading this same extension-only file */
*pErrorCode=U_INVALID_TABLE_FORMAT; return;
}
/* TODO parse package name out of the prefix of the base name in the extension .cnv file? */
args.size=sizeof(UConverterLoadArgs);
args.nestedLoads=2;
args.onlyTestIsLoadable=pArgs->onlyTestIsLoadable;
args.reserved=pArgs->reserved;
args.options=pArgs->options;
args.pkg=pArgs->pkg;
args.name=baseName;
baseSharedData=ucnv_load(&args, pErrorCode); if(U_FAILURE(*pErrorCode)) { return;
} if( baseSharedData->staticData->conversionType!=UCNV_MBCS ||
baseSharedData->mbcs.baseSharedData!=nullptr
) {
ucnv_unload(baseSharedData);
*pErrorCode=U_INVALID_TABLE_FORMAT; return;
} if(pArgs->onlyTestIsLoadable) { /* * Exit as soon as we know that we can load the converter * and the format is valid and supported. * The worst that can happen in the following code is a memory * allocation error.
*/
ucnv_unload(baseSharedData); return;
}
/* copy the base table data */
uprv_memcpy(mbcsTable, &baseSharedData->mbcs, sizeof(UConverterMBCSTable));
/* overwrite values with relevant ones for the extension converter */
mbcsTable->baseSharedData=baseSharedData;
mbcsTable->extIndexes=extIndexes;
/* * It would be possible to share the swapLFNL data with a base converter, * but the generated name would have to be different, and the memory * would have to be free'd only once. * It is easier to just create the data for the extension converter * separately when it is requested.
*/
mbcsTable->swapLFNLStateTable=nullptr;
mbcsTable->swapLFNLFromUnicodeBytes=nullptr;
mbcsTable->swapLFNLName=nullptr;
/* * The reconstitutedData must be deleted only when the base converter * is unloaded.
*/
mbcsTable->reconstitutedData=nullptr;
/* * Set a special, runtime-only outputType if the extension converter * is a DBCS version of a base converter that also maps single bytes.
*/ if( sharedData->staticData->conversionType==UCNV_DBCS ||
(sharedData->staticData->conversionType==UCNV_MBCS &&
sharedData->staticData->minBytesPerChar>=2)
) { if(baseSharedData->mbcs.outputType==MBCS_OUTPUT_2_SISO) { /* the base converter is SI/SO-stateful */
int32_t entry;
/* get the dbcs state from the state table entry for SO=0x0e */
entry=mbcsTable->stateTable[0][0xe]; if( MBCS_ENTRY_IS_FINAL(entry) &&
MBCS_ENTRY_FINAL_ACTION(entry)==MBCS_STATE_CHANGE_ONLY &&
MBCS_ENTRY_FINAL_STATE(entry)!=0
) {
mbcsTable->dbcsOnlyState = static_cast<uint8_t>(MBCS_ENTRY_FINAL_STATE(entry));
mbcsTable->outputType=MBCS_OUTPUT_DBCS_ONLY;
}
} elseif(
baseSharedData->staticData->conversionType==UCNV_MBCS &&
baseSharedData->staticData->minBytesPerChar==1 &&
baseSharedData->staticData->maxBytesPerChar==2 &&
mbcsTable->countStates<=127
) { /* non-stateful base converter, need to modify the state table */
int32_t (*newStateTable)[256];
int32_t *state;
int32_t i, count;
/* allocate a new state table and copy the base state table contents */
count=mbcsTable->countStates;
newStateTable = static_cast<int32_t(*)[256]>(uprv_malloc((count + 1) * 1024)); if(newStateTable==nullptr) {
ucnv_unload(baseSharedData);
*pErrorCode=U_MEMORY_ALLOCATION_ERROR; return;
}
/* change all final single-byte entries to go to a new all-illegal state */
state=newStateTable[0]; for(i=0; i<256; ++i) { if(MBCS_ENTRY_IS_FINAL(state[i])) {
state[i]=MBCS_ENTRY_TRANSITION(count, 0);
}
--> --------------------
--> maximum size reached
--> --------------------
Messung V0.5
¤ 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.0.28Bemerkung:
Wie Sie bei der Firma Beratungs- und Dienstleistungen beauftragen können
¤
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.