diff --git a/icu4c/source/common/caniter.cpp b/icu4c/source/common/caniter.cpp index d4768178775..ad09940dee6 100644 --- a/icu4c/source/common/caniter.cpp +++ b/icu4c/source/common/caniter.cpp @@ -294,7 +294,7 @@ void U_EXPORT2 CanonicalIterator::permute(UnicodeString &source, UBool skipZeros for (i = 0; i < source.length(); i += U16_LENGTH(cp)) { cp = source.char32At(i); const UHashElement *ne = NULL; - int32_t el = -1; + int32_t el = UHASH_FIRST; UnicodeString subPermuteString = source; // optimization: @@ -359,7 +359,7 @@ UnicodeString* CanonicalIterator::getEquivalents(const UnicodeString &segment, i // TODO: optimize by not permuting any class zero. const UHashElement *ne = NULL; - int32_t el = -1; + int32_t el = UHASH_FIRST; //Iterator it = basic.iterator(); ne = basic.nextElement(el); //while (it.hasNext()) @@ -370,7 +370,7 @@ UnicodeString* CanonicalIterator::getEquivalents(const UnicodeString &segment, i permutations.removeAll(); permute(item, CANITER_SKIP_ZEROES, &permutations, status); const UHashElement *ne2 = NULL; - int32_t el2 = -1; + int32_t el2 = UHASH_FIRST; //Iterator it2 = permutations.iterator(); ne2 = permutations.nextElement(el2); //while (it2.hasNext()) @@ -416,7 +416,7 @@ UnicodeString* CanonicalIterator::getEquivalents(const UnicodeString &segment, i } //result.toArray(finalResult); result_len = 0; - el = -1; + el = UHASH_FIRST; ne = result.nextElement(el); while(ne != NULL) { finalResult[result_len++] = *((UnicodeString *)(ne->value.pointer)); @@ -463,7 +463,7 @@ Hashtable *CanonicalIterator::getEquivalents2(Hashtable *fillinResult, const UCh UnicodeString prefix(segment, i); prefix += cp2; - int32_t el = -1; + int32_t el = UHASH_FIRST; const UHashElement *ne = remainder.nextElement(el); while (ne != NULL) { UnicodeString item = *((UnicodeString *)(ne->value.pointer)); diff --git a/icu4c/source/common/hash.h b/icu4c/source/common/hash.h index 57467daf218..ab5fbf6c73c 100644 --- a/icu4c/source/common/hash.h +++ b/icu4c/source/common/hash.h @@ -1,6 +1,6 @@ /* ****************************************************************************** -* Copyright (C) 1997-2011, International Business Machines +* Copyright (C) 1997-2014, International Business Machines * Corporation and others. All Rights Reserved. ****************************************************************************** * Date Name Description @@ -85,6 +85,10 @@ public: const UHashElement* find(const UnicodeString& key) const; + /** + * @param pos - must be UHASH_FIRST on first call, and untouched afterwards. + * @see uhash_nextElement + */ const UHashElement* nextElement(int32_t& pos) const; UKeyComparator* setKeyComparator(UKeyComparator*keyComp); diff --git a/icu4c/source/common/rbbistbl.cpp b/icu4c/source/common/rbbistbl.cpp index 804eca72cd4..c2fdf823351 100644 --- a/icu4c/source/common/rbbistbl.cpp +++ b/icu4c/source/common/rbbistbl.cpp @@ -3,7 +3,7 @@ // /* *************************************************************************** -* Copyright (C) 2002-2011 International Business Machines Corporation +* Copyright (C) 2002-2014 International Business Machines Corporation * and others. All rights reserved. *************************************************************************** */ @@ -230,7 +230,7 @@ void RBBISymbolTable::rbbiSymtablePrint() const { "Name Node Val String Val\n" "----------------------------------------------------------------------\n"); - int32_t pos = -1; + int32_t pos = UHASH_FIRST; const UHashElement *e = NULL; for (;;) { e = uhash_nextElement(fHashTable, &pos); diff --git a/icu4c/source/common/serv.cpp b/icu4c/source/common/serv.cpp index 1a8c9166e04..93ae060b617 100644 --- a/icu4c/source/common/serv.cpp +++ b/icu4c/source/common/serv.cpp @@ -1,6 +1,6 @@ /** ******************************************************************************* -* Copyright (C) 2001-2012, International Business Machines Corporation. +* Copyright (C) 2001-2014, International Business Machines Corporation. * All Rights Reserved. ******************************************************************************* */ @@ -102,7 +102,7 @@ UnicodeString& ICUServiceKey::debug(UnicodeString& result) const { debugClass(result); - result.append(" id: "); + result.append((UnicodeString)" id: "); result.append(_id); return result; } @@ -110,7 +110,7 @@ ICUServiceKey::debug(UnicodeString& result) const UnicodeString& ICUServiceKey::debugClass(UnicodeString& result) const { - return result.append("ICUServiceKey"); + return result.append((UnicodeString)"ICUServiceKey"); } #endif @@ -170,17 +170,17 @@ UnicodeString& SimpleFactory::debug(UnicodeString& toAppendTo) const { debugClass(toAppendTo); - toAppendTo.append(" id: "); + toAppendTo.append((UnicodeString)" id: "); toAppendTo.append(_id); - toAppendTo.append(", visible: "); - toAppendTo.append(_visible ? "T" : "F"); + toAppendTo.append((UnicodeString)", visible: "); + toAppendTo.append(_visible ? (UnicodeString)"T" : (UnicodeString)"F"); return toAppendTo; } UnicodeString& SimpleFactory::debugClass(UnicodeString& toAppendTo) const { - return toAppendTo.append("SimpleFactory"); + return toAppendTo.append((UnicodeString)"SimpleFactory"); } #endif @@ -619,7 +619,7 @@ ICUService::getVisibleIDs(UVector& result, const UnicodeString* matchID, UErrorC if (map != NULL) { ICUServiceKey* fallbackKey = createKey(matchID, status); - for (int32_t pos = -1;;) { + for (int32_t pos = UHASH_FIRST;;) { const UHashElement* e = map->nextElement(pos); if (e == NULL) { break; @@ -761,7 +761,7 @@ ICUService::getDisplayNames(UVector& result, return result; } - int32_t pos = -1; + int32_t pos = UHASH_FIRST; const UHashElement* entry = NULL; while ((entry = m->nextElement(pos)) != NULL) { const UnicodeString* id = (const UnicodeString*)entry->key.pointer; @@ -788,7 +788,7 @@ ICUService::getDisplayNames(UVector& result, * nextElement(pos) will skip the position at pos and begin the iteration * at the next position, which in this case will be 0. */ - int32_t pos = -1; + int32_t pos = UHASH_FIRST; const UHashElement *entry = NULL; while ((entry = dnCache->cache.nextElement(pos)) != NULL) { const UnicodeString* id = (const UnicodeString*)entry->value.pointer; diff --git a/icu4c/source/common/servlk.cpp b/icu4c/source/common/servlk.cpp index ab91f768f2a..5968f7b3102 100644 --- a/icu4c/source/common/servlk.cpp +++ b/icu4c/source/common/servlk.cpp @@ -158,13 +158,13 @@ UnicodeString& LocaleKey::debug(UnicodeString& result) const { ICUServiceKey::debug(result); - result.append(" kind: "); + result.append((UnicodeString)" kind: "); result.append(_kind); - result.append(" primaryID: "); + result.append((UnicodeString)" primaryID: "); result.append(_primaryID); - result.append(" fallbackID: "); + result.append((UnicodeString)" fallbackID: "); result.append(_fallbackID); - result.append(" currentID: "); + result.append((UnicodeString)" currentID: "); result.append(_currentID); return result; } @@ -172,7 +172,7 @@ LocaleKey::debug(UnicodeString& result) const UnicodeString& LocaleKey::debugClass(UnicodeString& result) const { - return result.append("LocaleKey "); + return result.append((UnicodeString)"LocaleKey "); } #endif diff --git a/icu4c/source/common/servlkf.cpp b/icu4c/source/common/servlkf.cpp index c455080fdd9..8486c2a811d 100644 --- a/icu4c/source/common/servlkf.cpp +++ b/icu4c/source/common/servlkf.cpp @@ -1,6 +1,6 @@ /** ******************************************************************************* - * Copyright (C) 2001-2005, International Business Machines Corporation and * + * Copyright (C) 2001-2014, International Business Machines Corporation and * * others. All Rights Reserved. * ******************************************************************************* * @@ -71,9 +71,8 @@ LocaleKeyFactory::updateVisibleIDs(Hashtable& result, UErrorCode& status) const const Hashtable* supported = getSupportedIDs(status); if (supported) { UBool visible = (_coverage & 0x1) == 0; - const UHashElement* elem = NULL; - int32_t pos = 0; + int32_t pos = UHASH_FIRST; while ((elem = supported->nextElement(pos)) != NULL) { const UnicodeString& id = *((const UnicodeString*)elem->key.pointer); if (!visible) { @@ -127,9 +126,9 @@ UnicodeString& LocaleKeyFactory::debug(UnicodeString& result) const { debugClass(result); - result.append(", name: "); + result.append((UnicodeString)", name: "); result.append(_name); - result.append(", coverage: "); + result.append((UnicodeString)", coverage: "); result.append(_coverage); return result; } @@ -137,7 +136,7 @@ LocaleKeyFactory::debug(UnicodeString& result) const UnicodeString& LocaleKeyFactory::debugClass(UnicodeString& result) const { - return result.append("LocaleKeyFactory"); + return result.append((UnicodeString)"LocaleKeyFactory"); } #endif diff --git a/icu4c/source/common/servnotf.h b/icu4c/source/common/servnotf.h index 4fae2f3981b..362696f5388 100644 --- a/icu4c/source/common/servnotf.h +++ b/icu4c/source/common/servnotf.h @@ -1,6 +1,6 @@ /** ******************************************************************************* - * Copyright (C) 2001-2011, International Business Machines Corporation and * + * Copyright (C) 2001-2014, International Business Machines Corporation and * * others. All Rights Reserved. * ******************************************************************************* */ @@ -47,7 +47,7 @@ public: } virtual UnicodeString& debugClass(UnicodeString& result) const { - return result.append("Key"); + return result.append((UnicodeString)"Key"); } #endif }; diff --git a/icu4c/source/common/servrbf.cpp b/icu4c/source/common/servrbf.cpp index 3a0227f76af..4295d03553f 100644 --- a/icu4c/source/common/servrbf.cpp +++ b/icu4c/source/common/servrbf.cpp @@ -1,6 +1,6 @@ /** ******************************************************************************* - * Copyright (C) 2001-2005, International Business Machines Corporation and * + * Copyright (C) 2001-2014, International Business Machines Corporation and * * others. All Rights Reserved. * ******************************************************************************* * @@ -73,14 +73,14 @@ UnicodeString& ICUResourceBundleFactory::debug(UnicodeString& result) const { LocaleKeyFactory::debug(result); - result.append(", bundle: "); + result.append((UnicodeString)", bundle: "); return result.append(_bundleName); } UnicodeString& ICUResourceBundleFactory::debugClass(UnicodeString& result) const { - return result.append("ICUResourceBundleFactory"); + return result.append((UnicodeString)"ICUResourceBundleFactory"); } #endif diff --git a/icu4c/source/common/servslkf.cpp b/icu4c/source/common/servslkf.cpp index 583f375a2c4..4222d2130ab 100644 --- a/icu4c/source/common/servslkf.cpp +++ b/icu4c/source/common/servslkf.cpp @@ -97,9 +97,9 @@ UnicodeString& SimpleLocaleKeyFactory::debug(UnicodeString& result) const { LocaleKeyFactory::debug(result); - result.append(", id: "); + result.append((UnicodeString)", id: "); result.append(_id); - result.append(", kind: "); + result.append((UnicodeString)", kind: "); result.append(_kind); return result; } @@ -107,7 +107,7 @@ SimpleLocaleKeyFactory::debug(UnicodeString& result) const UnicodeString& SimpleLocaleKeyFactory::debugClass(UnicodeString& result) const { - return result.append("SimpleLocaleKeyFactory"); + return result.append((UnicodeString)"SimpleLocaleKeyFactory"); } #endif diff --git a/icu4c/source/common/ucnv_bld.cpp b/icu4c/source/common/ucnv_bld.cpp index 4940310f1f6..e75926ec544 100644 --- a/icu4c/source/common/ucnv_bld.cpp +++ b/icu4c/source/common/ucnv_bld.cpp @@ -1,7 +1,7 @@ /* ******************************************************************** * COPYRIGHT: - * Copyright (c) 1996-2013, International Business Machines Corporation and + * Copyright (c) 1996-2014, International Business Machines Corporation and * others. All Rights Reserved. ******************************************************************** * @@ -1086,7 +1086,7 @@ ucnv_flushCache () i = 0; do { remaining = 0; - pos = -1; + pos = UHASH_FIRST; while ((e = uhash_nextElement (SHARED_DATA_HASHTABLE, &pos)) != NULL) { mySharedData = (UConverterSharedData *) e->value.pointer; diff --git a/icu4c/source/common/uhash.c b/icu4c/source/common/uhash.c index 5dd6ba3441c..400157dc92b 100644 --- a/icu4c/source/common/uhash.c +++ b/icu4c/source/common/uhash.c @@ -1,6 +1,6 @@ /* ****************************************************************************** -* Copyright (C) 1997-2011, International Business Machines +* Copyright (C) 1997-2014, International Business Machines * Corporation and others. All Rights Reserved. ****************************************************************************** * Date Name Description @@ -575,7 +575,7 @@ uhash_close(UHashtable *hash) { } if (hash->elements != NULL) { if (hash->keyDeleter != NULL || hash->valueDeleter != NULL) { - int32_t pos=-1; + int32_t pos=UHASH_FIRST; UHashElement *e; while ((e = (UHashElement*) uhash_nextElement(hash, &pos)) != NULL) { HASH_DELETE_KEY_VALUE(hash, e->key.pointer, e->value.pointer); @@ -756,7 +756,7 @@ uhash_iremovei(UHashtable *hash, U_CAPI void U_EXPORT2 uhash_removeAll(UHashtable *hash) { - int32_t pos = -1; + int32_t pos = UHASH_FIRST; const UHashElement *e; U_ASSERT(hash != NULL); if (hash->count != 0) { @@ -885,7 +885,7 @@ uhash_equals(const UHashtable* hash1, const UHashtable* hash2){ return FALSE; } - pos=-1; + pos=UHASH_FIRST; for(i=0; ikey; diff --git a/icu4c/source/common/uhash.h b/icu4c/source/common/uhash.h index ec4c630dc7d..c400c328822 100644 --- a/icu4c/source/common/uhash.h +++ b/icu4c/source/common/uhash.h @@ -1,6 +1,6 @@ /* ****************************************************************************** -* Copyright (C) 1997-2011, International Business Machines +* Copyright (C) 1997-2014, International Business Machines * Corporation and others. All Rights Reserved. ****************************************************************************** * Date Name Description @@ -484,6 +484,13 @@ uhash_removeAll(UHashtable *hash); U_CAPI const UHashElement* U_EXPORT2 uhash_find(const UHashtable *hash, const void* key); +/** + * \def UHASH_FIRST + * Constant for use with uhash_nextElement + * @see uhash_nextElement + */ +#define UHASH_FIRST (-1) + /** * Iterate through the elements of a UHashtable. The caller must not * modify the returned object. However, uhash_removeElement() may be @@ -492,7 +499,7 @@ uhash_find(const UHashtable *hash, const void* key); * called during iteration the iteration will then be out of sync and * should be restarted. * @param hash The target UHashtable. - * @param pos This should be set to -1 initially, and left untouched + * @param pos This should be set to UHASH_FIRST initially, and left untouched * thereafter. * @return a hash element, or NULL if no further key-value pairs * exist in the table. diff --git a/icu4c/source/common/unifiedcache.cpp b/icu4c/source/common/unifiedcache.cpp index ab9a3bbebb0..32899af73e9 100644 --- a/icu4c/source/common/unifiedcache.cpp +++ b/icu4c/source/common/unifiedcache.cpp @@ -147,7 +147,7 @@ void UnifiedCache::dumpContents() const { // On entry, gCacheMutex must be held. // On exit, cache contents dumped to stderr. void UnifiedCache::_dumpContents() const { - int32_t pos = -1; + int32_t pos = UHASH_FIRST; const UHashElement *element = uhash_nextElement(fHashtable, &pos); char buffer[256]; int32_t cnt = 0; @@ -193,7 +193,7 @@ UnifiedCache::~UnifiedCache() { // Returns TRUE if any value in cache was flushed or FALSE otherwise. UBool UnifiedCache::_flush(UBool all) const { UBool result = FALSE; - int32_t pos = -1; + int32_t pos = UHASH_FIRST; const UHashElement *element = uhash_nextElement(fHashtable, &pos); for (; element != NULL; element = uhash_nextElement(fHashtable, &pos)) { const SharedObject *sharedObject = diff --git a/icu4c/source/common/uresbund.cpp b/icu4c/source/common/uresbund.cpp index cce226fb3d5..f4b3bd4f037 100644 --- a/icu4c/source/common/uresbund.cpp +++ b/icu4c/source/common/uresbund.cpp @@ -187,7 +187,7 @@ static int32_t ures_flushCache() do { deletedMore = FALSE; /*creates an enumeration to iterate through every element in the table */ - pos = -1; + pos = UHASH_FIRST; while ((e = uhash_nextElement(cache, &pos)) != NULL) { resB = (UResourceDataEntry *) e->value.pointer; @@ -222,7 +222,7 @@ static int32_t ures_flushCache() U_CAPI UBool U_EXPORT2 ures_dumpCacheContents(void) { UBool cacheNotEmpty = FALSE; - int32_t pos = -1; + int32_t pos = UHASH_FIRST; const UHashElement *e; UResourceDataEntry *resB; diff --git a/icu4c/source/common/usprep.cpp b/icu4c/source/common/usprep.cpp index dd0b101d745..c1bd514065d 100644 --- a/icu4c/source/common/usprep.cpp +++ b/icu4c/source/common/usprep.cpp @@ -136,7 +136,7 @@ static int32_t usprep_internal_flushCache(UBool noRefCount){ UStringPrepProfile *profile = NULL; UStringPrepKey *key = NULL; - int32_t pos = -1; + int32_t pos = UHASH_FIRST; int32_t deletedNum = 0; const UHashElement *e; diff --git a/icu4c/source/i18n/compactdecimalformat.cpp b/icu4c/source/i18n/compactdecimalformat.cpp index 74d9c04191c..cd463ea2a3b 100644 --- a/icu4c/source/i18n/compactdecimalformat.cpp +++ b/icu4c/source/i18n/compactdecimalformat.cpp @@ -868,7 +868,7 @@ static void fillInMissing(CDFLocaleStyleData* result) { } } // Iterate over each variant. - int32_t pos = -1; + 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; diff --git a/icu4c/source/i18n/currpinf.cpp b/icu4c/source/i18n/currpinf.cpp index db81218c7dd..9a0bb4b2b9e 100644 --- a/icu4c/source/i18n/currpinf.cpp +++ b/icu4c/source/i18n/currpinf.cpp @@ -1,6 +1,6 @@ /* ******************************************************************************* - * Copyright (C) 2009-2011, International Business Machines Corporation and + * Copyright (C) 2009-2014, International Business Machines Corporation and * others. All Rights Reserved. ******************************************************************************* */ @@ -338,7 +338,7 @@ CurrencyPluralInfo::deleteHash(Hashtable* hTable) if ( hTable == NULL ) { return; } - int32_t pos = -1; + int32_t pos = UHASH_FIRST; const UHashElement* element = NULL; while ( (element = hTable->nextElement(pos)) != NULL ) { const UHashTok valueTok = element->value; @@ -376,7 +376,7 @@ CurrencyPluralInfo::copyHash(const Hashtable* source, if ( U_FAILURE(status) ) { return; } - int32_t pos = -1; + int32_t pos = UHASH_FIRST; const UHashElement* element = NULL; if ( source ) { while ( (element = source->nextElement(pos)) != NULL ) { diff --git a/icu4c/source/i18n/decimfmt.cpp b/icu4c/source/i18n/decimfmt.cpp index bc49f0ef418..86543d41ed1 100644 --- a/icu4c/source/i18n/decimfmt.cpp +++ b/icu4c/source/i18n/decimfmt.cpp @@ -636,7 +636,7 @@ DecimalFormat::setupCurrencyAffixPatterns(UErrorCode& status) { // save the unique currency plural patterns of this locale. Hashtable* pluralPtn = fCurrencyPluralInfo->fPluralCountToCurrencyUnitPattern; const UHashElement* element = NULL; - int32_t pos = -1; + int32_t pos = UHASH_FIRST; Hashtable pluralPatternSet; while ((element = pluralPtn->nextElement(pos)) != NULL) { const UHashTok valueTok = element->value; @@ -2391,7 +2391,7 @@ DecimalFormat::parseForCurrency(const UnicodeString& text, } // Then, parse against affix patterns. // Those are currency patterns and currency plural patterns. - int32_t pos = -1; + int32_t pos = UHASH_FIRST; const UHashElement* element = NULL; while ( (element = fAffixPatternsForCurrency->nextElement(pos)) != NULL ) { const UHashTok valueTok = element->value; @@ -5347,7 +5347,7 @@ DecimalFormat::deleteHashForAffix(Hashtable*& table) if ( table == NULL ) { return; } - int32_t pos = -1; + int32_t pos = UHASH_FIRST; const UHashElement* element = NULL; while ( (element = table->nextElement(pos)) != NULL ) { const UHashTok valueTok = element->value; @@ -5366,7 +5366,7 @@ DecimalFormat::deleteHashForAffixPattern() if ( fAffixPatternsForCurrency == NULL ) { return; } - int32_t pos = -1; + int32_t pos = UHASH_FIRST; const UHashElement* element = NULL; while ( (element = fAffixPatternsForCurrency->nextElement(pos)) != NULL ) { const UHashTok valueTok = element->value; @@ -5385,7 +5385,7 @@ DecimalFormat::copyHashForAffixPattern(const Hashtable* source, if ( U_FAILURE(status) ) { return; } - int32_t pos = -1; + int32_t pos = UHASH_FIRST; const UHashElement* element = NULL; if ( source ) { while ( (element = source->nextElement(pos)) != NULL ) { @@ -5645,7 +5645,7 @@ DecimalFormat::copyHashForAffix(const Hashtable* source, if ( U_FAILURE(status) ) { return; } - int32_t pos = -1; + int32_t pos = UHASH_FIRST; const UHashElement* element = NULL; if ( source ) { while ( (element = source->nextElement(pos)) != NULL ) { diff --git a/icu4c/source/i18n/dtitvinf.cpp b/icu4c/source/i18n/dtitvinf.cpp index 65be28469be..51f2d00fe64 100644 --- a/icu4c/source/i18n/dtitvinf.cpp +++ b/icu4c/source/i18n/dtitvinf.cpp @@ -1,5 +1,5 @@ /******************************************************************************* -* Copyright (C) 2008-2012, International Business Machines Corporation and +* Copyright (C) 2008-2014, International Business Machines Corporation and * others. All Rights Reserved. ******************************************************************************* * @@ -481,7 +481,7 @@ DateIntervalInfo::getBestSkeleton(const UnicodeString& skeleton, bestMatchDistanceInfo = 0; int8_t fieldLength = sizeof(skeletonFieldWidth)/sizeof(skeletonFieldWidth[0]); - int32_t pos = -1; + int32_t pos = UHASH_FIRST; const UHashElement* elem = NULL; while ( (elem = fIntervalPatterns->nextElement(pos)) != NULL ) { const UHashTok keyTok = elem->key; @@ -586,7 +586,7 @@ DateIntervalInfo::deleteHash(Hashtable* hTable) if ( hTable == NULL ) { return; } - int32_t pos = -1; + int32_t pos = UHASH_FIRST; const UHashElement* element = NULL; while ( (element = hTable->nextElement(pos)) != NULL ) { const UHashTok valueTok = element->value; @@ -649,7 +649,7 @@ DateIntervalInfo::copyHash(const Hashtable* source, if ( U_FAILURE(status) ) { return; } - int32_t pos = -1; + int32_t pos = UHASH_FIRST; const UHashElement* element = NULL; if ( source ) { while ( (element = source->nextElement(pos)) != NULL ) { diff --git a/icu4c/source/i18n/dtptngen.cpp b/icu4c/source/i18n/dtptngen.cpp index a40263bc713..dc0e9b4a05f 100644 --- a/icu4c/source/i18n/dtptngen.cpp +++ b/icu4c/source/i18n/dtptngen.cpp @@ -1261,7 +1261,7 @@ DateTimePatternGenerator::copyHashtable(Hashtable *other, UErrorCode &status) { if(U_FAILURE(status)){ return; } - int32_t pos = -1; + int32_t pos = UHASH_FIRST; const UHashElement* elem = NULL; // walk through the hash table and create a deep clone while((elem = other->nextElement(pos))!= NULL){ diff --git a/icu4c/source/i18n/identifier_info.cpp b/icu4c/source/i18n/identifier_info.cpp index d4e167c98f1..0c0706f1ccd 100644 --- a/icu4c/source/i18n/identifier_info.cpp +++ b/icu4c/source/i18n/identifier_info.cpp @@ -167,7 +167,7 @@ IdentifierInfo &IdentifierInfo::setIdentifier(const UnicodeString &identifier, U // We also compute any commonalities among the alternates. if (uhash_count(fScriptSetSet) > 0) { fCommonAmongAlternates->setAll(); - for (int32_t it = -1;;) { + for (int32_t it = UHASH_FIRST;;) { const UHashElement *nextHashEl = uhash_nextElement(fScriptSetSet, &it); if (nextHashEl == NULL) { break; @@ -179,7 +179,7 @@ IdentifierInfo &IdentifierInfo::setIdentifier(const UnicodeString &identifier, U } else { fCommonAmongAlternates->intersect(*next); // [[Arab Syrc Thaa]; [Arab Syrc]] => [[Arab Syrc]] - for (int32_t otherIt = -1;;) { + for (int32_t otherIt = UHASH_FIRST;;) { const UHashElement *otherHashEl = uhash_nextElement(fScriptSetSet, &otherIt); if (otherHashEl == NULL) { break; @@ -269,7 +269,7 @@ UBool IdentifierInfo::containsWithAlternates(const ScriptSet &container, const S if (!container.contains(containee)) { return FALSE; } - for (int32_t iter = -1; ;) { + for (int32_t iter = UHASH_FIRST; ;) { const UHashElement *hashEl = uhash_nextElement(fScriptSetSet, &iter); if (hashEl == NULL) { break; @@ -287,7 +287,7 @@ UnicodeString &IdentifierInfo::displayAlternates(UnicodeString &dest, const UHas if (U_FAILURE(status)) { return dest; } - for (int32_t pos = -1; ;) { + for (int32_t pos = UHASH_FIRST; ;) { const UHashElement *el = uhash_nextElement(alternates, &pos); if (el == NULL) { break; diff --git a/icu4c/source/i18n/msgfmt.cpp b/icu4c/source/i18n/msgfmt.cpp index 853a64ca4ba..32d9bc7d35d 100644 --- a/icu4c/source/i18n/msgfmt.cpp +++ b/icu4c/source/i18n/msgfmt.cpp @@ -413,7 +413,7 @@ MessageFormat::operator==(const Format& rhs) const if (count != rhs_count) { return FALSE; } - int32_t idx = 0, rhs_idx = 0, pos = -1, rhs_pos = -1; + int32_t idx = 0, rhs_idx = 0, pos = UHASH_FIRST, rhs_pos = UHASH_FIRST; for (; idx < count && rhs_idx < rhs_count && U_SUCCESS(ec); ++idx, ++rhs_idx) { const UHashElement* cur = uhash_nextElement(customFormatArgStarts, &pos); const UHashElement* rhs_cur = uhash_nextElement(that.customFormatArgStarts, &rhs_pos); @@ -1332,7 +1332,7 @@ void MessageFormat::copyObjects(const MessageFormat& that, UErrorCode& ec) { const int32_t count = uhash_count(that.cachedFormatters); int32_t pos, idx; - for (idx = 0, pos = -1; idx < count && U_SUCCESS(ec); ++idx) { + for (idx = 0, pos = UHASH_FIRST; idx < count && U_SUCCESS(ec); ++idx) { const UHashElement* cur = uhash_nextElement(that.cachedFormatters, &pos); Format* newFormat = ((Format*)(cur->value.pointer))->clone(); if (newFormat) { @@ -1350,7 +1350,7 @@ void MessageFormat::copyObjects(const MessageFormat& that, UErrorCode& ec) { } const int32_t count = uhash_count(that.customFormatArgStarts); int32_t pos, idx; - for (idx = 0, pos = -1; idx < count && U_SUCCESS(ec); ++idx) { + for (idx = 0, pos = UHASH_FIRST; idx < count && U_SUCCESS(ec); ++idx) { const UHashElement* cur = uhash_nextElement(that.customFormatArgStarts, &pos); uhash_iputi(customFormatArgStarts, cur->key.integer, cur->value.integer, &ec); } diff --git a/icu4c/source/i18n/rbt_data.cpp b/icu4c/source/i18n/rbt_data.cpp index cb949e541e2..e3358bfa725 100644 --- a/icu4c/source/i18n/rbt_data.cpp +++ b/icu4c/source/i18n/rbt_data.cpp @@ -42,7 +42,7 @@ TransliterationRuleData::TransliterationRuleData(const TransliterationRuleData& UErrorCode status = U_ZERO_ERROR; int32_t i = 0; variableNames.setValueDeleter(uprv_deleteUObject); - int32_t pos = -1; + int32_t pos = UHASH_FIRST; const UHashElement *e; while ((e = other.variableNames.nextElement(pos)) != 0) { UnicodeString* value = diff --git a/icu4c/source/i18n/rbt_pars.cpp b/icu4c/source/i18n/rbt_pars.cpp index 7e3678b6cfb..cebbe2ac749 100644 --- a/icu4c/source/i18n/rbt_pars.cpp +++ b/icu4c/source/i18n/rbt_pars.cpp @@ -1,6 +1,6 @@ /* ********************************************************************** - * Copyright (C) 1999-2011, International Business Machines + * Copyright (C) 1999-2014, International Business Machines * Corporation and others. All Rights Reserved. ********************************************************************** * Date Name Description @@ -1106,7 +1106,7 @@ void TransliteratorParser::parseRules(const UnicodeString& rule, } data->variableNames.removeAll(); - int32_t pos = -1; + int32_t pos = UHASH_FIRST; const UHashElement* he = variableNames.nextElement(pos); while (he != NULL) { UnicodeString* tempus = (UnicodeString*)(((UnicodeString*)(he->value.pointer))->clone()); diff --git a/icu4c/source/i18n/region.cpp b/icu4c/source/i18n/region.cpp index 02be72d5d5a..2a593b63f8d 100644 --- a/icu4c/source/i18n/region.cpp +++ b/icu4c/source/i18n/region.cpp @@ -305,7 +305,7 @@ void Region::loadRegionData(UErrorCode &status) { } // Create the availableRegions lists - int32_t pos = -1; + int32_t pos = UHASH_FIRST; while ( const UHashElement* element = uhash_nextElement(regionIDMap,&pos)) { Region *ar = (Region *)element->value.pointer; if ( availableRegions[ar->type] == NULL ) { diff --git a/icu4c/source/i18n/tmutfmt.cpp b/icu4c/source/i18n/tmutfmt.cpp index 3251bc85523..b7c16e513bc 100644 --- a/icu4c/source/i18n/tmutfmt.cpp +++ b/icu4c/source/i18n/tmutfmt.cpp @@ -189,7 +189,7 @@ TimeUnitFormat::parseObject(const UnicodeString& source, i < TimeUnit::UTIMEUNIT_FIELD_COUNT; i = (TimeUnit::UTimeUnitFields)(i+1)) { Hashtable* countToPatterns = fTimeUnitToCountToPatterns[i]; - int32_t elemPos = -1; + int32_t elemPos = UHASH_FIRST; const UHashElement* elem = NULL; while ((elem = countToPatterns->nextElement(elemPos)) != NULL){ const UHashTok keyTok = elem->key; @@ -686,7 +686,7 @@ TimeUnitFormat::setNumberFormat(const NumberFormat& format, UErrorCode& status){ void TimeUnitFormat::deleteHash(Hashtable* htable) { - int32_t pos = -1; + int32_t pos = UHASH_FIRST; const UHashElement* element = NULL; if ( htable ) { while ( (element = htable->nextElement(pos)) != NULL ) { @@ -707,7 +707,7 @@ TimeUnitFormat::copyHash(const Hashtable* source, Hashtable* target, UErrorCode& if ( U_FAILURE(status) ) { return; } - int32_t pos = -1; + int32_t pos = UHASH_FIRST; const UHashElement* element = NULL; if ( source ) { while ( (element = source->nextElement(pos)) != NULL ) { diff --git a/icu4c/source/i18n/transreg.cpp b/icu4c/source/i18n/transreg.cpp index 77281511b0b..445a26ac670 100644 --- a/icu4c/source/i18n/transreg.cpp +++ b/icu4c/source/i18n/transreg.cpp @@ -1,6 +1,6 @@ /* ********************************************************************** -* Copyright (c) 2001-2011, International Business Machines +* Copyright (c) 2001-2014, International Business Machines * Corporation and others. All Rights Reserved. ********************************************************************** * Date Name Description @@ -728,7 +728,7 @@ int32_t TransliteratorRegistry::countAvailableSources(void) const { UnicodeString& TransliteratorRegistry::getAvailableSource(int32_t index, UnicodeString& result) const { - int32_t pos = -1; + int32_t pos = UHASH_FIRST; const UHashElement *e = 0; while (index-- >= 0) { e = specDAG.nextElement(pos); @@ -757,7 +757,7 @@ UnicodeString& TransliteratorRegistry::getAvailableTarget(int32_t index, result.truncate(0); // invalid source return result; } - int32_t pos = -1; + int32_t pos = UHASH_FIRST; const UHashElement *e = 0; while (index-- >= 0) { e = targets->nextElement(pos); diff --git a/icu4c/source/i18n/tzgnames.cpp b/icu4c/source/i18n/tzgnames.cpp index e6bd109b749..6741607b6e6 100644 --- a/icu4c/source/i18n/tzgnames.cpp +++ b/icu4c/source/i18n/tzgnames.cpp @@ -1,6 +1,6 @@ /* ******************************************************************************* -* Copyright (C) 2011-2013, International Business Machines Corporation and +* Copyright (C) 2011-2014, International Business Machines Corporation and * others. All Rights Reserved. ******************************************************************************* */ @@ -1185,7 +1185,7 @@ U_CDECL_END * block. */ static void sweepCache() { - int32_t pos = -1; + int32_t pos = UHASH_FIRST; const UHashElement* elem; double now = (double)uprv_getUTCtime(); diff --git a/icu4c/source/i18n/tznames.cpp b/icu4c/source/i18n/tznames.cpp index 57bda37fc66..13f8c4677ae 100644 --- a/icu4c/source/i18n/tznames.cpp +++ b/icu4c/source/i18n/tznames.cpp @@ -81,7 +81,7 @@ U_CDECL_END * block. */ static void sweepCache() { - int32_t pos = -1; + int32_t pos = UHASH_FIRST; const UHashElement* elem; double now = (double)uprv_getUTCtime(); diff --git a/icu4c/source/test/intltest/apicoll.cpp b/icu4c/source/test/intltest/apicoll.cpp index b3d9c7ec8d9..f9a3eb86997 100644 --- a/icu4c/source/test/intltest/apicoll.cpp +++ b/icu4c/source/test/intltest/apicoll.cpp @@ -997,9 +997,6 @@ CollationAPITest::TestCompare(/* char* par */) void CollationAPITest::TestGetAll(/* char* par */) { - if (logKnownIssue("10774","Side effects from utility/LocaleTest/TestGetLocale")) { - return; - } int32_t count1, count2; UErrorCode status = U_ZERO_ERROR; diff --git a/icu4c/source/test/intltest/canittst.cpp b/icu4c/source/test/intltest/canittst.cpp index 5fe7c174e49..cde38a0c768 100644 --- a/icu4c/source/test/intltest/canittst.cpp +++ b/icu4c/source/test/intltest/canittst.cpp @@ -1,6 +1,6 @@ /******************************************************************** * COPYRIGHT: - * Copyright (c) 2002-2012, International Business Machines Corporation and + * Copyright (c) 2002-2014, International Business Machines Corporation and * others. All Rights Reserved. ******************************************************************** * @@ -263,7 +263,7 @@ UnicodeString CanonicalIteratorTest::collectionToString(Hashtable *col) { int32_t i = 0; const UHashElement *ne = NULL; - int32_t el = -1; + int32_t el = UHASH_FIRST; //Iterator it = basic.iterator(); ne = col->nextElement(el); //while (it.hasNext()) diff --git a/icu4c/source/test/intltest/loctest.cpp b/icu4c/source/test/intltest/loctest.cpp index 1bcf77107e6..d8c33144a36 100644 --- a/icu4c/source/test/intltest/loctest.cpp +++ b/icu4c/source/test/intltest/loctest.cpp @@ -16,6 +16,7 @@ #include #include "putilimp.h" #include "unicode/ustring.h" +#include "hash.h" static const char* const rawData[33][8] = { @@ -1832,124 +1833,159 @@ void LocaleTest::TestGetLocale(void) { // Calendar #if !UCONFIG_NO_FORMATTING - req = "en_US_BROOKLYN"; - Calendar* cal = Calendar::createInstance(Locale::createFromName(req), ec); - if (U_FAILURE(ec)) { - dataerrln("FAIL: Calendar::createInstance failed - %s", u_errorName(ec)); - } else { - valid = cal->getLocale(ULOC_VALID_LOCALE, ec); - actual = cal->getLocale(ULOC_ACTUAL_LOCALE, ec); + { + UErrorCode ec = U_ZERO_ERROR; // give each resource type its own error code + req = "en_US_BROOKLYN"; + Calendar* cal = Calendar::createInstance(Locale::createFromName(req), ec); if (U_FAILURE(ec)) { - errln("FAIL: Calendar::getLocale() failed"); + dataerrln("FAIL: Calendar::createInstance failed - %s", u_errorName(ec)); } else { - _checklocs("Calendar", req, valid, actual); + valid = cal->getLocale(ULOC_VALID_LOCALE, ec); + actual = cal->getLocale(ULOC_ACTUAL_LOCALE, ec); + if (U_FAILURE(ec)) { + errln("FAIL: Calendar::getLocale() failed"); + } else { + _checklocs("Calendar", req, valid, actual); + } + /* Make sure that it fails correctly */ + ec = U_FILE_ACCESS_ERROR; + if (cal->getLocale(ULOC_VALID_LOCALE, ec).getName()[0] != 0) { + errln("FAIL: Calendar::getLocale() failed to fail correctly. It should have returned \"\""); + } + ec = U_ZERO_ERROR; } - /* Make sure that it fails correctly */ - ec = U_FILE_ACCESS_ERROR; - if (cal->getLocale(ULOC_VALID_LOCALE, ec).getName()[0] != 0) { - errln("FAIL: Calendar::getLocale() failed to fail correctly. It should have returned \"\""); - } - ec = U_ZERO_ERROR; + delete cal; } - delete cal; #endif // DecimalFormat, DecimalFormatSymbols #if !UCONFIG_NO_FORMATTING - req = "fr_FR_NICE"; - NumberFormat* nf = NumberFormat::createInstance(Locale::createFromName(req), ec); - if (U_FAILURE(ec)) { - dataerrln("FAIL: NumberFormat::createInstance failed - %s", u_errorName(ec)); - } else { - DecimalFormat* dec = dynamic_cast(nf); - if (dec == NULL) { - errln("FAIL: NumberFormat::createInstance does not return a DecimalFormat"); - return; - } - valid = dec->getLocale(ULOC_VALID_LOCALE, ec); - actual = dec->getLocale(ULOC_ACTUAL_LOCALE, ec); + { + UErrorCode ec = U_ZERO_ERROR; // give each resource type its own error code + req = "fr_FR_NICE"; + NumberFormat* nf = NumberFormat::createInstance(Locale::createFromName(req), ec); if (U_FAILURE(ec)) { - errln("FAIL: DecimalFormat::getLocale() failed"); + dataerrln("FAIL: NumberFormat::createInstance failed - %s", u_errorName(ec)); } else { - _checklocs("DecimalFormat", req, valid, actual); - } + DecimalFormat* dec = dynamic_cast(nf); + if (dec == NULL) { + errln("FAIL: NumberFormat::createInstance does not return a DecimalFormat"); + return; + } + valid = dec->getLocale(ULOC_VALID_LOCALE, ec); + actual = dec->getLocale(ULOC_ACTUAL_LOCALE, ec); + if (U_FAILURE(ec)) { + errln("FAIL: DecimalFormat::getLocale() failed"); + } else { + _checklocs("DecimalFormat", req, valid, actual); + } - const DecimalFormatSymbols* sym = dec->getDecimalFormatSymbols(); - if (sym == NULL) { - errln("FAIL: getDecimalFormatSymbols returned NULL"); - return; + const DecimalFormatSymbols* sym = dec->getDecimalFormatSymbols(); + if (sym == NULL) { + errln("FAIL: getDecimalFormatSymbols returned NULL"); + return; + } + valid = sym->getLocale(ULOC_VALID_LOCALE, ec); + actual = sym->getLocale(ULOC_ACTUAL_LOCALE, ec); + if (U_FAILURE(ec)) { + errln("FAIL: DecimalFormatSymbols::getLocale() failed"); + } else { + _checklocs("DecimalFormatSymbols", req, valid, actual); + } } - valid = sym->getLocale(ULOC_VALID_LOCALE, ec); - actual = sym->getLocale(ULOC_ACTUAL_LOCALE, ec); - if (U_FAILURE(ec)) { - errln("FAIL: DecimalFormatSymbols::getLocale() failed"); - } else { - _checklocs("DecimalFormatSymbols", req, valid, actual); - } + delete nf; } - delete nf; #endif // DateFormat, DateFormatSymbols #if !UCONFIG_NO_FORMATTING - req = "de_CH_LUCERNE"; - DateFormat* df = - DateFormat::createDateInstance(DateFormat::kDefault, - Locale::createFromName(req)); - if (df == 0){ - dataerrln("Error calling DateFormat::createDateInstance()"); - } else { - SimpleDateFormat* dat = dynamic_cast(df); - if (dat == NULL) { - errln("FAIL: DateFormat::createInstance does not return a SimpleDateFormat"); - return; - } - valid = dat->getLocale(ULOC_VALID_LOCALE, ec); - actual = dat->getLocale(ULOC_ACTUAL_LOCALE, ec); - if (U_FAILURE(ec)) { - errln("FAIL: SimpleDateFormat::getLocale() failed"); + { + UErrorCode ec = U_ZERO_ERROR; // give each resource type its own error code + req = "de_CH_LUCERNE"; + DateFormat* df = + DateFormat::createDateInstance(DateFormat::kDefault, + Locale::createFromName(req)); + if (df == 0){ + dataerrln("Error calling DateFormat::createDateInstance()"); } else { - _checklocs("SimpleDateFormat", req, valid, actual); - } + SimpleDateFormat* dat = dynamic_cast(df); + if (dat == NULL) { + errln("FAIL: DateFormat::createInstance does not return a SimpleDateFormat"); + return; + } + valid = dat->getLocale(ULOC_VALID_LOCALE, ec); + actual = dat->getLocale(ULOC_ACTUAL_LOCALE, ec); + if (U_FAILURE(ec)) { + errln("FAIL: SimpleDateFormat::getLocale() failed"); + } else { + _checklocs("SimpleDateFormat", req, valid, actual); + } - const DateFormatSymbols* sym = dat->getDateFormatSymbols(); - if (sym == NULL) { - errln("FAIL: getDateFormatSymbols returned NULL"); - return; + const DateFormatSymbols* sym = dat->getDateFormatSymbols(); + if (sym == NULL) { + errln("FAIL: getDateFormatSymbols returned NULL"); + return; + } + valid = sym->getLocale(ULOC_VALID_LOCALE, ec); + actual = sym->getLocale(ULOC_ACTUAL_LOCALE, ec); + if (U_FAILURE(ec)) { + errln("FAIL: DateFormatSymbols::getLocale() failed"); + } else { + _checklocs("DateFormatSymbols", req, valid, actual); + } } - valid = sym->getLocale(ULOC_VALID_LOCALE, ec); - actual = sym->getLocale(ULOC_ACTUAL_LOCALE, ec); - if (U_FAILURE(ec)) { - errln("FAIL: DateFormatSymbols::getLocale() failed"); - } else { - _checklocs("DateFormatSymbols", req, valid, actual); - } + delete df; } - delete df; #endif // BreakIterator #if !UCONFIG_NO_BREAK_ITERATION - req = "es_ES_BARCELONA"; - reqLoc = Locale::createFromName(req); - BreakIterator* brk = BreakIterator::createWordInstance(reqLoc, ec); - if (U_FAILURE(ec)) { - dataerrln("FAIL: BreakIterator::createWordInstance failed - %s", u_errorName(ec)); - } else { - valid = brk->getLocale(ULOC_VALID_LOCALE, ec); - actual = brk->getLocale(ULOC_ACTUAL_LOCALE, ec); + { + UErrorCode ec = U_ZERO_ERROR; // give each resource type its own error code + req = "es_ES_BARCELONA"; + reqLoc = Locale::createFromName(req); + BreakIterator* brk = BreakIterator::createWordInstance(reqLoc, ec); if (U_FAILURE(ec)) { - errln("FAIL: BreakIterator::getLocale() failed"); + dataerrln("FAIL: BreakIterator::createWordInstance failed - %s", u_errorName(ec)); } else { - _checklocs("BreakIterator", req, valid, actual); - } + valid = brk->getLocale(ULOC_VALID_LOCALE, ec); + actual = brk->getLocale(ULOC_ACTUAL_LOCALE, ec); + if (U_FAILURE(ec)) { + errln("FAIL: BreakIterator::getLocale() failed"); + } else { + _checklocs("BreakIterator", req, valid, actual); + } - // After registering something, the behavior should be different - URegistryKey key = BreakIterator::registerInstance(brk, reqLoc, UBRK_WORD, ec); - brk = 0; // registerInstance adopts - if (U_FAILURE(ec)) { - errln("FAIL: BreakIterator::registerInstance() failed"); - } else { + // After registering something, the behavior should be different + URegistryKey key = BreakIterator::registerInstance(brk, reqLoc, UBRK_WORD, ec); + brk = 0; // registerInstance adopts + if (U_FAILURE(ec)) { + errln("FAIL: BreakIterator::registerInstance() failed"); + } else { + brk = BreakIterator::createWordInstance(reqLoc, ec); + if (U_FAILURE(ec)) { + errln("FAIL: BreakIterator::createWordInstance failed"); + } else { + valid = brk->getLocale(ULOC_VALID_LOCALE, ec); + actual = brk->getLocale(ULOC_ACTUAL_LOCALE, ec); + if (U_FAILURE(ec)) { + errln("FAIL: BreakIterator::getLocale() failed"); + } else { + // N.B.: now expect valid==actual==req + _checklocs("BreakIterator(registered)", + req, valid, actual, "eq", "eq"); + } + } + // No matter what, unregister + BreakIterator::unregister(key, ec); + if (U_FAILURE(ec)) { + errln("FAIL: BreakIterator::unregister() failed"); + } + delete brk; + brk = 0; + } + + // After unregistering, should behave normally again brk = BreakIterator::createWordInstance(reqLoc, ec); if (U_FAILURE(ec)) { errln("FAIL: BreakIterator::createWordInstance failed"); @@ -1959,101 +1995,176 @@ void LocaleTest::TestGetLocale(void) { if (U_FAILURE(ec)) { errln("FAIL: BreakIterator::getLocale() failed"); } else { - // N.B.: now expect valid==actual==req - _checklocs("BreakIterator(registered)", - req, valid, actual, "eq", "eq"); + _checklocs("BreakIterator(unregistered)", req, valid, actual); } } - // No matter what, unregister - BreakIterator::unregister(key, ec); - if (U_FAILURE(ec)) { - errln("FAIL: BreakIterator::unregister() failed"); - } - delete brk; - brk = 0; - } - - // After unregistering, should behave normally again - brk = BreakIterator::createWordInstance(reqLoc, ec); - if (U_FAILURE(ec)) { - errln("FAIL: BreakIterator::createWordInstance failed"); - } else { - valid = brk->getLocale(ULOC_VALID_LOCALE, ec); - actual = brk->getLocale(ULOC_ACTUAL_LOCALE, ec); - if (U_FAILURE(ec)) { - errln("FAIL: BreakIterator::getLocale() failed"); - } else { - _checklocs("BreakIterator(unregistered)", req, valid, actual); - } } + delete brk; } - delete brk; #endif // Collator #if !UCONFIG_NO_COLLATION - req = "hi_IN_BHOPAL"; - reqLoc = Locale::createFromName(req); - Collator* coll = Collator::createInstance(reqLoc, ec); - if (U_FAILURE(ec)) { - dataerrln("FAIL: Collator::createInstance failed - %s", u_errorName(ec)); - } else { - valid = coll->getLocale(ULOC_VALID_LOCALE, ec); - actual = coll->getLocale(ULOC_ACTUAL_LOCALE, ec); - if (U_FAILURE(ec)) { - errln("FAIL: Collator::getLocale() failed"); - } else { - _checklocs("Collator", req, valid, actual); - } + { + UErrorCode ec = U_ZERO_ERROR; // give each resource type its own error code - // After registering something, the behavior should be different - URegistryKey key = Collator::registerInstance(coll, reqLoc, ec); - coll = 0; // registerInstance adopts - if (U_FAILURE(ec)) { - errln("FAIL: Collator::registerInstance() failed"); - } else { - coll = Collator::createInstance(reqLoc, ec); - if (U_FAILURE(ec)) { - errln("FAIL: Collator::createWordInstance failed"); - } else { - valid = coll->getLocale(ULOC_VALID_LOCALE, ec); - actual = coll->getLocale(ULOC_ACTUAL_LOCALE, ec); - if (U_FAILURE(ec)) { - errln("FAIL: Collator::getLocale() failed"); - } else { - // N.B.: now expect valid==actual==req - _checklocs("Collator(registered)", - req, valid, actual, "eq", "eq"); - } - } - // No matter what, unregister - Collator::unregister(key, ec); - if (U_FAILURE(ec)) { - errln("FAIL: Collator::unregister() failed"); - } - delete coll; - coll = 0; - } + checkRegisteredCollators(NULL); // Don't expect any extras - // After unregistering, should behave normally again - coll = Collator::createInstance(reqLoc, ec); + req = "hi_IN_BHOPAL"; + reqLoc = Locale::createFromName(req); + Collator* coll = Collator::createInstance(reqLoc, ec); if (U_FAILURE(ec)) { - errln("FAIL: Collator::createInstance failed"); + dataerrln("FAIL: Collator::createInstance failed - %s", u_errorName(ec)); } else { valid = coll->getLocale(ULOC_VALID_LOCALE, ec); actual = coll->getLocale(ULOC_ACTUAL_LOCALE, ec); if (U_FAILURE(ec)) { errln("FAIL: Collator::getLocale() failed"); } else { - _checklocs("Collator(unregistered)", req, valid, actual); + _checklocs("Collator", req, valid, actual); + } + + // After registering something, the behavior should be different + URegistryKey key = Collator::registerInstance(coll, reqLoc, ec); + coll = 0; // registerInstance adopts + if (U_FAILURE(ec)) { + errln("FAIL: Collator::registerInstance() failed"); + } else { + coll = Collator::createInstance(reqLoc, ec); + if (U_FAILURE(ec)) { + errln("FAIL: Collator::createWordInstance failed"); + } else { + valid = coll->getLocale(ULOC_VALID_LOCALE, ec); + actual = coll->getLocale(ULOC_ACTUAL_LOCALE, ec); + if (U_FAILURE(ec)) { + errln("FAIL: Collator::getLocale() failed"); + } else { + // N.B.: now expect valid==actual==req + _checklocs("Collator(registered)", + req, valid, actual, "eq", "eq"); + } + } + checkRegisteredCollators(req); // include hi_IN_BHOPAL + + // No matter what, unregister + Collator::unregister(key, ec); + if (U_FAILURE(ec)) { + errln("FAIL: Collator::unregister() failed"); + } + delete coll; + coll = 0; + } + + // After unregistering, should behave normally again + coll = Collator::createInstance(reqLoc, ec); + if (U_FAILURE(ec)) { + errln("FAIL: Collator::createInstance failed"); + } else { + valid = coll->getLocale(ULOC_VALID_LOCALE, ec); + actual = coll->getLocale(ULOC_ACTUAL_LOCALE, ec); + if (U_FAILURE(ec)) { + errln("FAIL: Collator::getLocale() failed"); + } else { + _checklocs("Collator(unregistered)", req, valid, actual); + } } } + delete coll; + + checkRegisteredCollators(NULL); // extra should be gone again } - delete coll; #endif #endif } +#if !UCONFIG_NO_COLLATION +void LocaleTest::checkRegisteredCollators(const char *expectExtra) { + UErrorCode status = U_ZERO_ERROR; + int32_t count1=0,count2=0; + Hashtable oldHash(status); + Hashtable newHash(status); + TEST_ASSERT_STATUS(status); + + UnicodeString expectStr(expectExtra?expectExtra:"n/a", ""); + + // the 'old' list (non enumeration) + const Locale* oldList = Collator::getAvailableLocales(count1); + if(oldList == NULL) { + errln("Error: Collator::getAvailableLocales(count) returned NULL"); + return; + } + + // the 'new' list (enumeration) + LocalPointer newEnum(Collator::getAvailableLocales()); + if(newEnum.isNull()) { + errln("Error: collator::getAvailableLocales() returned NULL"); + return; + } + + // OK. Let's add all of the OLD + // then check for any in the NEW not in OLD + // then check for any in OLD not in NEW. + + // 1. add all of OLD + for(int32_t i=0;isnext(status)) && U_SUCCESS(status)) { + count2++; + + if(expectExtra != NULL && expectStr == *locStr) { + foundExpected = TRUE; + logln(UnicodeString("Found expected registered collator: ","") + expectStr); + } + + if( oldHash.geti(*locStr) == 0 ) { + if(expectExtra != NULL && expectStr==*locStr) { + logln(UnicodeString("As expected, Collator::getAvailableLocales(count) is missing registered collator ") + expectStr); + } else { + errln(UnicodeString("Error: Collator::getAvailableLocales(count) is missing: ","") + + *locStr); + } + } + newHash.puti(*locStr, 1, status); + } + + // 3. check all of OLD again + for(int32_t i=0;if16BitUnits[0] = 0; utf16Length = 1; ++bundle->f16BitUnitsLength; - for (pos = -1, i = 0; i < count; ++i) { + for (pos = UHASH_FIRST, i = 0; i < count; ++i) { array[i] = (struct SResource *)uhash_nextElement(stringSet, &pos)->key.pointer; } /* Sort the strings so that each one is immediately followed by all of its suffixes. */ diff --git a/icu4c/source/tools/gensprep/store.c b/icu4c/source/tools/gensprep/store.c index 30bd9fc50a3..a26d2b372b2 100644 --- a/icu4c/source/tools/gensprep/store.c +++ b/icu4c/source/tools/gensprep/store.c @@ -1,7 +1,7 @@ /* ******************************************************************************* * -* Copyright (C) 1999-2012, International Business Machines +* Copyright (C) 1999-2014, International Business Machines * Corporation and others. All Rights Reserved. * ******************************************************************************* @@ -236,7 +236,7 @@ static UBool U_CALLCONV compareEntries(const UHashTok p1, const UHashTok p2) { static void storeMappingData(){ - int32_t pos = -1; + int32_t pos = UHASH_FIRST; const UHashElement* element = NULL; ValueStruct* value = NULL; int32_t codepoint = 0;