icu4c/source/allinone/icucheck.bat -text
icu4c/source/common/common.vcxproj -text
icu4c/source/common/common.vcxproj.filters -text
-icu4c/source/common/uloc_keytype.cpp -text
-icu4c/source/common/unifiedcache.cpp -text
-icu4c/source/common/unifiedcache.h -text
-icu4c/source/data/brkitr/burmesedict.txt -text
-icu4c/source/data/coll/dsb.txt -text
-icu4c/source/data/coll/hsb.txt -text
-icu4c/source/data/coll/lb.txt -text
-icu4c/source/data/coll/se.txt -text
-icu4c/source/data/coll/smn.txt -text
-icu4c/source/data/coll/wae.txt -text
-icu4c/source/data/coll/yi.txt -text
-icu4c/source/data/curr/ar_AE.txt -text
-icu4c/source/data/curr/bm_Latn.txt -text
-icu4c/source/data/curr/dsb.txt -text
-icu4c/source/data/curr/en_MY.txt -text
-icu4c/source/data/curr/es_419.txt -text
-icu4c/source/data/curr/es_GQ.txt -text
-icu4c/source/data/curr/ff_GN.txt -text
-icu4c/source/data/curr/ff_MR.txt -text
-icu4c/source/data/curr/fur.txt -text
-icu4c/source/data/curr/fy.txt -text
-icu4c/source/data/curr/gd.txt -text
-icu4c/source/data/curr/hsb.txt -text
-icu4c/source/data/curr/ksh.txt -text
-icu4c/source/data/curr/lb.txt -text
-icu4c/source/data/curr/os.txt -text
-icu4c/source/data/curr/os_RU.txt -text
icu4c/source/data/curr/pool.res -text
-icu4c/source/data/curr/qu.txt -text
-icu4c/source/data/curr/qu_BO.txt -text
-icu4c/source/data/curr/qu_EC.txt -text
-icu4c/source/data/curr/sah.txt -text
-icu4c/source/data/curr/se.txt -text
-icu4c/source/data/curr/se_SE.txt -text
-icu4c/source/data/curr/smn.txt -text
-icu4c/source/data/curr/ur_IN.txt -text
-icu4c/source/data/curr/wae.txt -text
-icu4c/source/data/curr/yi.txt -text
icu4c/source/data/in/coll/ucadata-implicithan.icu -text
icu4c/source/data/in/coll/ucadata-unihan.icu -text
icu4c/source/data/in/nfc.nrm -text
icu4c/source/data/in/unames.icu -text
icu4c/source/data/in/uprops.icu -text
icu4c/source/data/in/uts46.nrm -text
-icu4c/source/data/lang/ar_AE.txt -text
-icu4c/source/data/lang/bm_Latn.txt -text
-icu4c/source/data/lang/dsb.txt -text
-icu4c/source/data/lang/en_MY.txt -text
-icu4c/source/data/lang/fur.txt -text
-icu4c/source/data/lang/fy.txt -text
-icu4c/source/data/lang/gd.txt -text
-icu4c/source/data/lang/hsb.txt -text
-icu4c/source/data/lang/ksh.txt -text
-icu4c/source/data/lang/lb.txt -text
-icu4c/source/data/lang/ne_IN.txt -text
-icu4c/source/data/lang/os.txt -text
icu4c/source/data/lang/pool.res -text
-icu4c/source/data/lang/qu.txt -text
-icu4c/source/data/lang/sah.txt -text
-icu4c/source/data/lang/se.txt -text
-icu4c/source/data/lang/se_FI.txt -text
-icu4c/source/data/lang/smn.txt -text
-icu4c/source/data/lang/ur_IN.txt -text
-icu4c/source/data/lang/wae.txt -text
-icu4c/source/data/lang/yi.txt -text
-icu4c/source/data/locales/bm_Latn.txt -text
-icu4c/source/data/locales/bm_Latn_ML.txt -text
-icu4c/source/data/locales/dsb.txt -text
-icu4c/source/data/locales/dsb_DE.txt -text
-icu4c/source/data/locales/en_MY.txt -text
-icu4c/source/data/locales/ff_CM.txt -text
-icu4c/source/data/locales/ff_GN.txt -text
-icu4c/source/data/locales/ff_MR.txt -text
-icu4c/source/data/locales/fur.txt -text
-icu4c/source/data/locales/fur_IT.txt -text
-icu4c/source/data/locales/fy.txt -text
-icu4c/source/data/locales/fy_NL.txt -text
-icu4c/source/data/locales/gd.txt -text
-icu4c/source/data/locales/gd_GB.txt -text
-icu4c/source/data/locales/gsw_FR.txt -text
-icu4c/source/data/locales/hsb.txt -text
-icu4c/source/data/locales/hsb_DE.txt -text
-icu4c/source/data/locales/ksh.txt -text
-icu4c/source/data/locales/ksh_DE.txt -text
-icu4c/source/data/locales/lb.txt -text
-icu4c/source/data/locales/lb_LU.txt -text
-icu4c/source/data/locales/os.txt -text
-icu4c/source/data/locales/os_GE.txt -text
-icu4c/source/data/locales/os_RU.txt -text
icu4c/source/data/locales/pool.res -text
-icu4c/source/data/locales/qu.txt -text
-icu4c/source/data/locales/qu_BO.txt -text
-icu4c/source/data/locales/qu_EC.txt -text
-icu4c/source/data/locales/qu_PE.txt -text
-icu4c/source/data/locales/sah.txt -text
-icu4c/source/data/locales/sah_RU.txt -text
-icu4c/source/data/locales/se.txt -text
-icu4c/source/data/locales/se_FI.txt -text
-icu4c/source/data/locales/se_NO.txt -text
-icu4c/source/data/locales/se_SE.txt -text
-icu4c/source/data/locales/smn.txt -text
-icu4c/source/data/locales/smn_FI.txt -text
-icu4c/source/data/locales/wae.txt -text
-icu4c/source/data/locales/wae_CH.txt -text
-icu4c/source/data/locales/yi.txt -text
-icu4c/source/data/locales/yi_001.txt -text
icu4c/source/data/makedata.vcxproj -text
icu4c/source/data/makedata.vcxproj.filters -text
-icu4c/source/data/rbnf/se.txt -text
-icu4c/source/data/region/ar_AE.txt -text
-icu4c/source/data/region/bm_Latn.txt -text
-icu4c/source/data/region/dsb.txt -text
-icu4c/source/data/region/en_MY.txt -text
-icu4c/source/data/region/es_419.txt -text
-icu4c/source/data/region/fur.txt -text
-icu4c/source/data/region/fy.txt -text
-icu4c/source/data/region/gd.txt -text
-icu4c/source/data/region/hsb.txt -text
-icu4c/source/data/region/ksh.txt -text
-icu4c/source/data/region/lb.txt -text
-icu4c/source/data/region/os.txt -text
icu4c/source/data/region/pool.res -text
-icu4c/source/data/region/qu.txt -text
-icu4c/source/data/region/sah.txt -text
-icu4c/source/data/region/se.txt -text
-icu4c/source/data/region/se_FI.txt -text
-icu4c/source/data/region/smn.txt -text
-icu4c/source/data/region/ur_IN.txt -text
-icu4c/source/data/region/wae.txt -text
-icu4c/source/data/region/yi.txt -text
-icu4c/source/data/xml/collation/dsb.xml -text
-icu4c/source/data/xml/collation/hsb.xml -text
-icu4c/source/data/xml/collation/lb.xml -text
-icu4c/source/data/xml/collation/se.xml -text
-icu4c/source/data/xml/collation/smn.xml -text
-icu4c/source/data/xml/collation/wae.xml -text
-icu4c/source/data/xml/collation/yi.xml -text
-icu4c/source/data/xml/main/dsb.xml -text
-icu4c/source/data/xml/main/fur.xml -text
-icu4c/source/data/xml/main/fy.xml -text
-icu4c/source/data/xml/main/gd.xml -text
-icu4c/source/data/xml/main/hsb.xml -text
-icu4c/source/data/xml/main/ksh.xml -text
-icu4c/source/data/xml/main/lb.xml -text
-icu4c/source/data/xml/main/os.xml -text
-icu4c/source/data/xml/main/qu.xml -text
-icu4c/source/data/xml/main/sah.xml -text
-icu4c/source/data/xml/main/se.xml -text
-icu4c/source/data/xml/main/smn.xml -text
-icu4c/source/data/xml/main/wae.xml -text
-icu4c/source/data/xml/main/yi.xml -text
-icu4c/source/data/zone/ar_AE.txt -text
-icu4c/source/data/zone/bm_Latn.txt -text
-icu4c/source/data/zone/dsb.txt -text
-icu4c/source/data/zone/en_MY.txt -text
-icu4c/source/data/zone/fur.txt -text
-icu4c/source/data/zone/fy.txt -text
-icu4c/source/data/zone/gd.txt -text
-icu4c/source/data/zone/hsb.txt -text
-icu4c/source/data/zone/ksh.txt -text
-icu4c/source/data/zone/lb.txt -text
-icu4c/source/data/zone/os.txt -text
icu4c/source/data/zone/pool.res -text
-icu4c/source/data/zone/qu.txt -text
-icu4c/source/data/zone/sah.txt -text
-icu4c/source/data/zone/se.txt -text
-icu4c/source/data/zone/smn.txt -text
-icu4c/source/data/zone/tzdbNames.txt -text
-icu4c/source/data/zone/wae.txt -text
-icu4c/source/data/zone/yi.txt -text
icu4c/source/extra/uconv/uconv.vcxproj -text
icu4c/source/extra/uconv/uconv.vcxproj.filters -text
icu4c/source/i18n/i18n.vcxproj -text
icu4c/source/test/depstest/icu-dependencies-mode.el -text
icu4c/source/test/intltest/intltest.vcxproj -text
icu4c/source/test/intltest/intltest.vcxproj.filters -text
-icu4c/source/test/intltest/numfmtspectest.cpp -text
-icu4c/source/test/intltest/unifiedcachetest.cpp -text
icu4c/source/test/iotest/iotest.vcxproj -text
icu4c/source/test/iotest/iotest.vcxproj.filters -text
icu4c/source/test/letest/cletest.vcxproj -text
icu4c/source/test/testdata/TestFont1.otf -text
icu4c/source/test/testdata/importtest.bin -text
icu4c/source/test/testdata/iscii.bin -text
-icu4c/source/test/testdata/metaZones.txt -text
icu4c/source/test/testdata/old_e_testtypes.res -text
icu4c/source/test/testdata/old_l_testtypes.res -text
-icu4c/source/test/testdata/timezoneTypes.txt -text
icu4c/source/test/testdata/uni-text.bin -text
-icu4c/source/test/testdata/windowsZones.txt -text
-icu4c/source/test/testdata/zoneinfo64.txt -text
icu4c/source/tools/ctestfw/ctestfw.vcxproj -text
icu4c/source/tools/ctestfw/ctestfw.vcxproj.filters -text
icu4c/source/tools/genbrk/genbrk.vcxproj -text
-/*\r
-**********************************************************************\r
-* Copyright (C) 2014, International Business Machines\r
-* Corporation and others. All Rights Reserved.\r
-**********************************************************************\r
-*/\r
-#include "unicode/utypes.h"\r
-\r
-#include "cstring.h"\r
-#include "uassert.h"\r
-#include "ucln_cmn.h"\r
-#include "uhash.h"\r
-#include "umutex.h"\r
-#include "uresimp.h"\r
-#include "uvector.h"\r
-\r
-static UHashtable* gLocExtKeyMap = NULL;\r
-static icu::UInitOnce gLocExtKeyMapInitOnce = U_INITONCE_INITIALIZER;\r
-static icu::UVector* gKeyTypeStringPool = NULL;\r
-static icu::UVector* gLocExtKeyDataEntries = NULL;\r
-static icu::UVector* gLocExtTypeEntries = NULL;\r
-\r
-// bit flags for special types\r
-typedef enum {\r
- SPECIALTYPE_NONE = 0,\r
- SPECIALTYPE_CODEPOINTS = 1,\r
- SPECIALTYPE_REORDER_CODE = 2\r
-} SpecialType;\r
-\r
-typedef struct LocExtKeyData {\r
- const char* legacyId;\r
- const char* bcpId;\r
- UHashtable* typeMap;\r
- uint32_t specialTypes;\r
-} LocExtKeyData;\r
-\r
-typedef struct LocExtType {\r
- const char* legacyId;\r
- const char* bcpId;\r
-} LocExtType;\r
-\r
-U_CDECL_BEGIN\r
-\r
-static UBool U_CALLCONV\r
-uloc_key_type_cleanup(void) {\r
- if (gLocExtKeyMap != NULL) {\r
- uhash_close(gLocExtKeyMap);\r
- gLocExtKeyMap = NULL;\r
- }\r
-\r
- delete gLocExtKeyDataEntries;\r
- gLocExtKeyDataEntries = NULL;\r
-\r
- delete gLocExtTypeEntries;\r
- gLocExtTypeEntries = NULL;\r
-\r
- delete gKeyTypeStringPool;\r
- gKeyTypeStringPool = NULL;\r
-\r
- gLocExtKeyMapInitOnce.reset();\r
- return TRUE;\r
-}\r
-\r
-static void U_CALLCONV\r
-uloc_deleteKeyTypeStringPoolEntry(void* obj) {\r
- uprv_free(obj);\r
-}\r
-\r
-static void U_CALLCONV\r
-uloc_deleteKeyDataEntry(void* obj) {\r
- LocExtKeyData* keyData = (LocExtKeyData*)obj;\r
- if (keyData->typeMap != NULL) {\r
- uhash_close(keyData->typeMap);\r
- }\r
- uprv_free(keyData);\r
-}\r
-\r
-static void U_CALLCONV\r
-uloc_deleteTypeEntry(void* obj) {\r
- uprv_free(obj);\r
-}\r
-\r
-U_CDECL_END\r
-\r
-\r
-static void U_CALLCONV\r
-initFromResourceBundle(UErrorCode& sts) {\r
- ucln_common_registerCleanup(UCLN_COMMON_LOCALE_KEY_TYPE, uloc_key_type_cleanup);\r
-\r
- gLocExtKeyMap = uhash_open(uhash_hashIChars, uhash_compareIChars, NULL, &sts);\r
- if (U_FAILURE(sts)) {\r
- return;\r
- }\r
-\r
- UResourceBundle *keyTypeDataRes = NULL;\r
- UResourceBundle *keyMapRes = NULL;\r
- UResourceBundle *typeMapRes = NULL;\r
- UResourceBundle *typeAliasRes = NULL;\r
- UResourceBundle *bcpTypeAliasRes = NULL;\r
-\r
- keyTypeDataRes = ures_openDirect(NULL, "keyTypeData", &sts);\r
- keyMapRes = ures_getByKey(keyTypeDataRes, "keyMap", NULL, &sts);\r
- typeMapRes = ures_getByKey(keyTypeDataRes, "typeMap", NULL, &sts);\r
-\r
- UErrorCode tmpSts = U_ZERO_ERROR;\r
- typeAliasRes = ures_getByKey(keyTypeDataRes, "typeAlias", NULL, &tmpSts);\r
- if (U_FAILURE(tmpSts)) {\r
- typeAliasRes = NULL;\r
- tmpSts = U_ZERO_ERROR;\r
- }\r
- bcpTypeAliasRes = ures_getByKey(keyTypeDataRes, "bcpTypeAlias", NULL, &tmpSts);\r
- if (U_FAILURE(tmpSts)) {\r
- bcpTypeAliasRes = NULL;\r
- tmpSts = U_ZERO_ERROR;\r
- }\r
-\r
- // initialize vectors storing dynamically allocated objects\r
- gKeyTypeStringPool = new icu::UVector(uloc_deleteKeyTypeStringPoolEntry, NULL, sts);\r
- if (gKeyTypeStringPool == NULL || U_FAILURE(sts)) {\r
- goto close_bundles;\r
- }\r
- gLocExtKeyDataEntries = new icu::UVector(uloc_deleteKeyDataEntry, NULL, sts);\r
- if (gLocExtKeyDataEntries == NULL || U_FAILURE(sts)) {\r
- goto close_bundles;\r
- }\r
- gLocExtTypeEntries = new icu::UVector(uloc_deleteTypeEntry, NULL, sts);\r
- if (gLocExtTypeEntries == NULL || U_FAILURE(sts)) {\r
- goto close_bundles;\r
- }\r
-\r
- // iterate through keyMap resource\r
- UResourceBundle keyMapEntry;\r
- ures_initStackObject(&keyMapEntry);\r
-\r
- while (ures_hasNext(keyMapRes)) {\r
- ures_getNextResource(keyMapRes, &keyMapEntry, &sts);\r
- if (U_FAILURE(sts)) {\r
- break;\r
- }\r
- const char* legacyKeyId = ures_getKey(&keyMapEntry);\r
- int32_t bcpKeyIdLen = 0;\r
- const UChar* uBcpKeyId = ures_getString(&keyMapEntry, &bcpKeyIdLen, &sts);\r
- if (U_FAILURE(sts)) {\r
- break;\r
- }\r
-\r
- // empty value indicates that BCP key is same with the legacy key.\r
- const char* bcpKeyId = legacyKeyId;\r
- if (bcpKeyIdLen > 0) {\r
- char* bcpKeyIdBuf = (char*)uprv_malloc(bcpKeyIdLen + 1);\r
- if (bcpKeyIdBuf == NULL) {\r
- sts = U_MEMORY_ALLOCATION_ERROR;\r
- break;\r
- }\r
- u_UCharsToChars(uBcpKeyId, bcpKeyIdBuf, bcpKeyIdLen);\r
- bcpKeyIdBuf[bcpKeyIdLen] = 0;\r
- gKeyTypeStringPool->addElement(bcpKeyIdBuf, sts);\r
- if (U_FAILURE(sts)) {\r
- break;\r
- }\r
- bcpKeyId = bcpKeyIdBuf;\r
- }\r
-\r
- UBool isTZ = uprv_strcmp(legacyKeyId, "timezone") == 0;\r
-\r
- UHashtable* typeDataMap = uhash_open(uhash_hashIChars, uhash_compareIChars, NULL, &sts);\r
- if (U_FAILURE(sts)) {\r
- break;\r
- }\r
- uint32_t specialTypes = SPECIALTYPE_NONE;\r
-\r
- UResourceBundle* typeAliasResByKey = NULL;\r
- UResourceBundle* bcpTypeAliasResByKey = NULL;\r
-\r
- if (typeAliasRes != NULL) {\r
- typeAliasResByKey = ures_getByKey(typeAliasRes, legacyKeyId, NULL, &tmpSts);\r
- if (U_FAILURE(tmpSts)) {\r
- // only a few keys have type alias mapping\r
- typeAliasResByKey = NULL;\r
- tmpSts = U_ZERO_ERROR;\r
- }\r
- }\r
- if (bcpTypeAliasRes != NULL) {\r
- bcpTypeAliasResByKey = ures_getByKey(bcpTypeAliasRes, bcpKeyId, NULL, &tmpSts);\r
- if (U_FAILURE(tmpSts)) {\r
- // only a few keys have BCP type alias mapping\r
- bcpTypeAliasResByKey = NULL;\r
- tmpSts = U_ZERO_ERROR;\r
- }\r
- }\r
-\r
- // look up type map for the key, and walk through the mapping data\r
- UResourceBundle* typeMapResByKey = ures_getByKey(typeMapRes, legacyKeyId, NULL, &tmpSts);\r
- if (U_FAILURE(tmpSts)) {\r
- // type map for each key must exist\r
- U_ASSERT(FALSE);\r
- tmpSts = U_ZERO_ERROR;\r
- } else {\r
- UResourceBundle typeMapEntry;\r
- ures_initStackObject(&typeMapEntry);\r
-\r
- while (ures_hasNext(typeMapResByKey)) {\r
- ures_getNextResource(typeMapResByKey, &typeMapEntry, &sts);\r
- if (U_FAILURE(sts)) {\r
- break;\r
- }\r
- const char* legacyTypeId = ures_getKey(&typeMapEntry);\r
-\r
- // special types\r
- if (uprv_strcmp(legacyTypeId, "CODEPOINTS") == 0) {\r
- specialTypes |= SPECIALTYPE_CODEPOINTS;\r
- continue;\r
- }\r
- if (uprv_strcmp(legacyTypeId, "REORDER_CODE") == 0) {\r
- specialTypes |= SPECIALTYPE_REORDER_CODE;\r
- continue;\r
- }\r
-\r
- if (isTZ) {\r
- // a timezone key uses a colon instead of a slash in the resource.\r
- // e.g. America:Los_Angeles\r
- if (uprv_strchr(legacyTypeId, ':') != NULL) {\r
- int32_t legacyTypeIdLen = uprv_strlen(legacyTypeId);\r
- char* legacyTypeIdBuf = (char*)uprv_malloc(legacyTypeIdLen + 1);\r
- if (legacyTypeIdBuf == NULL) {\r
- sts = U_MEMORY_ALLOCATION_ERROR;\r
- break;\r
- }\r
- const char* p = legacyTypeId;\r
- char* q = legacyTypeIdBuf;\r
- while (*p) {\r
- if (*p == ':') {\r
- *q++ = '/';\r
- } else {\r
- *q++ = *p;\r
- }\r
- p++;\r
- }\r
- *q = 0;\r
-\r
- gKeyTypeStringPool->addElement(legacyTypeIdBuf, sts);\r
- if (U_FAILURE(sts)) {\r
- break;\r
- }\r
- legacyTypeId = legacyTypeIdBuf;\r
- }\r
- }\r
-\r
- int32_t bcpTypeIdLen = 0;\r
- const UChar* uBcpTypeId = ures_getString(&typeMapEntry, &bcpTypeIdLen, &sts);\r
- if (U_FAILURE(sts)) {\r
- break;\r
- }\r
-\r
- // empty value indicates that BCP type is same with the legacy type.\r
- const char* bcpTypeId = legacyTypeId;\r
- if (bcpTypeIdLen > 0) {\r
- char* bcpTypeIdBuf = (char*)uprv_malloc(bcpTypeIdLen + 1);\r
- if (bcpTypeIdBuf == NULL) {\r
- sts = U_MEMORY_ALLOCATION_ERROR;\r
- break;\r
- }\r
- u_UCharsToChars(uBcpTypeId, bcpTypeIdBuf, bcpTypeIdLen);\r
- bcpTypeIdBuf[bcpTypeIdLen] = 0;\r
- gKeyTypeStringPool->addElement(bcpTypeIdBuf, sts);\r
- if (U_FAILURE(sts)) {\r
- break;\r
- }\r
- bcpTypeId = bcpTypeIdBuf;\r
- }\r
-\r
- // Note: legacy type value should never be\r
- // equivalent to bcp type value of a different\r
- // type under the same key. So we use a single\r
- // map for lookup.\r
- LocExtType* t = (LocExtType*)uprv_malloc(sizeof(LocExtType));\r
- if (t == NULL) {\r
- sts = U_MEMORY_ALLOCATION_ERROR;\r
- break;\r
- }\r
- t->bcpId = bcpTypeId;\r
- t->legacyId = legacyTypeId;\r
- gLocExtTypeEntries->addElement((void*)t, sts);\r
- if (U_FAILURE(sts)) {\r
- break;\r
- }\r
-\r
- uhash_put(typeDataMap, (void*)legacyTypeId, t, &sts);\r
- if (bcpTypeId != legacyTypeId) {\r
- // different type value\r
- uhash_put(typeDataMap, (void*)bcpTypeId, t, &sts);\r
- }\r
- if (U_FAILURE(sts)) {\r
- break;\r
- }\r
-\r
- // also put aliases in the map\r
- if (typeAliasResByKey != NULL) {\r
- UResourceBundle typeAliasDataEntry;\r
- ures_initStackObject(&typeAliasDataEntry);\r
-\r
- ures_resetIterator(typeAliasResByKey);\r
- while (ures_hasNext(typeAliasResByKey) && U_SUCCESS(sts)) {\r
- int32_t toLen;\r
- ures_getNextResource(typeAliasResByKey, &typeAliasDataEntry, &sts);\r
- const UChar* to = ures_getString(&typeAliasDataEntry, &toLen, &sts);\r
- if (U_FAILURE(sts)) {\r
- break;\r
- }\r
- // check if this is an alias of canoncal legacy type\r
- if (uprv_compareInvAscii(NULL, legacyTypeId, -1, to, toLen) == 0) {\r
- const char* from = ures_getKey(&typeAliasDataEntry);\r
- if (isTZ) {\r
- // replace colon with slash if necessary\r
- if (uprv_strchr(from, ':') != NULL) {\r
- int32_t fromLen = uprv_strlen(from);\r
- char* fromBuf = (char*)uprv_malloc(fromLen + 1);\r
- if (fromBuf == NULL) {\r
- sts = U_MEMORY_ALLOCATION_ERROR;\r
- break;\r
- }\r
- const char* p = from;\r
- char* q = fromBuf;\r
- while (*p) {\r
- if (*p == ':') {\r
- *q++ = '/';\r
- } else {\r
- *q++ = *p;\r
- }\r
- p++;\r
- }\r
- *q = 0;\r
-\r
- gKeyTypeStringPool->addElement(fromBuf, sts);\r
- if (U_FAILURE(sts)) {\r
- break;\r
- }\r
- from = fromBuf;\r
- }\r
- }\r
- uhash_put(typeDataMap, (void*)from, t, &sts);\r
- }\r
- }\r
- ures_close(&typeAliasDataEntry);\r
- if (U_FAILURE(sts)) {\r
- break;\r
- }\r
- }\r
-\r
- if (bcpTypeAliasResByKey != NULL) {\r
- UResourceBundle bcpTypeAliasDataEntry;\r
- ures_initStackObject(&bcpTypeAliasDataEntry);\r
-\r
- ures_resetIterator(bcpTypeAliasResByKey);\r
- while (ures_hasNext(bcpTypeAliasResByKey) && U_SUCCESS(sts)) {\r
- int32_t toLen;\r
- ures_getNextResource(bcpTypeAliasResByKey, &bcpTypeAliasDataEntry, &sts);\r
- const UChar* to = ures_getString(&bcpTypeAliasDataEntry, &toLen, &sts);\r
- if (U_FAILURE(sts)) {\r
- break;\r
- }\r
- // check if this is an alias of bcp type\r
- if (uprv_compareInvAscii(NULL, bcpTypeId, -1, to, toLen) == 0) {\r
- const char* from = ures_getKey(&bcpTypeAliasDataEntry);\r
- uhash_put(typeDataMap, (void*)from, t, &sts);\r
- }\r
- }\r
- ures_close(&bcpTypeAliasDataEntry);\r
- if (U_FAILURE(sts)) {\r
- break;\r
- }\r
- }\r
- }\r
- ures_close(&typeMapEntry);\r
- }\r
- ures_close(typeMapResByKey);\r
- ures_close(typeAliasResByKey);\r
- ures_close(bcpTypeAliasResByKey);\r
- if (U_FAILURE(sts)) {\r
- break;\r
- }\r
-\r
- LocExtKeyData* keyData = (LocExtKeyData*)uprv_malloc(sizeof(LocExtKeyData));\r
- if (keyData == NULL) {\r
- sts = U_MEMORY_ALLOCATION_ERROR;\r
- break;\r
- }\r
- keyData->bcpId = bcpKeyId;\r
- keyData->legacyId = legacyKeyId;\r
- keyData->specialTypes = specialTypes;\r
- keyData->typeMap = typeDataMap;\r
-\r
- gLocExtKeyDataEntries->addElement((void*)keyData, sts);\r
- if (U_FAILURE(sts)) {\r
- break;\r
- }\r
-\r
- uhash_put(gLocExtKeyMap, (void*)legacyKeyId, keyData, &sts);\r
- if (legacyKeyId != bcpKeyId) {\r
- // different key value\r
- uhash_put(gLocExtKeyMap, (void*)bcpKeyId, keyData, &sts);\r
- }\r
- if (U_FAILURE(sts)) {\r
- break;\r
- }\r
- }\r
-\r
- ures_close(&keyMapEntry);\r
-\r
-close_bundles:\r
- ures_close(bcpTypeAliasRes);\r
- ures_close(typeAliasRes);\r
- ures_close(typeMapRes);\r
- ures_close(keyMapRes);\r
- ures_close(keyTypeDataRes);\r
-}\r
-\r
-static UBool\r
-init() {\r
- UErrorCode sts = U_ZERO_ERROR;\r
- umtx_initOnce(gLocExtKeyMapInitOnce, &initFromResourceBundle, sts);\r
- if (U_FAILURE(sts)) {\r
- return FALSE;\r
- }\r
- return TRUE;\r
-}\r
-\r
-static UBool\r
-isSpecialTypeCodepoints(const char* val) {\r
- int32_t subtagLen = 0;\r
- const char* p = val;\r
- while (*p) {\r
- if (*p == '-') {\r
- if (subtagLen < 4 || subtagLen > 6) {\r
- return FALSE;\r
- }\r
- subtagLen = 0;\r
- } else if (('0' <= *p && *p <= '9') ||\r
- ('A' <= *p && *p <= 'F') || ('a' <= *p && *p <= 'f')) {\r
- subtagLen++;\r
- } else {\r
- return FALSE;\r
- }\r
- p++;\r
- }\r
- return (subtagLen >= 4 && subtagLen <= 6);\r
-}\r
-\r
-static UBool\r
-isSpecialTypeReorderCode(const char* val) {\r
- int32_t subtagLen = 0;\r
- const char* p = val;\r
- while (*p) {\r
- if (*p == '-') {\r
- if (subtagLen < 3 || subtagLen > 8) {\r
- return FALSE;\r
- }\r
- subtagLen = 0;\r
- } else if (('A' <= *p && *p <= 'Z') || ('a' <= *p && *p <= 'z')) {\r
- subtagLen++;\r
- } else {\r
- return FALSE;\r
- }\r
- p++;\r
- }\r
- return (subtagLen >=3 && subtagLen <=8);\r
-}\r
-\r
-U_CFUNC const char*\r
-ulocimp_toBcpKey(const char* key) {\r
- if (!init()) {\r
- return NULL;\r
- }\r
-\r
- LocExtKeyData* keyData = (LocExtKeyData*)uhash_get(gLocExtKeyMap, key);\r
- if (keyData != NULL) {\r
- return keyData->bcpId;\r
- }\r
- return NULL;\r
-}\r
-\r
-U_CFUNC const char*\r
-ulocimp_toLegacyKey(const char* key) {\r
- if (!init()) {\r
- return NULL;\r
- }\r
-\r
- LocExtKeyData* keyData = (LocExtKeyData*)uhash_get(gLocExtKeyMap, key);\r
- if (keyData != NULL) {\r
- return keyData->legacyId;\r
- }\r
- return NULL;\r
-}\r
-\r
-U_CFUNC const char*\r
-ulocimp_toBcpType(const char* key, const char* type, UBool* isKnownKey, UBool* isSpecialType) {\r
- if (isKnownKey != NULL) {\r
- *isKnownKey = FALSE;\r
- }\r
- if (isSpecialType != NULL) {\r
- *isSpecialType = FALSE;\r
- }\r
-\r
- if (!init()) {\r
- return NULL;\r
- }\r
-\r
- LocExtKeyData* keyData = (LocExtKeyData*)uhash_get(gLocExtKeyMap, key);\r
- if (keyData != NULL) {\r
- if (isKnownKey != NULL) {\r
- *isKnownKey = TRUE;\r
- }\r
- LocExtType* t = (LocExtType*)uhash_get(keyData->typeMap, type);\r
- if (t != NULL) {\r
- return t->bcpId;\r
- }\r
- if (keyData->specialTypes != SPECIALTYPE_NONE) {\r
- UBool matched = FALSE;\r
- if (keyData->specialTypes & SPECIALTYPE_CODEPOINTS) {\r
- matched = isSpecialTypeCodepoints(type);\r
- }\r
- if (!matched && keyData->specialTypes & SPECIALTYPE_REORDER_CODE) {\r
- matched = isSpecialTypeReorderCode(type);\r
- }\r
- if (matched) {\r
- if (isSpecialType != NULL) {\r
- *isSpecialType = TRUE;\r
- }\r
- return type;\r
- }\r
- }\r
- }\r
- return NULL;\r
-}\r
-\r
-\r
-U_CFUNC const char*\r
-ulocimp_toLegacyType(const char* key, const char* type, UBool* isKnownKey, UBool* isSpecialType) {\r
- if (isKnownKey != NULL) {\r
- *isKnownKey = FALSE;\r
- }\r
- if (isSpecialType != NULL) {\r
- *isSpecialType = FALSE;\r
- }\r
-\r
- if (!init()) {\r
- return NULL;\r
- }\r
-\r
- LocExtKeyData* keyData = (LocExtKeyData*)uhash_get(gLocExtKeyMap, key);\r
- if (keyData != NULL) {\r
- if (isKnownKey != NULL) {\r
- *isKnownKey = TRUE;\r
- }\r
- LocExtType* t = (LocExtType*)uhash_get(keyData->typeMap, type);\r
- if (t != NULL) {\r
- return t->legacyId;\r
- }\r
- if (keyData->specialTypes != SPECIALTYPE_NONE) {\r
- UBool matched = FALSE;\r
- if (keyData->specialTypes & SPECIALTYPE_CODEPOINTS) {\r
- matched = isSpecialTypeCodepoints(type);\r
- }\r
- if (!matched && keyData->specialTypes & SPECIALTYPE_REORDER_CODE) {\r
- matched = isSpecialTypeReorderCode(type);\r
- }\r
- if (matched) {\r
- if (isSpecialType != NULL) {\r
- *isSpecialType = TRUE;\r
- }\r
- return type;\r
- }\r
- }\r
- }\r
- return NULL;\r
-}\r
-\r
+/*
+**********************************************************************
+* Copyright (C) 2014, International Business Machines
+* Corporation and others. All Rights Reserved.
+**********************************************************************
+*/
+#include "unicode/utypes.h"
+
+#include "cstring.h"
+#include "uassert.h"
+#include "ucln_cmn.h"
+#include "uhash.h"
+#include "umutex.h"
+#include "uresimp.h"
+#include "uvector.h"
+
+static UHashtable* gLocExtKeyMap = NULL;
+static icu::UInitOnce gLocExtKeyMapInitOnce = U_INITONCE_INITIALIZER;
+static icu::UVector* gKeyTypeStringPool = NULL;
+static icu::UVector* gLocExtKeyDataEntries = NULL;
+static icu::UVector* gLocExtTypeEntries = NULL;
+
+// bit flags for special types
+typedef enum {
+ SPECIALTYPE_NONE = 0,
+ SPECIALTYPE_CODEPOINTS = 1,
+ SPECIALTYPE_REORDER_CODE = 2
+} SpecialType;
+
+typedef struct LocExtKeyData {
+ const char* legacyId;
+ const char* bcpId;
+ UHashtable* typeMap;
+ uint32_t specialTypes;
+} LocExtKeyData;
+
+typedef struct LocExtType {
+ const char* legacyId;
+ const char* bcpId;
+} LocExtType;
+
+U_CDECL_BEGIN
+
+static UBool U_CALLCONV
+uloc_key_type_cleanup(void) {
+ if (gLocExtKeyMap != NULL) {
+ uhash_close(gLocExtKeyMap);
+ gLocExtKeyMap = NULL;
+ }
+
+ delete gLocExtKeyDataEntries;
+ gLocExtKeyDataEntries = NULL;
+
+ delete gLocExtTypeEntries;
+ gLocExtTypeEntries = NULL;
+
+ delete gKeyTypeStringPool;
+ gKeyTypeStringPool = NULL;
+
+ gLocExtKeyMapInitOnce.reset();
+ return TRUE;
+}
+
+static void U_CALLCONV
+uloc_deleteKeyTypeStringPoolEntry(void* obj) {
+ uprv_free(obj);
+}
+
+static void U_CALLCONV
+uloc_deleteKeyDataEntry(void* obj) {
+ LocExtKeyData* keyData = (LocExtKeyData*)obj;
+ if (keyData->typeMap != NULL) {
+ uhash_close(keyData->typeMap);
+ }
+ uprv_free(keyData);
+}
+
+static void U_CALLCONV
+uloc_deleteTypeEntry(void* obj) {
+ uprv_free(obj);
+}
+
+U_CDECL_END
+
+
+static void U_CALLCONV
+initFromResourceBundle(UErrorCode& sts) {
+ ucln_common_registerCleanup(UCLN_COMMON_LOCALE_KEY_TYPE, uloc_key_type_cleanup);
+
+ gLocExtKeyMap = uhash_open(uhash_hashIChars, uhash_compareIChars, NULL, &sts);
+ if (U_FAILURE(sts)) {
+ return;
+ }
+
+ UResourceBundle *keyTypeDataRes = NULL;
+ UResourceBundle *keyMapRes = NULL;
+ UResourceBundle *typeMapRes = NULL;
+ UResourceBundle *typeAliasRes = NULL;
+ UResourceBundle *bcpTypeAliasRes = NULL;
+
+ keyTypeDataRes = ures_openDirect(NULL, "keyTypeData", &sts);
+ keyMapRes = ures_getByKey(keyTypeDataRes, "keyMap", NULL, &sts);
+ typeMapRes = ures_getByKey(keyTypeDataRes, "typeMap", NULL, &sts);
+
+ UErrorCode tmpSts = U_ZERO_ERROR;
+ typeAliasRes = ures_getByKey(keyTypeDataRes, "typeAlias", NULL, &tmpSts);
+ if (U_FAILURE(tmpSts)) {
+ typeAliasRes = NULL;
+ tmpSts = U_ZERO_ERROR;
+ }
+ bcpTypeAliasRes = ures_getByKey(keyTypeDataRes, "bcpTypeAlias", NULL, &tmpSts);
+ if (U_FAILURE(tmpSts)) {
+ bcpTypeAliasRes = NULL;
+ tmpSts = U_ZERO_ERROR;
+ }
+
+ // initialize vectors storing dynamically allocated objects
+ gKeyTypeStringPool = new icu::UVector(uloc_deleteKeyTypeStringPoolEntry, NULL, sts);
+ if (gKeyTypeStringPool == NULL || U_FAILURE(sts)) {
+ goto close_bundles;
+ }
+ gLocExtKeyDataEntries = new icu::UVector(uloc_deleteKeyDataEntry, NULL, sts);
+ if (gLocExtKeyDataEntries == NULL || U_FAILURE(sts)) {
+ goto close_bundles;
+ }
+ gLocExtTypeEntries = new icu::UVector(uloc_deleteTypeEntry, NULL, sts);
+ if (gLocExtTypeEntries == NULL || U_FAILURE(sts)) {
+ goto close_bundles;
+ }
+
+ // iterate through keyMap resource
+ UResourceBundle keyMapEntry;
+ ures_initStackObject(&keyMapEntry);
+
+ while (ures_hasNext(keyMapRes)) {
+ ures_getNextResource(keyMapRes, &keyMapEntry, &sts);
+ if (U_FAILURE(sts)) {
+ break;
+ }
+ const char* legacyKeyId = ures_getKey(&keyMapEntry);
+ int32_t bcpKeyIdLen = 0;
+ const UChar* uBcpKeyId = ures_getString(&keyMapEntry, &bcpKeyIdLen, &sts);
+ if (U_FAILURE(sts)) {
+ break;
+ }
+
+ // empty value indicates that BCP key is same with the legacy key.
+ const char* bcpKeyId = legacyKeyId;
+ if (bcpKeyIdLen > 0) {
+ char* bcpKeyIdBuf = (char*)uprv_malloc(bcpKeyIdLen + 1);
+ if (bcpKeyIdBuf == NULL) {
+ sts = U_MEMORY_ALLOCATION_ERROR;
+ break;
+ }
+ u_UCharsToChars(uBcpKeyId, bcpKeyIdBuf, bcpKeyIdLen);
+ bcpKeyIdBuf[bcpKeyIdLen] = 0;
+ gKeyTypeStringPool->addElement(bcpKeyIdBuf, sts);
+ if (U_FAILURE(sts)) {
+ break;
+ }
+ bcpKeyId = bcpKeyIdBuf;
+ }
+
+ UBool isTZ = uprv_strcmp(legacyKeyId, "timezone") == 0;
+
+ UHashtable* typeDataMap = uhash_open(uhash_hashIChars, uhash_compareIChars, NULL, &sts);
+ if (U_FAILURE(sts)) {
+ break;
+ }
+ uint32_t specialTypes = SPECIALTYPE_NONE;
+
+ UResourceBundle* typeAliasResByKey = NULL;
+ UResourceBundle* bcpTypeAliasResByKey = NULL;
+
+ if (typeAliasRes != NULL) {
+ typeAliasResByKey = ures_getByKey(typeAliasRes, legacyKeyId, NULL, &tmpSts);
+ if (U_FAILURE(tmpSts)) {
+ // only a few keys have type alias mapping
+ typeAliasResByKey = NULL;
+ tmpSts = U_ZERO_ERROR;
+ }
+ }
+ if (bcpTypeAliasRes != NULL) {
+ bcpTypeAliasResByKey = ures_getByKey(bcpTypeAliasRes, bcpKeyId, NULL, &tmpSts);
+ if (U_FAILURE(tmpSts)) {
+ // only a few keys have BCP type alias mapping
+ bcpTypeAliasResByKey = NULL;
+ tmpSts = U_ZERO_ERROR;
+ }
+ }
+
+ // look up type map for the key, and walk through the mapping data
+ UResourceBundle* typeMapResByKey = ures_getByKey(typeMapRes, legacyKeyId, NULL, &tmpSts);
+ if (U_FAILURE(tmpSts)) {
+ // type map for each key must exist
+ U_ASSERT(FALSE);
+ tmpSts = U_ZERO_ERROR;
+ } else {
+ UResourceBundle typeMapEntry;
+ ures_initStackObject(&typeMapEntry);
+
+ while (ures_hasNext(typeMapResByKey)) {
+ ures_getNextResource(typeMapResByKey, &typeMapEntry, &sts);
+ if (U_FAILURE(sts)) {
+ break;
+ }
+ const char* legacyTypeId = ures_getKey(&typeMapEntry);
+
+ // special types
+ if (uprv_strcmp(legacyTypeId, "CODEPOINTS") == 0) {
+ specialTypes |= SPECIALTYPE_CODEPOINTS;
+ continue;
+ }
+ if (uprv_strcmp(legacyTypeId, "REORDER_CODE") == 0) {
+ specialTypes |= SPECIALTYPE_REORDER_CODE;
+ continue;
+ }
+
+ if (isTZ) {
+ // a timezone key uses a colon instead of a slash in the resource.
+ // e.g. America:Los_Angeles
+ if (uprv_strchr(legacyTypeId, ':') != NULL) {
+ int32_t legacyTypeIdLen = uprv_strlen(legacyTypeId);
+ char* legacyTypeIdBuf = (char*)uprv_malloc(legacyTypeIdLen + 1);
+ if (legacyTypeIdBuf == NULL) {
+ sts = U_MEMORY_ALLOCATION_ERROR;
+ break;
+ }
+ const char* p = legacyTypeId;
+ char* q = legacyTypeIdBuf;
+ while (*p) {
+ if (*p == ':') {
+ *q++ = '/';
+ } else {
+ *q++ = *p;
+ }
+ p++;
+ }
+ *q = 0;
+
+ gKeyTypeStringPool->addElement(legacyTypeIdBuf, sts);
+ if (U_FAILURE(sts)) {
+ break;
+ }
+ legacyTypeId = legacyTypeIdBuf;
+ }
+ }
+
+ int32_t bcpTypeIdLen = 0;
+ const UChar* uBcpTypeId = ures_getString(&typeMapEntry, &bcpTypeIdLen, &sts);
+ if (U_FAILURE(sts)) {
+ break;
+ }
+
+ // empty value indicates that BCP type is same with the legacy type.
+ const char* bcpTypeId = legacyTypeId;
+ if (bcpTypeIdLen > 0) {
+ char* bcpTypeIdBuf = (char*)uprv_malloc(bcpTypeIdLen + 1);
+ if (bcpTypeIdBuf == NULL) {
+ sts = U_MEMORY_ALLOCATION_ERROR;
+ break;
+ }
+ u_UCharsToChars(uBcpTypeId, bcpTypeIdBuf, bcpTypeIdLen);
+ bcpTypeIdBuf[bcpTypeIdLen] = 0;
+ gKeyTypeStringPool->addElement(bcpTypeIdBuf, sts);
+ if (U_FAILURE(sts)) {
+ break;
+ }
+ bcpTypeId = bcpTypeIdBuf;
+ }
+
+ // Note: legacy type value should never be
+ // equivalent to bcp type value of a different
+ // type under the same key. So we use a single
+ // map for lookup.
+ LocExtType* t = (LocExtType*)uprv_malloc(sizeof(LocExtType));
+ if (t == NULL) {
+ sts = U_MEMORY_ALLOCATION_ERROR;
+ break;
+ }
+ t->bcpId = bcpTypeId;
+ t->legacyId = legacyTypeId;
+ gLocExtTypeEntries->addElement((void*)t, sts);
+ if (U_FAILURE(sts)) {
+ break;
+ }
+
+ uhash_put(typeDataMap, (void*)legacyTypeId, t, &sts);
+ if (bcpTypeId != legacyTypeId) {
+ // different type value
+ uhash_put(typeDataMap, (void*)bcpTypeId, t, &sts);
+ }
+ if (U_FAILURE(sts)) {
+ break;
+ }
+
+ // also put aliases in the map
+ if (typeAliasResByKey != NULL) {
+ UResourceBundle typeAliasDataEntry;
+ ures_initStackObject(&typeAliasDataEntry);
+
+ ures_resetIterator(typeAliasResByKey);
+ while (ures_hasNext(typeAliasResByKey) && U_SUCCESS(sts)) {
+ int32_t toLen;
+ ures_getNextResource(typeAliasResByKey, &typeAliasDataEntry, &sts);
+ const UChar* to = ures_getString(&typeAliasDataEntry, &toLen, &sts);
+ if (U_FAILURE(sts)) {
+ break;
+ }
+ // check if this is an alias of canoncal legacy type
+ if (uprv_compareInvAscii(NULL, legacyTypeId, -1, to, toLen) == 0) {
+ const char* from = ures_getKey(&typeAliasDataEntry);
+ if (isTZ) {
+ // replace colon with slash if necessary
+ if (uprv_strchr(from, ':') != NULL) {
+ int32_t fromLen = uprv_strlen(from);
+ char* fromBuf = (char*)uprv_malloc(fromLen + 1);
+ if (fromBuf == NULL) {
+ sts = U_MEMORY_ALLOCATION_ERROR;
+ break;
+ }
+ const char* p = from;
+ char* q = fromBuf;
+ while (*p) {
+ if (*p == ':') {
+ *q++ = '/';
+ } else {
+ *q++ = *p;
+ }
+ p++;
+ }
+ *q = 0;
+
+ gKeyTypeStringPool->addElement(fromBuf, sts);
+ if (U_FAILURE(sts)) {
+ break;
+ }
+ from = fromBuf;
+ }
+ }
+ uhash_put(typeDataMap, (void*)from, t, &sts);
+ }
+ }
+ ures_close(&typeAliasDataEntry);
+ if (U_FAILURE(sts)) {
+ break;
+ }
+ }
+
+ if (bcpTypeAliasResByKey != NULL) {
+ UResourceBundle bcpTypeAliasDataEntry;
+ ures_initStackObject(&bcpTypeAliasDataEntry);
+
+ ures_resetIterator(bcpTypeAliasResByKey);
+ while (ures_hasNext(bcpTypeAliasResByKey) && U_SUCCESS(sts)) {
+ int32_t toLen;
+ ures_getNextResource(bcpTypeAliasResByKey, &bcpTypeAliasDataEntry, &sts);
+ const UChar* to = ures_getString(&bcpTypeAliasDataEntry, &toLen, &sts);
+ if (U_FAILURE(sts)) {
+ break;
+ }
+ // check if this is an alias of bcp type
+ if (uprv_compareInvAscii(NULL, bcpTypeId, -1, to, toLen) == 0) {
+ const char* from = ures_getKey(&bcpTypeAliasDataEntry);
+ uhash_put(typeDataMap, (void*)from, t, &sts);
+ }
+ }
+ ures_close(&bcpTypeAliasDataEntry);
+ if (U_FAILURE(sts)) {
+ break;
+ }
+ }
+ }
+ ures_close(&typeMapEntry);
+ }
+ ures_close(typeMapResByKey);
+ ures_close(typeAliasResByKey);
+ ures_close(bcpTypeAliasResByKey);
+ if (U_FAILURE(sts)) {
+ break;
+ }
+
+ LocExtKeyData* keyData = (LocExtKeyData*)uprv_malloc(sizeof(LocExtKeyData));
+ if (keyData == NULL) {
+ sts = U_MEMORY_ALLOCATION_ERROR;
+ break;
+ }
+ keyData->bcpId = bcpKeyId;
+ keyData->legacyId = legacyKeyId;
+ keyData->specialTypes = specialTypes;
+ keyData->typeMap = typeDataMap;
+
+ gLocExtKeyDataEntries->addElement((void*)keyData, sts);
+ if (U_FAILURE(sts)) {
+ break;
+ }
+
+ uhash_put(gLocExtKeyMap, (void*)legacyKeyId, keyData, &sts);
+ if (legacyKeyId != bcpKeyId) {
+ // different key value
+ uhash_put(gLocExtKeyMap, (void*)bcpKeyId, keyData, &sts);
+ }
+ if (U_FAILURE(sts)) {
+ break;
+ }
+ }
+
+ ures_close(&keyMapEntry);
+
+close_bundles:
+ ures_close(bcpTypeAliasRes);
+ ures_close(typeAliasRes);
+ ures_close(typeMapRes);
+ ures_close(keyMapRes);
+ ures_close(keyTypeDataRes);
+}
+
+static UBool
+init() {
+ UErrorCode sts = U_ZERO_ERROR;
+ umtx_initOnce(gLocExtKeyMapInitOnce, &initFromResourceBundle, sts);
+ if (U_FAILURE(sts)) {
+ return FALSE;
+ }
+ return TRUE;
+}
+
+static UBool
+isSpecialTypeCodepoints(const char* val) {
+ int32_t subtagLen = 0;
+ const char* p = val;
+ while (*p) {
+ if (*p == '-') {
+ if (subtagLen < 4 || subtagLen > 6) {
+ return FALSE;
+ }
+ subtagLen = 0;
+ } else if (('0' <= *p && *p <= '9') ||
+ ('A' <= *p && *p <= 'F') || ('a' <= *p && *p <= 'f')) {
+ subtagLen++;
+ } else {
+ return FALSE;
+ }
+ p++;
+ }
+ return (subtagLen >= 4 && subtagLen <= 6);
+}
+
+static UBool
+isSpecialTypeReorderCode(const char* val) {
+ int32_t subtagLen = 0;
+ const char* p = val;
+ while (*p) {
+ if (*p == '-') {
+ if (subtagLen < 3 || subtagLen > 8) {
+ return FALSE;
+ }
+ subtagLen = 0;
+ } else if (('A' <= *p && *p <= 'Z') || ('a' <= *p && *p <= 'z')) {
+ subtagLen++;
+ } else {
+ return FALSE;
+ }
+ p++;
+ }
+ return (subtagLen >=3 && subtagLen <=8);
+}
+
+U_CFUNC const char*
+ulocimp_toBcpKey(const char* key) {
+ if (!init()) {
+ return NULL;
+ }
+
+ LocExtKeyData* keyData = (LocExtKeyData*)uhash_get(gLocExtKeyMap, key);
+ if (keyData != NULL) {
+ return keyData->bcpId;
+ }
+ return NULL;
+}
+
+U_CFUNC const char*
+ulocimp_toLegacyKey(const char* key) {
+ if (!init()) {
+ return NULL;
+ }
+
+ LocExtKeyData* keyData = (LocExtKeyData*)uhash_get(gLocExtKeyMap, key);
+ if (keyData != NULL) {
+ return keyData->legacyId;
+ }
+ return NULL;
+}
+
+U_CFUNC const char*
+ulocimp_toBcpType(const char* key, const char* type, UBool* isKnownKey, UBool* isSpecialType) {
+ if (isKnownKey != NULL) {
+ *isKnownKey = FALSE;
+ }
+ if (isSpecialType != NULL) {
+ *isSpecialType = FALSE;
+ }
+
+ if (!init()) {
+ return NULL;
+ }
+
+ LocExtKeyData* keyData = (LocExtKeyData*)uhash_get(gLocExtKeyMap, key);
+ if (keyData != NULL) {
+ if (isKnownKey != NULL) {
+ *isKnownKey = TRUE;
+ }
+ LocExtType* t = (LocExtType*)uhash_get(keyData->typeMap, type);
+ if (t != NULL) {
+ return t->bcpId;
+ }
+ if (keyData->specialTypes != SPECIALTYPE_NONE) {
+ UBool matched = FALSE;
+ if (keyData->specialTypes & SPECIALTYPE_CODEPOINTS) {
+ matched = isSpecialTypeCodepoints(type);
+ }
+ if (!matched && keyData->specialTypes & SPECIALTYPE_REORDER_CODE) {
+ matched = isSpecialTypeReorderCode(type);
+ }
+ if (matched) {
+ if (isSpecialType != NULL) {
+ *isSpecialType = TRUE;
+ }
+ return type;
+ }
+ }
+ }
+ return NULL;
+}
+
+
+U_CFUNC const char*
+ulocimp_toLegacyType(const char* key, const char* type, UBool* isKnownKey, UBool* isSpecialType) {
+ if (isKnownKey != NULL) {
+ *isKnownKey = FALSE;
+ }
+ if (isSpecialType != NULL) {
+ *isSpecialType = FALSE;
+ }
+
+ if (!init()) {
+ return NULL;
+ }
+
+ LocExtKeyData* keyData = (LocExtKeyData*)uhash_get(gLocExtKeyMap, key);
+ if (keyData != NULL) {
+ if (isKnownKey != NULL) {
+ *isKnownKey = TRUE;
+ }
+ LocExtType* t = (LocExtType*)uhash_get(keyData->typeMap, type);
+ if (t != NULL) {
+ return t->legacyId;
+ }
+ if (keyData->specialTypes != SPECIALTYPE_NONE) {
+ UBool matched = FALSE;
+ if (keyData->specialTypes & SPECIALTYPE_CODEPOINTS) {
+ matched = isSpecialTypeCodepoints(type);
+ }
+ if (!matched && keyData->specialTypes & SPECIALTYPE_REORDER_CODE) {
+ matched = isSpecialTypeReorderCode(type);
+ }
+ if (matched) {
+ if (isSpecialType != NULL) {
+ *isSpecialType = TRUE;
+ }
+ return type;
+ }
+ }
+ }
+ return NULL;
+}
+