static void createNormalizedAliasStrings(char *normalizedStrings, const char *origStringBlock, int32_t stringBlockLength) { int32_t currStrLen; uprv_memcpy(normalizedStrings, origStringBlock, stringBlockLength); while ((currStrLen = (int32_t)uprv_strlen(origStringBlock)) < stringBlockLength) { int32_t currStrSize = currStrLen + 1; if (currStrLen > 0) { int32_t normStrLen; ucnv_io_stripForCompare(normalizedStrings, origStringBlock); normStrLen = uprv_strlen(normalizedStrings); if (normStrLen > 0) { uprv_memset(normalizedStrings + normStrLen, 0, currStrSize - normStrLen); } } stringBlockLength -= currStrSize; normalizedStrings += currStrSize; origStringBlock += currStrSize; } }
/*returns a converter type from a string */ static const UConverterSharedData * getAlgorithmicTypeFromName(const char *realName) { uint32_t mid, start, limit; uint32_t lastMid; int result; char strippedName[UCNV_MAX_CONVERTER_NAME_LENGTH]; /* Lower case and remove ignoreable characters. */ ucnv_io_stripForCompare(strippedName, realName); /* do a binary search for the alias */ start = 0; limit = sizeof(cnvNameType)/sizeof(cnvNameType[0]); mid = limit; lastMid = UINT32_MAX; for (;;) { mid = (uint32_t)((start + limit) / 2); if (lastMid == mid) { /* Have we moved? */ break; /* We haven't moved, and it wasn't found. */ } lastMid = mid; result = uprv_strcmp(strippedName, cnvNameType[mid].name); if (result < 0) { limit = mid; } else if (result > 0) { start = mid; } else { return converterData[cnvNameType[mid].type]; } } return NULL; }
/* * search for an alias * return the converter number index for gConverterList */ static inline uint32_t findConverter(const char *alias, UBool *containsOption, UErrorCode *pErrorCode) { uint32_t mid, start, limit; uint32_t lastMid; int result; int isUnnormalized = (gMainTable.optionTable->stringNormalizationType == UCNV_IO_UNNORMALIZED); char strippedName[UCNV_MAX_CONVERTER_NAME_LENGTH]; 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 = (uint32_t)((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; } else if (result > 0) { start = mid; } else { /* Since the gencnval tool folds duplicates into one entry, * this alias in gAliasList is unique, but different standards * may map an alias to different converters. */ 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 = (UBool)gMainTable.optionTable->containsCnvOptionInfo; *containsOption = (UBool)((containsCnvOptionInfo && ((gMainTable.untaggedConvArray[mid] & UCNV_CONTAINS_OPTION_BIT) != 0)) || !containsCnvOptionInfo); } return gMainTable.untaggedConvArray[mid] & UCNV_CONVERTER_INDEX_MASK; } } return UINT32_MAX; }