void U_CALLCONV locale_available_init() { // This function is a friend of class Locale. // This function is only invoked via umtx_initOnce().
// for now, there is a hardcoded list, so just walk through that list and set it up. // Note: this function is a friend of class Locale.
availableLocaleListCount = uloc_countAvailable(); if(availableLocaleListCount) {
availableLocaleList = new Locale[availableLocaleListCount];
} if (availableLocaleList == nullptr) {
availableLocaleListCount= 0;
} for (int32_t locCount=availableLocaleListCount-1; locCount>=0; --locCount) {
availableLocaleList[locCount].setFromPOSIXID(uloc_getAvailable(locCount));
}
ucln_common_registerCleanup(UCLN_COMMON_LOCALE_AVAILABLE, locale_available_cleanup);
}
// Enough capacity for the two lists in the res_index.res file constchar** gAvailableLocaleNames[2] = {};
int32_t gAvailableLocaleCounts[2] = {};
icu::UInitOnce ginstalledLocalesInitOnce {};
class AvailableLocalesSink : public ResourceSink { public: void put(constchar *key, ResourceValue &value, UBool /*noFallback*/, UErrorCode &status) override { if (U_FAILURE(status)) { return; }
ResourceTable resIndexTable = value.getTable(status); if (U_FAILURE(status)) { return; } for (int32_t i = 0; resIndexTable.getKeyAndValue(i, key, value); ++i) {
ULocAvailableType type; if (uprv_strcmp(key, "InstalledLocales") == 0) {
type = ULOC_AVAILABLE_DEFAULT;
} elseif (uprv_strcmp(key, "AliasLocales") == 0) {
type = ULOC_AVAILABLE_ONLY_LEGACY_ALIASES;
} else { // CLDRVersion, etc. continue;
}
ResourceTable availableLocalesTable = value.getTable(status); if (U_FAILURE(status)) { return;
}
gAvailableLocaleCounts[type] = availableLocalesTable.getSize();
gAvailableLocaleNames[type] = static_cast<constchar**>(
uprv_malloc(gAvailableLocaleCounts[type] * sizeof(constchar*))); if (gAvailableLocaleNames[type] == nullptr) {
status = U_MEMORY_ALLOCATION_ERROR; return;
} for (int32_t j = 0; availableLocalesTable.getKeyAndValue(j, key, value); ++j) {
gAvailableLocaleNames[type][j] = key;
}
}
}
};
class AvailableLocalesStringEnumeration : public StringEnumeration { public:
AvailableLocalesStringEnumeration(ULocAvailableType type) : fType(type) {
}
// If the "combined" list was requested, resolve that now if (fType == ULOC_AVAILABLE_WITH_LEGACY_ALIASES) {
int32_t defaultLocalesCount = gAvailableLocaleCounts[ULOC_AVAILABLE_DEFAULT]; if (actualIndex < defaultLocalesCount) {
actualType = ULOC_AVAILABLE_DEFAULT;
} else {
actualIndex -= defaultLocalesCount;
actualType = ULOC_AVAILABLE_ONLY_LEGACY_ALIASES;
}
}
// Return the requested string
int32_t count = gAvailableLocaleCounts[actualType]; constchar* result; if (actualIndex < count) {
result = gAvailableLocaleNames[actualType][actualIndex]; if (resultLength != nullptr) {
*resultLength = static_cast<int32_t>(uprv_strlen(result));
}
} else {
result = nullptr; if (resultLength != nullptr) {
*resultLength = 0;
}
} return result;
}
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.