enum {
tocLengthIndex=0,
converterListIndex=1,
tagListIndex=2,
aliasListIndex=3,
untaggedConvArrayIndex=4,
taggedAliasArrayIndex=5,
taggedAliasListsIndex=6,
tableOptionsIndex=7,
stringTableIndex=8,
normalizedStringTableIndex=9,
offsetsCount, /* length of the swapper's temporary offsets[] */
minTocLength=8/* min. tocLength in the file, does not count the tocLengthIndex! */
};
U_ASSERT(gAliasData == nullptr);
data = udata_openChoice(nullptr, DATA_TYPE, DATA_NAME, isAcceptable, nullptr, &errCode); if (U_FAILURE(errCode)) { return;
}
sectionSizes = static_cast<const uint32_t*>(udata_getMemory(data));
int32_t dataLength = udata_getLength(data); // This is the length minus the UDataInfo size if (dataLength <= int32_t(sizeof(sectionSizes[0]))) { // We don't even have a TOC! goto invalidFormat;
}
table = reinterpret_cast<const uint16_t*>(sectionSizes);
tableStart = sectionSizes[0];
sizeOfTOC = int32_t((tableStart + 1) * sizeof(sectionSizes[0])); if (tableStart < minTocLength || dataLength <= sizeOfTOC) { // We don't have a whole TOC! goto invalidFormat;
}
gAliasData = data;
if (tableStart > minTocLength) {
gMainTable.normalizedStringTableSize = sectionSizes[9];
}
sizeOfData = sizeOfTOC; for (uint32_t section = 1; section <= tableStart; section++) {
sizeOfData += sectionSizes[section] * sizeof(table[0]);
} if (dataLength < sizeOfData) { // Truncated file! goto invalidFormat;
} // There may be some extra padding at the end, or this is a new file format with extra data that we can't read yet.
/* aliasLists is a 1's based array, but it has a padding character */
currOffset += gMainTable.taggedAliasArraySize;
gMainTable.taggedAliasLists = table + currOffset;
currOffset += gMainTable.taggedAliasListsSize; if (gMainTable.optionTableSize > 0
&& reinterpret_cast<const UConverterAliasOptions*>(table + currOffset)->stringNormalizationType < UCNV_IO_NORM_TYPE_COUNT)
{ /* Faster table */
gMainTable.optionTable = reinterpret_cast<const UConverterAliasOptions*>(table + currOffset);
} else { /* Smaller table, or I can't handle this normalization mode!
Use the original slower table lookup. */
gMainTable.optionTable = &defaultTableOptions;
}
static uint32_t getTagNumber(constchar *tagname) { if (gMainTable.tagList) {
uint32_t tagNum; for (tagNum = 0; tagNum < gMainTable.tagListSize; tagNum++) { if (!uprv_stricmp(GET_STRING(gMainTable.tagList[tagNum]), tagname)) { return tagNum;
}
}
}
return UINT32_MAX;
}
/* character types relevant for ucnv_compareNames() */ enum {
UIGNORE,
ZERO,
NONZERO,
MINLETTER /* any values from here on are lowercase letter mappings */
};
for (;;) { while ((c1 = *name1++) != 0) {
type = GET_CHAR_TYPE(c1); switch (type) { case UIGNORE:
afterDigit1 = false; continue; /* ignore all but letters and digits */ case ZERO: if (!afterDigit1) {
nextType = GET_CHAR_TYPE(*name1); if (nextType == ZERO || nextType == NONZERO) { continue; /* ignore leading zero before another digit */
}
} break; case NONZERO:
afterDigit1 = true; break; default:
c1 = (char)type; /* lowercased letter */
afterDigit1 = false; break;
} break; /* deliver c1 */
} while ((c2 = *name2++) != 0) {
type = GET_CHAR_TYPE(c2); switch (type) { case UIGNORE:
afterDigit2 = false; continue; /* ignore all but letters and digits */ case ZERO: if (!afterDigit2) {
nextType = GET_CHAR_TYPE(*name2); if (nextType == ZERO || nextType == NONZERO) { continue; /* ignore leading zero before another digit */
}
} break; case NONZERO:
afterDigit2 = true; break; default:
c2 = (char)type; /* lowercased letter */
afterDigit2 = false; break;
} break; /* deliver c2 */
}
/* If we reach the ends of both strings then they match */ if ((c1|c2)==0) { return0;
}
if (!isUnnormalized) { if (uprv_strlen(alias) >= UCNV_MAX_CONVERTER_NAME_LENGTH) {
*pErrorCode = U_BUFFER_OVERFLOW_ERROR; return UINT32_MAX;
}
/* Lower case and remove ignoreable characters. */
ucnv_io_stripForCompare(strippedName, alias);
alias = strippedName;
}
/* do a binary search for the alias */
start = 0;
limit = gMainTable.untaggedConvArraySize;
mid = limit;
lastMid = UINT32_MAX;
for (;;) {
mid = (start + limit) / 2; if (lastMid == mid) { /* Have we moved? */ break; /* We haven't moved, and it wasn't found. */
}
lastMid = mid; if (isUnnormalized) {
result = ucnv_compareNames(alias, GET_STRING(gMainTable.aliasList[mid]));
} else {
result = uprv_strcmp(alias, GET_NORMALIZED_STRING(gMainTable.aliasList[mid]));
}
if (result < 0) {
limit = mid;
} elseif (result > 0) {
start = mid;
} else { /* Since the gencnval tool folds duplicates into one entry, *thisaliasingAliasListisunique,butdifferentstandards *maymapanaliastodifferentconverters.
*/ if (gMainTable.untaggedConvArray[mid] & UCNV_AMBIGUOUS_ALIAS_MAP_BIT) {
*pErrorCode = U_AMBIGUOUS_ALIAS_WARNING;
} /* State whether the canonical converter name contains an option.
This information is contained in this list in order to maintain backward & forward compatibility. */ if (containsOption) {
UBool containsCnvOptionInfo = static_cast<UBool>(gMainTable.optionTable->containsCnvOptionInfo);
*containsOption = static_cast<UBool>((containsCnvOptionInfo
&& ((gMainTable.untaggedConvArray[mid] & UCNV_CONTAINS_OPTION_BIT) != 0))
|| !containsCnvOptionInfo);
} return gMainTable.untaggedConvArray[mid] & UCNV_CONVERTER_INDEX_MASK;
}
}
/* Make a quick guess. Hopefully they used a TR22 canonical alias. */
convNum = findConverter(alias, nullptr, &myErr); if (myErr != U_ZERO_ERROR) {
*pErrorCode = myErr;
}
if (tagNum < (gMainTable.tagListSize - UCNV_NUM_HIDDEN_TAGS) && convNum < gMainTable.converterListSize) {
listOffset = gMainTable.taggedAliasArray[tagNum*gMainTable.converterListSize + convNum]; if (listOffset && gMainTable.taggedAliasLists[listOffset + 1]) { return listOffset;
} if (myErr == U_AMBIGUOUS_ALIAS_WARNING) { /* Uh Oh! They used an ambiguous alias. Wehavetosearchthewholeswisscheesestarting atthehigheststandardaffinity. Thismaytakeawhile.
*/ for (idx = 0; idx < gMainTable.taggedAliasArraySize; idx++) {
listOffset = gMainTable.taggedAliasArray[idx]; if (listOffset && isAliasInList(alias, listOffset)) {
uint32_t currTagNum = idx/gMainTable.converterListSize;
uint32_t currConvNum = (idx - currTagNum*gMainTable.converterListSize);
uint32_t tempListOffset = gMainTable.taggedAliasArray[tagNum*gMainTable.converterListSize + currConvNum]; if (tempListOffset && gMainTable.taggedAliasLists[tempListOffset + 1]) { return tempListOffset;
} /* else keep on looking */ /* We could speed this up by starting on the next row becauseanaliasisuniqueperrow,rightnow.
This would change if alias versioning appears. */
}
} /* The standard doesn't know about the alias */
} /* else no default name */ return0;
} /* else converter or tag not found */
/* Make a quick guess. Hopefully they used a TR22 canonical alias. */
convNum = findConverter(alias, nullptr, &myErr); if (myErr != U_ZERO_ERROR) {
*pErrorCode = myErr;
}
if (tagNum < (gMainTable.tagListSize - UCNV_NUM_HIDDEN_TAGS) && convNum < gMainTable.converterListSize) {
listOffset = gMainTable.taggedAliasArray[tagNum*gMainTable.converterListSize + convNum]; if (listOffset && isAliasInList(alias, listOffset)) { return convNum;
} if (myErr == U_AMBIGUOUS_ALIAS_WARNING) { /* Uh Oh! They used an ambiguous alias. Wehavetosearchonesliceoftheswisscheese. Wesearchonlyintherequestedtag,notthewholething. Thismaytakeawhile.
*/
uint32_t convStart = (tagNum)*gMainTable.converterListSize;
uint32_t convLimit = (tagNum+1)*gMainTable.converterListSize; for (idx = convStart; idx < convLimit; idx++) {
listOffset = gMainTable.taggedAliasArray[idx]; if (listOffset && isAliasInList(alias, listOffset)) { return idx-convStart;
}
} /* The standard doesn't know about the alias */
} /* else no canonical name */
} /* else converter or tag not found */
return UINT32_MAX;
}
U_CAPI constchar *
ucnv_io_getConverterName(constchar *alias, UBool *containsOption, UErrorCode *pErrorCode) { constchar *aliasTmp = alias;
int32_t i = 0; for (i = 0; i < 2; i++) { if (i == 1) { /* *Afterthefirstunsuccessconverterlookup,checktoseeif *thenamebeginswith'x-'.Ifitdoes,stripitoffandtry *again.ThisbehaviourissimilartohowICU4Jdoesit.
*/ if (aliasTmp[0] == 'x' && aliasTmp[1] == '-') {
aliasTmp = aliasTmp+2;
} else { break;
}
} if(haveAliasData(pErrorCode) && isAlias(aliasTmp, pErrorCode)) {
uint32_t convNum = findConverter(aliasTmp, containsOption, pErrorCode); if (convNum < gMainTable.converterListSize) { return GET_STRING(gMainTable.converterList[convNum]);
} /* else converter not found */
} else { break;
}
}
if (myContext->listIdx < listCount) { constchar *myStr = GET_STRING(currList[myContext->listIdx++]); if (resultLength) {
*resultLength = (int32_t)uprv_strlen(myStr);
} return myStr;
}
} /* Either we accessed a zero length list, or we enumerated too far. */ if (resultLength) {
*resultLength = 0;
} return nullptr;
}
/* Enumerate the aliases for the specified converter and standard tag */ staticconst UEnumeration gEnumAliases = {
nullptr,
nullptr,
ucnv_io_closeUEnumeration,
ucnv_io_countStandardAliases,
uenum_unextDefault,
ucnv_io_nextStandardAliases,
ucnv_io_resetStandardAliases
};
/* When listOffset == 0, we want to acknowledge that the converternameandstandardareokay,butthere
is nothing to enumerate. */ if (listOffset < gMainTable.taggedAliasListsSize) {
UAliasContext *myContext;
myEnum = static_cast<UEnumeration *>(uprv_malloc(sizeof(UEnumeration))); if (myEnum == nullptr) {
*pErrorCode = U_MEMORY_ALLOCATION_ERROR; return nullptr;
}
uprv_memcpy(myEnum, &gEnumAliases, sizeof(UEnumeration));
myContext = static_cast<UAliasContext *>(uprv_malloc(sizeof(UAliasContext))); if (myContext == nullptr) {
*pErrorCode = U_MEMORY_ALLOCATION_ERROR;
uprv_free(myEnum); return nullptr;
}
myContext->listOffset = listOffset;
myContext->listIdx = 0;
myEnum->context = myContext;
} /* else converter or tag not found */
} return myEnum;
}
static uint16_t
ucnv_io_countAliases(constchar *alias, UErrorCode *pErrorCode) { if(haveAliasData(pErrorCode) && isAlias(alias, pErrorCode)) {
uint32_t convNum = findConverter(alias, nullptr, pErrorCode); if (convNum < gMainTable.converterListSize) { /* tagListNum - 1 is the ALL tag */
int32_t listOffset = gMainTable.taggedAliasArray[(gMainTable.tagListSize - 1)*gMainTable.converterListSize + convNum];
if (listOffset) { return gMainTable.taggedAliasLists[listOffset];
} /* else this shouldn't happen. internal program error */
} /* else converter not found */
} return0;
}
static uint16_t
ucnv_io_getAliases(constchar *alias, uint16_t start, constchar **aliases, UErrorCode *pErrorCode) { if(haveAliasData(pErrorCode) && isAlias(alias, pErrorCode)) {
uint32_t currAlias;
uint32_t convNum = findConverter(alias, nullptr, pErrorCode); if (convNum < gMainTable.converterListSize) { /* tagListNum - 1 is the ALL tag */
int32_t listOffset = gMainTable.taggedAliasArray[(gMainTable.tagListSize - 1)*gMainTable.converterListSize + convNum];
if (n < listCount) { return GET_STRING(currList[n]);
}
*pErrorCode = U_INDEX_OUTOFBOUNDS_ERROR;
} /* else this shouldn't happen. internal program error */
} /* else converter not found */
} return nullptr;
}
static uint16_t
ucnv_io_countStandards(UErrorCode *pErrorCode) { if (haveAliasData(pErrorCode)) { /* Don't include the empty list */ return static_cast<uint16_t>(gMainTable.tagListSize - UCNV_NUM_HIDDEN_TAGS);
}
return0;
}
U_CAPI constchar * U_EXPORT2
ucnv_getStandard(uint16_t n, UErrorCode *pErrorCode) { if (haveAliasData(pErrorCode)) { if (n < gMainTable.tagListSize - UCNV_NUM_HIDDEN_TAGS) { return GET_STRING(gMainTable.tagList[n]);
}
*pErrorCode = U_INDEX_OUTOFBOUNDS_ERROR;
}
/* Get the preferred name from this list */ if (currList[0]) { return GET_STRING(currList[0]);
} /* else someone screwed up the alias table. */ /* *pErrorCode = U_INVALID_FORMAT_ERROR */
}
}
if (*myContext < gMainTable.converterListSize) { constchar *myStr = GET_STRING(gMainTable.converterList[(*myContext)++]); if (resultLength) {
*resultLength = (int32_t)uprv_strlen(myStr);
} return myStr;
} /* Either we accessed a zero length list, or we enumerated too far. */ if (resultLength) {
*resultLength = 0;
} return nullptr;
}
/* check data format and format version */
pInfo=(const UDataInfo *)((constchar *)inData+4); if(!(
pInfo->dataFormat[0]==0x43 && /* dataFormat="CvAl" */
pInfo->dataFormat[1]==0x76 &&
pInfo->dataFormat[2]==0x41 &&
pInfo->dataFormat[3]==0x6c &&
pInfo->formatVersion[0]==3
)) {
udata_printError(ds, "ucnv_swapAliases(): data format %02x.%02x.%02x.%02x (format version %02x) is not an alias table\n",
pInfo->dataFormat[0], pInfo->dataFormat[1],
pInfo->dataFormat[2], pInfo->dataFormat[3],
pInfo->formatVersion[0]);
*pErrorCode=U_UNSUPPORTED_ERROR; return0;
}
/* an alias table must contain at least the table of contents array */ if(length>=0 && (length-headerSize)<4*(1+minTocLength)) {
udata_printError(ds, "ucnv_swapAliases(): too few bytes (%d after header) for an alias table\n",
length-headerSize);
*pErrorCode=U_INDEX_OUTOFBOUNDS_ERROR; return0;
}
if((length-headerSize)<(2*(int32_t)topOffset)) {
udata_printError(ds, "ucnv_swapAliases(): too few bytes (%d after header) for an alias table\n",
length-headerSize);
*pErrorCode=U_INDEX_OUTOFBOUNDS_ERROR; return0;
}
if(ds->inCharset==ds->outCharset) { /* no need to sort, just swap all 16-bit values together */
ds->swapArray16(ds,
inTable+offsets[converterListIndex], 2*(int32_t)(offsets[stringTableIndex]-offsets[converterListIndex]),
outTable+offsets[converterListIndex],
pErrorCode);
} else { /* allocate the temporary table for sorting */
count=toc[aliasListIndex];
tempTable.chars=(constchar *)(outTable+offsets[stringTableIndex]); /* sort by outCharset */
¤ Diese beiden folgenden Angebotsgruppen bietet das Unternehmen0.39Angebot
(Wie Sie bei der Firma Beratungs- und Dienstleistungen beauftragen können 2026-08-26)
¤
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.