/** * Returns a pointer to a Region using the given numeric region code. If the numeric region code is not recognized, * the appropriate error code will be set ( U_ILLEGAL_ARGUMENT_ERROR ). */ const Region* U_EXPORT2 Region::getInstance (int32_t code, UErrorCode &status) { loadRegionData(); Region *r = (Region *)uhash_iget(numericCodeMap,code); if ( !r ) { // Just in case there's an alias that's numeric, try to find it. UErrorCode fs = U_ZERO_ERROR; UnicodeString pat = UNICODE_STRING_SIMPLE("00#"); DecimalFormat *df = new DecimalFormat(pat,fs); UnicodeString id; id.remove(); df->format(code,id); delete df; r = (Region *)uhash_get(regionAliases,&id); } if ( !r ) { status = U_ILLEGAL_ARGUMENT_ERROR; return NULL; } if ( r->type == URGN_DEPRECATED && r->preferredValues->size() == 1) { StringEnumeration *pv = r->getPreferredValues(); pv->reset(status); const UnicodeString *ustr = pv->snext(status); r = (Region *)uhash_get(regionIDMap,(void *)ustr); delete pv; } return r; }
/** * Returns a pointer to a Region using the given region code. The region code can be either 2-letter ISO code, * 3-letter ISO code, UNM.49 numeric code, or other valid Unicode Region Code as defined by the LDML specification. * The identifier will be canonicalized internally using the supplemental metadata as defined in the CLDR. * If the region code is NULL or not recognized, the appropriate error code will be set ( U_ILLEGAL_ARGUMENT_ERROR ) */ const Region* U_EXPORT2 Region::getInstance(const char *region_code, UErrorCode &status) { if ( !region_code ) { status = U_ILLEGAL_ARGUMENT_ERROR; return NULL; } loadRegionData(); UnicodeString regionCodeString = UnicodeString(region_code); Region *r = (Region *)uhash_get(regionIDMap,(void *)®ionCodeString); if ( !r ) { r = (Region *)uhash_get(regionAliases,(void *)®ionCodeString); } if ( !r ) { // Unknown region code status = U_ILLEGAL_ARGUMENT_ERROR; return NULL; } if ( r->type == URGN_DEPRECATED && r->preferredValues->size() == 1) { StringEnumeration *pv = r->getPreferredValues(); pv->reset(status); const UnicodeString *ustr = pv->snext(status); r = (Region *)uhash_get(regionIDMap,(void *)ustr); delete pv; } return r; }
CollData *CollDataCache::get(UCollator *collator, UErrorCode &status) { char keyBuffer[KEY_BUFFER_SIZE]; int32_t keyLength = KEY_BUFFER_SIZE; char *key = getKey(collator, keyBuffer, &keyLength); CollData *result = NULL, *newData = NULL; CollDataCacheEntry *entry = NULL, *newEntry = NULL; umtx_lock(&lock); entry = (CollDataCacheEntry *) uhash_get(cache, key); if (entry == NULL) { umtx_unlock(&lock); newData = new CollData(collator, key, keyLength, status); newEntry = new CollDataCacheEntry(newData); if (U_FAILURE(status) || newData == NULL || newEntry == NULL) { status = U_MEMORY_ALLOCATION_ERROR; return NULL; } umtx_lock(&lock); entry = (CollDataCacheEntry *) uhash_get(cache, key); if (entry == NULL) { uhash_put(cache, newData->key, newEntry, &status); umtx_unlock(&lock); if (U_FAILURE(status)) { delete newEntry; delete newData; return NULL; } return newData; } } result = entry->data; entry->refCount += 1; umtx_unlock(&lock); if (key != keyBuffer) { deleteKey(key); } if (newEntry != NULL) { delete newEntry; delete newData; } return result; }
// getCDFUnitFallback returns a pointer to the prefix-suffix pair for a given // variant and log10 value within table. If the given variant doesn't exist, it // falls back to the OTHER variant. Therefore, this method will always return // some non-NULL value. static const CDFUnit* getCDFUnitFallback(const UHashtable* table, const UnicodeString& variant, int32_t log10Value) { CharString cvariant; UErrorCode status = U_ZERO_ERROR; const CDFUnit *cdfUnit = NULL; cvariant.appendInvariantChars(variant, status); if (!U_FAILURE(status)) { cdfUnit = (const CDFUnit*) uhash_get(table, cvariant.data()); } if (cdfUnit == NULL) { cdfUnit = (const CDFUnit*) uhash_get(table, gOther); } return &cdfUnit[log10Value]; }
UnicodeString& U_EXPORT2 ZoneMeta::getZoneIdByMetazone(const UnicodeString &mzid, const UnicodeString ®ion, UnicodeString &result) { initializeMetaToOlson(); UBool isSet = FALSE; if (gMetaToOlson != NULL) { UErrorCode status = U_ZERO_ERROR; UChar mzidUChars[ZID_KEY_MAX]; mzid.extract(mzidUChars, ZID_KEY_MAX, status); if (U_SUCCESS(status) && status!=U_STRING_NOT_TERMINATED_WARNING) { UVector *mappings = (UVector*)uhash_get(gMetaToOlson, mzidUChars); if (mappings != NULL) { // Find a preferred time zone for the given region. for (int32_t i = 0; i < mappings->size(); i++) { MetaToOlsonMappingEntry *olsonmap = (MetaToOlsonMappingEntry*)mappings->elementAt(i); if (region.compare(olsonmap->territory, -1) == 0) { result.setTo(olsonmap->id); isSet = TRUE; break; } else if (u_strcmp(olsonmap->territory, gWorld) == 0) { result.setTo(olsonmap->id); isSet = TRUE; } } } } } if (!isSet) { result.remove(); } return result; }
// // RBBISymbolTable::lookup This function from the abstract symbol table inteface // looks up a variable name and returns a UnicodeString // containing the substitution text. // // The variable name does NOT include the leading $. // const UnicodeString * RBBISymbolTable::lookup(const UnicodeString & s) const { RBBISymbolTableEntry * el; RBBINode * varRefNode; RBBINode * exprNode; RBBINode * usetNode; const UnicodeString * retString; RBBISymbolTable * This = (RBBISymbolTable *)this; // cast off const el = (RBBISymbolTableEntry *)uhash_get(fHashTable, &s); if (el == NULL) { return NULL; } varRefNode = el->val; exprNode = varRefNode->fLeftChild; // Root node of expression for variable if (exprNode->fType == RBBINode::setRef) { // The $variable refers to a single UnicodeSet // return the ffffString, which will subsequently be interpreted as a // stand-in character for the set by RBBISymbolTable::lookupMatcher() usetNode = exprNode->fLeftChild; This->fCachedSetLookup = usetNode->fInputSet; retString = &ffffString; } else { // The variable refers to something other than just a set. // return the original source string for the expression retString = &exprNode->fText; This->fCachedSetLookup = NULL; } return retString; }
const UChar *ZNStringPool::get(const UChar *s, UErrorCode &status) { const UChar *pooledString; if (U_FAILURE(status)) { return &EmptyString; } pooledString = static_cast<UChar *>(uhash_get(fHash, s)); if (pooledString != NULL) { return pooledString; } int32_t length = u_strlen(s); int32_t remainingLength = POOL_CHUNK_SIZE - fChunks->fLimit; if (remainingLength <= length) { U_ASSERT(length < POOL_CHUNK_SIZE); if (length >= POOL_CHUNK_SIZE) { status = U_INTERNAL_PROGRAM_ERROR; return &EmptyString; } ZNStringPoolChunk *oldChunk = fChunks; fChunks = new ZNStringPoolChunk; if (fChunks == NULL) { status = U_MEMORY_ALLOCATION_ERROR; return &EmptyString; } fChunks->fNext = oldChunk; } UChar *destString = &fChunks->fStrings[fChunks->fLimit]; u_strcpy(destString, s); fChunks->fLimit += (length + 1); uhash_put(fHash, destString, destString, &status); return destString; }
// // RBBISymbolTable::addEntry Add a new entry to the symbol table. // Indicate an error if the name already exists - // this will only occur in the case of duplicate // variable assignments. // void RBBISymbolTable::addEntry(const UnicodeString & key, RBBINode * val, UErrorCode & err) { RBBISymbolTableEntry * e; /* test for buffer overflows */ if (U_FAILURE(err)) { return; } e = (RBBISymbolTableEntry *)uhash_get(fHashTable, &key); if (e != NULL) { err = U_BRK_VARIABLE_REDFINITION; return; } e = new RBBISymbolTableEntry; if (e == NULL) { err = U_MEMORY_ALLOCATION_ERROR; return; } e->key = key; e->val = val; uhash_put(fHashTable, &e->key, e, &err); }
// fillInMissing ensures that the data in result is complete. // result data is complete if for each variant in result, there exists // a prefix-suffix pair for each log10 value and there also exists // a divisor for each log10 value. // // First this function figures out for which log10 values, the other // variant already had data. These are the same log10 values defined // in CLDR. // // For each log10 value not defined in CLDR, it uses the divisor for // the last defined log10 value or 1. // // Then for each variant, it does the following. For each log10 // value not defined in CLDR, copy the prefix-suffix pair from the // previous log10 value. If log10 value is defined in CLDR but is // missing from given variant, copy the prefix-suffix pair for that // log10 value from the 'other' variant. static void fillInMissing(CDFLocaleStyleData* result) { const CDFUnit* otherUnits = (const CDFUnit*) uhash_get(result->unitsByVariant, gOther); UBool definedInCLDR[MAX_DIGITS]; double lastDivisor = 1.0; for (int32_t i = 0; i < MAX_DIGITS; ++i) { if (!otherUnits[i].isSet()) { result->divisors[i] = lastDivisor; definedInCLDR[i] = FALSE; } else { lastDivisor = result->divisors[i]; definedInCLDR[i] = TRUE; } } // Iterate over each variant. int32_t pos = UHASH_FIRST; const UHashElement* element = uhash_nextElement(result->unitsByVariant, &pos); for (;element != NULL; element = uhash_nextElement(result->unitsByVariant, &pos)) { CDFUnit* units = (CDFUnit*) element->value.pointer; for (int32_t i = 0; i < MAX_DIGITS; ++i) { if (definedInCLDR[i]) { if (!units[i].isSet()) { units[i] = otherUnits[i]; } } else { if (i == 0) { units[0].markAsSet(); } else { units[i] = units[i - 1]; } } } } }
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; } }
//---------------------------------------------------------------------------------------- // // findSetFor given a UnicodeString, // - find the corresponding Unicode Set (uset node) // (create one if necessary) // - Set fLeftChild of the caller's node (should be a setRef node) // to the uset node // Maintain a hash table of uset nodes, so the same one is always used // for the same string. // If a "to adopt" set is provided and we haven't seen this key before, // add the provided set to the hash table. // If the string is one (32 bit) char in length, the set contains // just one element which is the char in question. // If the string is "any", return a set containing all chars. // //---------------------------------------------------------------------------------------- void RBBIRuleScanner::findSetFor(const UnicodeString &s, RBBINode *node, UnicodeSet *setToAdopt) { RBBISetTableEl *el; // First check whether we've already cached a set for this string. // If so, just use the cached set in the new node. // delete any set provided by the caller, since we own it. el = (RBBISetTableEl *)uhash_get(fSetTable, &s); if (el != NULL) { delete setToAdopt; node->fLeftChild = el->val; U_ASSERT(node->fLeftChild->fType == RBBINode::uset); return; } // Haven't seen this set before. // If the caller didn't provide us with a prebuilt set, // create a new UnicodeSet now. if (setToAdopt == NULL) { if (s.compare(kAny, -1) == 0) { setToAdopt = new UnicodeSet(0x000000, 0x10ffff); } else { UChar32 c; c = s.char32At(0); setToAdopt = new UnicodeSet(c, c); } } // // Make a new uset node to refer to this UnicodeSet // This new uset node becomes the child of the caller's setReference node. // RBBINode *usetNode = new RBBINode(RBBINode::uset); usetNode->fInputSet = setToAdopt; usetNode->fParent = node; node->fLeftChild = usetNode; usetNode->fText = s; // // Add the new uset node to the list of all uset nodes. // fRB->fUSetNodes->addElement(usetNode, *fRB->fStatus); // // Add the new set to the set hash table. // el = (RBBISetTableEl *)uprv_malloc(sizeof(RBBISetTableEl)); UnicodeString *tkey = new UnicodeString(s); if (tkey == NULL || el == NULL || setToAdopt == NULL) { error(U_MEMORY_ALLOCATION_ERROR); return; } el->key = tkey; el->val = usetNode; uhash_put(fSetTable, el->key, el, fRB->fStatus); return; }
// Checks to make sure that an "other" variant is present in all // powers of 10. static void checkForOtherVariants(CDFLocaleStyleData* result, UErrorCode& status) { if (result == NULL || result->unitsByVariant == NULL) { return; } const CDFUnit* otherByBase = (const CDFUnit*) uhash_get(result->unitsByVariant, gOther); if (otherByBase == NULL) { status = U_INTERNAL_PROGRAM_ERROR; return; } // Check all other plural variants, and make sure that if // any of them are populated, then other is also populated int32_t pos = UHASH_FIRST; const UHashElement* element; while ((element = uhash_nextElement(result->unitsByVariant, &pos)) != NULL) { CDFUnit* variantsByBase = (CDFUnit*) element->value.pointer; if (variantsByBase == otherByBase) continue; for (int32_t log10Value = 0; log10Value < MAX_DIGITS; ++log10Value) { if (variantsByBase[log10Value].isSet() && !otherByBase[log10Value].isSet()) { status = U_INTERNAL_PROGRAM_ERROR; return; } } } }
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; }
const UChar* ZoneMeta::findMetaZoneID(const UnicodeString& mzid) { umtx_initOnce(gMetaZoneIDsInitOnce, &initAvailableMetaZoneIDs); if (gMetaZoneIDTable == NULL) { return NULL; } return (const UChar*)uhash_get(gMetaZoneIDTable, &mzid); }
// 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_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 && keyData->specialTypes & SPECIALTYPE_RG_KEY_VALUE) { matched = isSpecialTypeRgKeyValue(type); } if (matched) { if (isSpecialType != NULL) { *isSpecialType = TRUE; } return type; } } } return NULL; }
/** * Returns a pointer to a Region using the given numeric region code. If the numeric region code is not recognized, * the appropriate error code will be set ( U_ILLEGAL_ARGUMENT_ERROR ). */ const Region* U_EXPORT2 Region::getInstance (int32_t code, UErrorCode &status) { umtx_initOnce(gRegionDataInitOnce, &loadRegionData, status); if (U_FAILURE(status)) { return NULL; } Region *r = (Region *)uhash_iget(numericCodeMap,code); if ( !r ) { // Just in case there's an alias that's numeric, try to find it. UnicodeString pat = UNICODE_STRING_SIMPLE("0"); LocalPointer<DecimalFormat> df(new DecimalFormat(pat,status), status); if( U_FAILURE(status) ) { return NULL; } UnicodeString id; id.remove(); FieldPosition posIter; df->format(code,id, posIter, status); r = (Region *)uhash_get(regionAliases,&id); } if( U_FAILURE(status) ) { return NULL; } if ( !r ) { status = U_ILLEGAL_ARGUMENT_ERROR; return NULL; } if ( r->type == URGN_DEPRECATED && r->preferredValues->size() == 1) { StringEnumeration *pv = r->getPreferredValues(status); pv->reset(status); const UnicodeString *ustr = pv->snext(status); r = (Region *)uhash_get(regionIDMap,(void *)ustr); delete pv; } return r; }
SPUString *SPUStringPool::addString(UnicodeString *src, UErrorCode &status) { SPUString *hashedString = static_cast<SPUString *>(uhash_get(fHash, src)); if (hashedString != NULL) { delete src; } else { hashedString = new SPUString(src); uhash_put(fHash, src, hashedString, &status); fVec->addElement(hashedString, status); } return hashedString; }
// // RBBISymbolTable::lookupNode Given a key (a variable name), return the // corresponding RBBI Node. If there is no entry // in the table for this name, return NULL. // RBBINode *RBBISymbolTable::lookupNode(const UnicodeString &key) const{ RBBINode *retNode = NULL; RBBISymbolTableEntry *el; el = (RBBISymbolTableEntry *)uhash_get(fHashTable, &key); if (el != NULL) { retNode = el->val; } return retNode; }
void CollDataCache::unref(CollData *collData) { CollDataCacheEntry *entry = NULL; umtx_lock(&lock); entry = (CollDataCacheEntry *) uhash_get(cache, collData->key); if (entry != NULL) { entry->refCount -= 1; } umtx_unlock(&lock); }
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; }
const GenderInfo* GenderInfo::getInstance(const Locale& locale, UErrorCode& status) { // Make sure our cache exists. umtx_initOnce(gGenderInitOnce, &GenderInfo_initCache, status); if (U_FAILURE(status)) { return NULL; } const GenderInfo* result = NULL; const char* key = locale.getName(); { Mutex lock(&gGenderMetaLock); result = (const GenderInfo*) uhash_get(gGenderInfoCache, key); } if (result) { return result; } // On cache miss, try to create GenderInfo from CLDR data result = loadInstance(locale, status); if (U_FAILURE(status)) { return NULL; } // Try to put our GenderInfo object in cache. If there is a race condition, // favor the GenderInfo object that is already in the cache. { Mutex lock(&gGenderMetaLock); GenderInfo* temp = (GenderInfo*) uhash_get(gGenderInfoCache, key); if (temp) { result = temp; } else { uhash_put(gGenderInfoCache, uprv_strdup(key), (void*) result, &status); if (U_FAILURE(status)) { return NULL; } } } return result; }
const CanonicalMapEntry* U_EXPORT2 ZoneMeta::getCanonicalInfo(const UnicodeString &tzid) { initializeCanonicalMap(); CanonicalMapEntry *entry = NULL; if (gCanonicalMap != NULL) { UErrorCode status = U_ZERO_ERROR; UChar tzidUChars[ZID_KEY_MAX]; tzid.extract(tzidUChars, ZID_KEY_MAX, status); if (U_SUCCESS(status) && status!=U_STRING_NOT_TERMINATED_WARNING) { entry = (CanonicalMapEntry*)uhash_get(gCanonicalMap, tzidUChars); } } return entry; }
const UVector* U_EXPORT2 ZoneMeta::getMetazoneMappings(const UnicodeString &tzid) { initializeOlsonToMeta(); const UVector *result = NULL; if (gOlsonToMeta != NULL) { UErrorCode status = U_ZERO_ERROR; UChar tzidUChars[ZID_KEY_MAX]; tzid.extract(tzidUChars, ZID_KEY_MAX, status); if (U_SUCCESS(status) && status!=U_STRING_NOT_TERMINATED_WARNING) { result = (UVector*)uhash_get(gOlsonToMeta, tzidUChars); } } return result; }
// // ZNStringPool::adopt() Put a string into the hash, but do not copy the string data // into the pool's storage. Used for strings from resource bundles, // which will perisist for the life of the zone string formatter, and // therefore can be used directly without copying. const UChar *ZNStringPool::adopt(const UChar * s, UErrorCode &status) { const UChar *pooledString; if (U_FAILURE(status)) { return &EmptyString; } if (s != NULL) { pooledString = static_cast<UChar *>(uhash_get(fHash, s)); if (pooledString == NULL) { UChar *ncs = const_cast<UChar *>(s); uhash_put(fHash, ncs, ncs, &status); } } return s; }
/* gets the shared data from the SHARED_DATA_HASHTABLE (might return NULL if it isn't there) * @param name The name of the shared data * @return the shared data from the SHARED_DATA_HASHTABLE */ static UConverterSharedData * ucnv_getSharedConverterData(const char *name) { /*special case when no Table has yet been created we return NULL */ if (SHARED_DATA_HASHTABLE == NULL) { return NULL; } else { UConverterSharedData *rc; rc = (UConverterSharedData*)uhash_get(SHARED_DATA_HASHTABLE, name); UCNV_DEBUG_LOG("get",name,rc); return rc; } }
// createCDFUnit returns a pointer to the prefix-suffix pair for a given // variant and log10 value within table. If no such prefix-suffix pair is // stored in table, one is created within table before returning pointer. static CDFUnit* createCDFUnit(const char* variant, int32_t log10Value, UHashtable* table, UErrorCode& status) { if (U_FAILURE(status)) { return NULL; } CDFUnit *cdfUnit = (CDFUnit*) uhash_get(table, variant); if (cdfUnit == NULL) { cdfUnit = new CDFUnit[MAX_DIGITS]; if (cdfUnit == NULL) { status = U_MEMORY_ALLOCATION_ERROR; return NULL; } uhash_put(table, uprv_strdup(variant), cdfUnit, &status); if (U_FAILURE(status)) { return NULL; } } CDFUnit* result = &cdfUnit[log10Value]; return result; }
static UDataMemory *udata_findCachedData(const char *path) { UHashtable *htable; UDataMemory *retVal = NULL; DataCacheElement *el; const char *baseName; baseName = findBasename(path); /* Cache remembers only the base name, not the full path. */ htable = udata_getHashTable(); umtx_lock(NULL); el = (DataCacheElement *)uhash_get(htable, baseName); umtx_unlock(NULL); if (el != NULL) { retVal = el->item; } #ifdef UDATA_DEBUG fprintf(stderr, "Cache: [%s] -> %p\n", baseName, retVal); #endif return retVal; }
/** * Returns true if this region contains the supplied other region anywhere in the region hierarchy. */ UBool Region::contains(const Region &other) const { loadRegionData(); if (!containedRegions) { return FALSE; } if (containedRegions->contains((void *)&other.idStr)) { return TRUE; } else { for ( int32_t i = 0 ; i < containedRegions->size() ; i++ ) { UnicodeString *crStr = (UnicodeString *)containedRegions->elementAt(i); Region *cr = (Region *) uhash_get(regionIDMap,(void *)crStr); if ( cr && cr->contains(other) ) { return TRUE; } } } return FALSE; }
/** * Returns true if this region contains the supplied other region anywhere in the region hierarchy. */ UBool Region::contains(const Region &other) const { UErrorCode status = U_ZERO_ERROR; umtx_initOnce(gRegionDataInitOnce, &loadRegionData, status); if (!containedRegions) { return FALSE; } if (containedRegions->contains((void *)&other.idStr)) { return TRUE; } else { for ( int32_t i = 0 ; i < containedRegions->size() ; i++ ) { UnicodeString *crStr = (UnicodeString *)containedRegions->elementAt(i); Region *cr = (Region *) uhash_get(regionIDMap,(void *)crStr); if ( cr && cr->contains(other) ) { return TRUE; } } } return FALSE; }