ConfusabledataBuilder::ConfusabledataBuilder(SpoofImpl *spImpl, UErrorCode &status) : fSpoofImpl(spImpl), fInput(NULL), fSLTable(NULL), fSATable(NULL), fMLTable(NULL), fMATable(NULL), fKeySet(NULL), fKeyVec(NULL), fValueVec(NULL), fStringTable(NULL), fStringLengthsTable(NULL), stringPool(NULL), fParseLine(NULL), fParseHexNum(NULL), fLineNum(0) { if (U_FAILURE(status)) { return; } fSLTable = uhash_open(uhash_hashLong, uhash_compareLong, NULL, &status); fSATable = uhash_open(uhash_hashLong, uhash_compareLong, NULL, &status); fMLTable = uhash_open(uhash_hashLong, uhash_compareLong, NULL, &status); fMATable = uhash_open(uhash_hashLong, uhash_compareLong, NULL, &status); fKeySet = new UnicodeSet(); fKeyVec = new UVector(status); fValueVec = new UVector(status); stringPool = new SPUStringPool(status); }
U_CDECL_END /** Initializes the cache for resources */ static void initCache(UErrorCode * status) { UBool makeCache; UMTX_CHECK(&usprepMutex, (SHARED_DATA_HASHTABLE == NULL), makeCache); if (makeCache) { UHashtable * newCache = uhash_open(hashEntry, compareEntries, NULL, status); if (U_SUCCESS(*status)) { umtx_lock(&usprepMutex); if (SHARED_DATA_HASHTABLE == NULL) { SHARED_DATA_HASHTABLE = newCache; ucln_common_registerCleanup(UCLN_COMMON_USPREP, usprep_cleanup); newCache = NULL; } umtx_unlock(&usprepMutex); } if (newCache != NULL) { uhash_close(newCache); } } }
U_CDECL_END U_NAMESPACE_BEGIN void U_CALLCONV GenderInfo_initCache(UErrorCode &status) { ucln_i18n_registerCleanup(UCLN_I18N_GENDERINFO, gender_cleanup); U_ASSERT(gGenderInfoCache == NULL); if (U_FAILURE(status)) { return; } gObjs = new GenderInfo[GENDER_STYLE_LENGTH]; if (gObjs == NULL) { status = U_MEMORY_ALLOCATION_ERROR; return; } for (int i = 0; i < GENDER_STYLE_LENGTH; i++) { gObjs[i]._style = i; } gGenderInfoCache = uhash_open(uhash_hashChars, uhash_compareChars, NULL, &status); if (U_FAILURE(status)) { delete [] gObjs; return; } uhash_setKeyDeleter(gGenderInfoCache, uprv_free); }
/* udata_getCacheHashTable() * Get the hash table used to store the data cache entries. * Lazy create it if it doesn't yet exist. */ static UHashtable *udata_getHashTable() { UErrorCode err = U_ZERO_ERROR; UBool cacheIsInitialized; UHashtable *tHT = NULL; UMTX_CHECK(NULL, (gCommonDataCache != NULL), cacheIsInitialized); if (cacheIsInitialized) { return gCommonDataCache; } tHT = uhash_open(uhash_hashChars, uhash_compareChars, NULL, &err); /* Check for null pointer. */ if (tHT == NULL) { return NULL; /* TODO: Handle this error better. */ } uhash_setValueDeleter(tHT, DataCacheElement_deleter); umtx_lock(NULL); if (gCommonDataCache == NULL) { gCommonDataCache = tHT; tHT = NULL; ucln_common_registerCleanup(UCLN_COMMON_UDATA, udata_cleanup); } umtx_unlock(NULL); if (tHT != NULL) { uhash_close(tHT); } if (U_FAILURE(err)) { return NULL; /* TODO: handle this error better. */ } return gCommonDataCache; }
static void U_CALLCONV initAvailableMetaZoneIDs () { U_ASSERT(gMetaZoneIDs == NULL); U_ASSERT(gMetaZoneIDTable == NULL); ucln_i18n_registerCleanup(UCLN_I18N_ZONEMETA, zoneMeta_cleanup); UErrorCode status = U_ZERO_ERROR; gMetaZoneIDTable = uhash_open(uhash_hashUnicodeString, uhash_compareUnicodeString, NULL, &status); if (U_FAILURE(status) || gMetaZoneIDTable == NULL) { gMetaZoneIDTable = NULL; return; } uhash_setKeyDeleter(gMetaZoneIDTable, uprv_deleteUObject); // No valueDeleter, because the vector maintain the value objects gMetaZoneIDs = new UVector(NULL, uhash_compareUChars, status); if (U_FAILURE(status) || gMetaZoneIDs == NULL) { gMetaZoneIDs = NULL; uhash_close(gMetaZoneIDTable); gMetaZoneIDTable = NULL; return; } gMetaZoneIDs->setDeleter(uprv_free); UResourceBundle *rb = ures_openDirect(NULL, gMetaZones, &status); UResourceBundle *bundle = ures_getByKey(rb, gMapTimezonesTag, NULL, &status); UResourceBundle res; ures_initStackObject(&res); while (U_SUCCESS(status) && ures_hasNext(bundle)) { ures_getNextResource(bundle, &res, &status); if (U_FAILURE(status)) { break; } const char *mzID = ures_getKey(&res); int32_t len = uprv_strlen(mzID); UChar *uMzID = (UChar*)uprv_malloc(sizeof(UChar) * (len + 1)); if (uMzID == NULL) { status = U_MEMORY_ALLOCATION_ERROR; break; } u_charsToUChars(mzID, uMzID, len); uMzID[len] = 0; UnicodeString *usMzID = new UnicodeString(uMzID); if (uhash_get(gMetaZoneIDTable, usMzID) == NULL) { gMetaZoneIDs->addElement((void *)uMzID, status); uhash_put(gMetaZoneIDTable, (void *)usMzID, (void *)uMzID, &status); } else { uprv_free(uMzID); delete usMzID; } } ures_close(&res); ures_close(bundle); ures_close(rb); if (U_FAILURE(status)) { uhash_close(gMetaZoneIDTable); delete gMetaZoneIDs; gMetaZoneIDTable = NULL; gMetaZoneIDs = NULL; } }
SPUStringPool::SPUStringPool(UErrorCode &status) : fVec(NULL), fHash(NULL) { fVec = new UVector(status); fHash = uhash_open(uhash_hashUnicodeString, // key hash function uhash_compareUnicodeString, // Key Comparator NULL, // Value Comparator &status); }
static void hashIChars(void) { static const char which[] = "which"; static const char WHICH2[] = "WHICH"; static const char where[] = "where"; UErrorCode status = U_ZERO_ERROR; UHashtable *hash; hash = uhash_open(uhash_hashIChars, uhash_compareIChars, NULL, &status); if (U_FAILURE(status)) { log_err("FAIL: uhash_open failed with %s and returned 0x%08x\n", u_errorName(status), hash); return; } if (hash == NULL) { log_err("FAIL: uhash_open returned NULL\n"); return; } log_verbose("Ok: uhash_open returned 0x%08X\n", hash); _put(hash, which, 1, 0); _put(hash, WHICH2, 2, 1); _put(hash, where, 3, 0); if(uhash_count(hash) != 2){ log_err("FAIL: uhas_count() failed. Expected: 1, Got: %d\n", uhash_count(hash)); } _remove(hash, which, 2); uhash_close(hash); }
UnifiedCache::UnifiedCache(UErrorCode &status) : fHashtable(NULL), fEvictPos(UHASH_FIRST), fNumValuesTotal(0), fNumValuesInUse(0), fMaxUnused(DEFAULT_MAX_UNUSED), fMaxPercentageOfInUse(DEFAULT_PERCENTAGE_OF_IN_USE), fAutoEvictedCount(0), fNoValue(nullptr) { if (U_FAILURE(status)) { return; } fNoValue = new SharedObject(); if (fNoValue == nullptr) { status = U_MEMORY_ALLOCATION_ERROR; return; } fNoValue->softRefCount = 1; // Add fake references to prevent fNoValue from being deleted fNoValue->hardRefCount = 1; // when other references to it are removed. fNoValue->cachePtr = this; fHashtable = uhash_open( &ucache_hashKeys, &ucache_compareKeys, NULL, &status); if (U_FAILURE(status)) { return; } uhash_setKeyDeleter(fHashtable, &ucache_deleteKey); }
U_CDECL_END U_NAMESPACE_BEGIN Locale *locale_set_default_internal(const char *id, UErrorCode& status) { // Synchronize this entire function. Mutex lock(&gDefaultLocaleMutex); UBool canonicalize = FALSE; // If given a NULL string for the locale id, grab the default // name from the system. // (Different from most other locale APIs, where a null name means use // the current ICU default locale.) if (id == NULL) { id = uprv_getDefaultLocaleID(); // This function not thread safe? TODO: verify. canonicalize = TRUE; // always canonicalize host ID } char localeNameBuf[512]; if (canonicalize) { uloc_canonicalize(id, localeNameBuf, sizeof(localeNameBuf)-1, &status); } else { uloc_getName(id, localeNameBuf, sizeof(localeNameBuf)-1, &status); } localeNameBuf[sizeof(localeNameBuf)-1] = 0; // Force null termination in event of // a long name filling the buffer. // (long names are truncated.) // if (U_FAILURE(status)) { return gDefaultLocale; } if (gDefaultLocalesHashT == NULL) { gDefaultLocalesHashT = uhash_open(uhash_hashChars, uhash_compareChars, NULL, &status); if (U_FAILURE(status)) { return gDefaultLocale; } uhash_setValueDeleter(gDefaultLocalesHashT, deleteLocale); ucln_common_registerCleanup(UCLN_COMMON_LOCALE, locale_cleanup); } Locale *newDefault = (Locale *)uhash_get(gDefaultLocalesHashT, localeNameBuf); if (newDefault == NULL) { newDefault = new Locale(Locale::eBOGUS); if (newDefault == NULL) { status = U_MEMORY_ALLOCATION_ERROR; return gDefaultLocale; } newDefault->init(localeNameBuf, FALSE); uhash_put(gDefaultLocalesHashT, (char*) newDefault->getName(), newDefault, &status); if (U_FAILURE(status)) { return gDefaultLocale; } } gDefaultLocale = newDefault; return gDefaultLocale; }
/** * Copy constructor. */ AnyTransliterator::AnyTransliterator(const AnyTransliterator& o) : Transliterator(o), target(o.target), targetScript(o.targetScript) { // Don't copy the cache contents UErrorCode ec = U_ZERO_ERROR; cache = uhash_open(uhash_hashLong, uhash_compareLong, NULL, &ec); uhash_setValueDeleter(cache, _deleteTransliterator); }
static void U_CALLCONV olsonToMetaInit(UErrorCode &status) { U_ASSERT(gOlsonToMeta == NULL); ucln_i18n_registerCleanup(UCLN_I18N_ZONEMETA, zoneMeta_cleanup); gOlsonToMeta = uhash_open(uhash_hashUChars, uhash_compareUChars, NULL, &status); if (U_FAILURE(status)) { gOlsonToMeta = NULL; } else { uhash_setKeyDeleter(gOlsonToMeta, deleteUCharString); uhash_setValueDeleter(gOlsonToMeta, deleteUVector); } }
static void U_CALLCONV initCanonicalIDCache(UErrorCode &status) { gCanonicalIDCache = uhash_open(uhash_hashUChars, uhash_compareUChars, NULL, &status); if (gCanonicalIDCache == NULL) { status = U_MEMORY_ALLOCATION_ERROR; } if (U_FAILURE(status)) { gCanonicalIDCache = NULL; } // No key/value deleters - keys/values are from a resource bundle ucln_i18n_registerCleanup(UCLN_I18N_ZONEMETA, zoneMeta_cleanup); }
void CDFLocaleStyleData::Init(UErrorCode& status) { if (unitsByVariant != NULL) { return; } unitsByVariant = uhash_open(uhash_hashChars, uhash_compareChars, NULL, &status); if (U_FAILURE(status)) { return; } uhash_setKeyDeleter(unitsByVariant, uprv_free); uhash_setValueDeleter(unitsByVariant, deleteCDFUnits); }
static void TestBasic(void) { const char one[4] = {0x6F, 0x6E, 0x65, 0}; /* "one" */ const char one2[4] = {0x6F, 0x6E, 0x65, 0}; /* Get around compiler optimizations */ const char two[4] = {0x74, 0x77, 0x6F, 0}; /* "two" */ const char three[6] = {0x74, 0x68, 0x72, 0x65, 0x65, 0}; /* "three" */ const char omega[6] = {0x6F, 0x6D, 0x65, 0x67, 0x61, 0}; /* "omega" */ UErrorCode status = U_ZERO_ERROR; UHashtable *hash; hash = uhash_open(hashChars, isEqualChars, &status); if (U_FAILURE(status)) { log_err("FAIL: uhash_open failed with %s and returned 0x%08x\n", u_errorName(status), hash); return; } if (hash == NULL) { log_err("FAIL: uhash_open returned NULL\n"); return; } log_verbose("Ok: uhash_open returned 0x%08X\n", hash); _put(hash, one, 1, 0); _put(hash, omega, 24, 0); _put(hash, two, 2, 0); _put(hash, three, 3, 0); _put(hash, one, -1, 1); _put(hash, two, -2, 2); _put(hash, omega, 48, 24); _put(hash, one, 100, -1); _get(hash, three, 3); _remove(hash, two, -2); _get(hash, two, 0); _get(hash, one, 100); _put(hash, two, 200, 0); _get(hash, omega, 48); _get(hash, two, 200); if(_compareChars((void*)one, (void*)three) == TRUE || _compareChars((void*)one, (void*)one2) != TRUE || _compareChars((void*)one, (void*)one) != TRUE || _compareChars((void*)one, NULL) == TRUE ) { log_err("FAIL: compareChars failed\n"); } if(_compareIChars((void*)one, (void*)three) == TRUE || _compareIChars((void*)one, (void*)one) != TRUE || _compareIChars((void*)one, (void*)one2) != TRUE || _compareIChars((void*)one, NULL) == TRUE ) { log_err("FAIL: compareIChars failed\n"); } uhash_close(hash); }
U_CDECL_END /** Initializes the cache for resources */ static void U_CALLCONV createCache(UErrorCode &status) { SHARED_DATA_HASHTABLE = uhash_open(hashEntry, compareEntries, NULL, &status); if (U_FAILURE(status)) { SHARED_DATA_HASHTABLE = NULL; } ucln_common_registerCleanup(UCLN_COMMON_USPREP, usprep_cleanup); }
void AlphabeticIndex::init(UErrorCode &status) { // Initialize statics if needed. AlphabeticIndex::staticInit(status); // Put the object into a known state so that the destructor will function. alreadyIn_ = NULL; bucketList_ = NULL; collator_ = NULL; collatorPrimaryOnly_ = NULL; currentBucket_ = NULL; firstScriptCharacters_ = NULL; initialLabels_ = NULL; indexBuildRequired_ = TRUE; inputRecords_ = NULL; itemsIterIndex_ = 0; labels_ = NULL; labelsIterIndex_ = 0; maxLabelCount_ = 99; noDistinctSorting_ = NULL; notAlphabetic_ = NULL; recordCounter_ = 0; if (U_FAILURE(status)) { return; } alreadyIn_ = uhash_open(uhash_hashUnicodeString, // Key Hash, uhash_compareUnicodeString, // key Comparator, NULL, // value Comparator &status); uhash_setKeyDeleter(alreadyIn_, uprv_deleteUObject); uhash_setValueDeleter(alreadyIn_, uprv_deleteUObject); bucketList_ = new UVector(status); bucketList_->setDeleter(alphaIndex_deleteBucket); labels_ = new UVector(status); labels_->setDeleter(uprv_deleteUObject); labels_->setComparer(uhash_compareUnicodeString); inputRecords_ = new UVector(status); inputRecords_->setDeleter(alphaIndex_deleteRecord); noDistinctSorting_ = new UnicodeSet(); notAlphabetic_ = new UnicodeSet(); initialLabels_ = new UnicodeSet(); inflowLabel_.remove(); inflowLabel_.append((UChar)0x2026); // Ellipsis overflowLabel_ = inflowLabel_; underflowLabel_ = inflowLabel_; // TODO: check for memory allocation failures. }
void TimeZoneNamesImpl::initialize(const Locale& locale, UErrorCode& status) { if (U_FAILURE(status)) { return; } // Load zoneStrings bundle UErrorCode tmpsts = U_ZERO_ERROR; // OK with fallback warning.. fZoneStrings = ures_open(U_ICUDATA_ZONE, locale.getName(), &tmpsts); fZoneStrings = ures_getByKeyWithFallback(fZoneStrings, gZoneStrings, fZoneStrings, &tmpsts); if (U_FAILURE(tmpsts)) { status = tmpsts; cleanup(); return; } // Initialize hashtables holding time zone/meta zone names fMZNamesMap = uhash_open(uhash_hashUChars, uhash_compareUChars, NULL, &status); fTZNamesMap = uhash_open(uhash_hashUChars, uhash_compareUChars, NULL, &status); if (U_FAILURE(status)) { cleanup(); return; } uhash_setValueDeleter(fMZNamesMap, deleteZNames); uhash_setValueDeleter(fTZNamesMap, deleteTZNames); // no key deleters for name maps // preload zone strings for the default zone TimeZone *tz = TimeZone::createDefault(); const UChar *tzID = ZoneMeta::getCanonicalCLDRID(*tz); if (tzID != NULL) { loadStrings(UnicodeString(tzID)); } delete tz; return; }
static void U_CALLCONV nscacheInit() { U_ASSERT(NumberingSystem_cache == NULL); ucln_i18n_registerCleanup(UCLN_I18N_NUMFMT, numfmt_cleanup); UErrorCode status = U_ZERO_ERROR; NumberingSystem_cache = uhash_open(uhash_hashLong, uhash_compareLong, NULL, &status); if (U_FAILURE(status)) { // Number Format code will run with no cache if creation fails. NumberingSystem_cache = NULL; return; } uhash_setValueDeleter(NumberingSystem_cache, deleteNumberingSystem); }
UnifiedCache::UnifiedCache(UErrorCode &status) { if (U_FAILURE(status)) { return; } U_ASSERT(gNoValue != NULL); fHashtable = uhash_open( &ucache_hashKeys, &ucache_compareKeys, NULL, &status); if (U_FAILURE(status)) { return; } uhash_setKeyDeleter(fHashtable, &ucache_deleteKey); }
//-------------------------------------------------------------------------- // // init Shared initialization for use by constructors. // Bring an uninitialized RegexPattern up to a default state. // //-------------------------------------------------------------------------- void RegexPattern::init() { fFlags = 0; fCompiledPat = 0; fLiteralText.remove(); fSets = NULL; fSets8 = NULL; fDeferredStatus = U_ZERO_ERROR; fMinMatchLen = 0; fFrameSize = 0; fDataSize = 0; fGroupMap = NULL; fStaticSets = NULL; fStaticSets8 = NULL; fStartType = START_NO_INFO; fInitialStringIdx = 0; fInitialStringLen = 0; fInitialChars = NULL; fInitialChar = 0; fInitialChars8 = NULL; fNeedsAltInput = FALSE; fNamedCaptureMap = NULL; fPattern = NULL; // will be set later fPatternString = NULL; // may be set later fCompiledPat = new UVector64(fDeferredStatus); fGroupMap = new UVector32(fDeferredStatus); fSets = new UVector(fDeferredStatus); fInitialChars = new UnicodeSet; fInitialChars8 = new Regex8BitSet; fNamedCaptureMap = uhash_open(uhash_hashUnicodeString, // Key hash function uhash_compareUnicodeString, // Key comparator function uhash_compareLong, // Value comparator function &fDeferredStatus); if (U_FAILURE(fDeferredStatus)) { return; } if (fCompiledPat == NULL || fGroupMap == NULL || fSets == NULL || fInitialChars == NULL || fInitialChars8 == NULL || fNamedCaptureMap == NULL) { fDeferredStatus = U_MEMORY_ALLOCATION_ERROR; return; } // Slot zero of the vector of sets is reserved. Fill it here. fSets->addElement((int32_t)0, fDeferredStatus); // fNamedCaptureMap owns its key strings, type (UnicodeString *) uhash_setKeyDeleter(fNamedCaptureMap, uprv_deleteUObject); }
AnyTransliterator::AnyTransliterator(const UnicodeString& id, const UnicodeString& theTarget, const UnicodeString& theVariant, UScriptCode theTargetScript, UErrorCode& ec) : Transliterator(id, NULL), targetScript(theTargetScript) { cache = uhash_open(uhash_hashLong, uhash_compareLong, NULL, &ec); uhash_setValueDeleter(cache, _deleteTransliterator); target = theTarget; if (theVariant.length() > 0) { target.append(VARIANT_SEP).append(theVariant); } }
CollDataCache::CollDataCache(UErrorCode &status) : cache(NULL) { if (U_FAILURE(status)) { return; } cache = uhash_open(uhash_hashChars, uhash_compareChars, uhash_compareLong, &status); if (U_FAILURE(status)) { return; } uhash_setValueDeleter(cache, deleteCollDataCacheEntry); uhash_setKeyDeleter(cache, deleteChars); }
U_CDECL_END IdentifierInfo::IdentifierInfo(UErrorCode &status): fIdentifier(NULL), fRequiredScripts(NULL), fScriptSetSet(NULL), fCommonAmongAlternates(NULL), fNumerics(NULL), fIdentifierProfile(NULL) { if (U_FAILURE(status)) { return; } { Mutex lock(&gInitMutex); if (!gStaticsAreInitialized) { ASCII = new UnicodeSet(0, 0x7f); JAPANESE = new ScriptSet(); CHINESE = new ScriptSet(); KOREAN = new ScriptSet(); CONFUSABLE_WITH_LATIN = new ScriptSet(); if (ASCII == NULL || JAPANESE == NULL || CHINESE == NULL || KOREAN == NULL || CONFUSABLE_WITH_LATIN == NULL) { status = U_MEMORY_ALLOCATION_ERROR; return; } ASCII->freeze(); JAPANESE->set(USCRIPT_LATIN, status).set(USCRIPT_HAN, status).set(USCRIPT_HIRAGANA, status) .set(USCRIPT_KATAKANA, status); CHINESE->set(USCRIPT_LATIN, status).set(USCRIPT_HAN, status).set(USCRIPT_BOPOMOFO, status); KOREAN->set(USCRIPT_LATIN, status).set(USCRIPT_HAN, status).set(USCRIPT_HANGUL, status); CONFUSABLE_WITH_LATIN->set(USCRIPT_CYRILLIC, status).set(USCRIPT_GREEK, status) .set(USCRIPT_CHEROKEE, status); ucln_i18n_registerCleanup(UCLN_I18N_IDENTIFIER_INFO, IdentifierInfo_cleanup); gStaticsAreInitialized = TRUE; } } fIdentifier = new UnicodeString(); fRequiredScripts = new ScriptSet(); fScriptSetSet = uhash_open(uhash_hashScriptSet, uhash_compareScriptSet, NULL, &status); uhash_setKeyDeleter(fScriptSetSet, uhash_deleteScriptSet); fCommonAmongAlternates = new ScriptSet(); fNumerics = new UnicodeSet(); fIdentifierProfile = new UnicodeSet(0, 0x10FFFF); if (U_SUCCESS(status) && (fIdentifier == NULL || fRequiredScripts == NULL || fScriptSetSet == NULL || fCommonAmongAlternates == NULL || fNumerics == NULL || fIdentifierProfile == NULL)) { status = U_MEMORY_ALLOCATION_ERROR; } }
CEToStringsMap::CEToStringsMap(UErrorCode &status) : map(NULL) { if (U_FAILURE(status)) { return; } map = uhash_open(uhash_hashLong, uhash_compareLong, uhash_compareCaselessUnicodeString, &status); if (U_FAILURE(status)) { return; } uhash_setValueDeleter(map, deleteStringList); }
// getCDFLocaleStyleData returns pointer to formatting data for given locale and // style within the global cache. On cache miss, getCDFLocaleStyleData loads // the data from CLDR into the global cache before returning the pointer. If a // UNUM_LONG data is requested for a locale, and that locale does not have // UNUM_LONG data, getCDFLocaleStyleData will fall back to UNUM_SHORT data for // that locale. static const CDFLocaleStyleData* getCDFLocaleStyleData(const Locale& inLocale, UNumberCompactStyle style, UErrorCode& status) { if (U_FAILURE(status)) { return NULL; } CDFLocaleData* result = NULL; const char* key = inLocale.getName(); { Mutex lock(&gCompactDecimalMetaLock); if (gCompactDecimalData == NULL) { gCompactDecimalData = uhash_open(uhash_hashChars, uhash_compareChars, NULL, &status); if (U_FAILURE(status)) { return NULL; } uhash_setKeyDeleter(gCompactDecimalData, uprv_free); uhash_setValueDeleter(gCompactDecimalData, deleteCDFLocaleData); ucln_i18n_registerCleanup(UCLN_I18N_CDFINFO, cdf_cleanup); } else { result = (CDFLocaleData*) uhash_get(gCompactDecimalData, key); } } if (result != NULL) { return extractDataByStyleEnum(*result, style, status); } result = loadCDFLocaleData(inLocale, status); if (U_FAILURE(status)) { return NULL; } { Mutex lock(&gCompactDecimalMetaLock); CDFLocaleData* temp = (CDFLocaleData*) uhash_get(gCompactDecimalData, key); if (temp != NULL) { delete result; result = temp; } else { uhash_put(gCompactDecimalData, uprv_strdup(key), (void*) result, &status); if (U_FAILURE(status)) { return NULL; } } } return extractDataByStyleEnum(*result, style, status); }
U_CDECL_END U_NAMESPACE_BEGIN RBBISymbolTable::RBBISymbolTable(RBBIRuleScanner *rs, const UnicodeString &rules, UErrorCode &status) :fRules(rules), fRuleScanner(rs), ffffString(UChar(0xffff)) { fHashTable = NULL; fCachedSetLookup = NULL; fHashTable = uhash_open(uhash_hashUnicodeString, uhash_compareUnicodeString, NULL, &status); // uhash_open checks status if (U_FAILURE(status)) { return; } uhash_setValueDeleter(fHashTable, RBBISymbolTableEntry_deleter); }
void U_CALLCONV DayPeriodRules::load(UErrorCode &errorCode) { if (U_FAILURE(errorCode)) { return; } data = new DayPeriodRulesData(); data->localeToRuleSetNumMap = uhash_open(uhash_hashChars, uhash_compareChars, NULL, &errorCode); LocalUResourceBundlePointer rb_dayPeriods(ures_openDirect(NULL, "dayPeriods", &errorCode)); // Get the largest rule set number (so we allocate enough objects). DayPeriodRulesCountSink countSink; ures_getAllItemsWithFallback(rb_dayPeriods.getAlias(), "rules", countSink, errorCode); // Populate rules. DayPeriodRulesDataSink sink; ures_getAllItemsWithFallback(rb_dayPeriods.getAlias(), "", sink, errorCode); ucln_i18n_registerCleanup(UCLN_I18N_DAYPERIODRULES, dayPeriodRulesCleanup); }
StringToCEsMap::StringToCEsMap(UErrorCode &status) : map(NULL) { if (U_FAILURE(status)) { return; } map = uhash_open(uhash_hashUnicodeString, uhash_compareUnicodeString, uhash_compareLong, &status); if (U_FAILURE(status)) { return; } uhash_setValueDeleter(map, deleteCEList); uhash_setKeyDeleter(map, deleteUnicodeStringKey); }
ZNStringPool::ZNStringPool(UErrorCode &status) { fChunks = NULL; fHash = NULL; if (U_FAILURE(status)) { return; } fChunks = new ZNStringPoolChunk; if (fChunks == NULL) { status = U_MEMORY_ALLOCATION_ERROR; return; } fHash = uhash_open(uhash_hashUChars /* keyHash */, uhash_compareUChars /* keyComp */, uhash_compareUChars /* valueComp */, &status); if (U_FAILURE(status)) { return; } }
UnifiedCache::UnifiedCache(UErrorCode &status) : fHashtable(NULL), fEvictPos(UHASH_FIRST), fItemsInUseCount(0), fMaxUnused(DEFAULT_MAX_UNUSED), fMaxPercentageOfInUse(DEFAULT_PERCENTAGE_OF_IN_USE), fAutoEvictedCount(0) { if (U_FAILURE(status)) { return; } U_ASSERT(gNoValue != NULL); fHashtable = uhash_open( &ucache_hashKeys, &ucache_compareKeys, NULL, &status); if (U_FAILURE(status)) { return; } uhash_setKeyDeleter(fHashtable, &ucache_deleteKey); }