本文整理汇总了C++中StringEnumeration::snext方法的典型用法代码示例。如果您正苦于以下问题:C++ StringEnumeration::snext方法的具体用法?C++ StringEnumeration::snext怎么用?C++ StringEnumeration::snext使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StringEnumeration
的用法示例。
在下文中一共展示了StringEnumeration::snext方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: TIMEZONE_GET_LIST
void TIMEZONE_GET_LIST(sLONG_PTR *pResult, PackagePtr pParams)
{
ARRAY_TEXT Param1;
Param1.setSize(1);
StringEnumeration *timeZoneIds = TimeZone::createEnumeration();
UErrorCode status = U_ZERO_ERROR;
const UnicodeString *zoneId = timeZoneIds->snext(status);
while (zoneId != NULL && status == U_ZERO_ERROR)
{
std::string zoneIdString;
zoneId->toUTF8String(zoneIdString);
Param1.appendUTF8String((const uint8_t *)zoneIdString.c_str(), (uint32_t)zoneIdString.size());
zoneId = timeZoneIds->snext(status);
}
delete timeZoneIds;
Param1.toParamAtIndex(pParams, 1);
}
示例2: testGetSamples
void PluralRulesTest::testGetSamples() {
// TODO: fix samples, re-enable this test.
// no get functional equivalent API in ICU4C, so just
// test every locale...
UErrorCode status = U_ZERO_ERROR;
int32_t numLocales;
const Locale* locales = Locale::getAvailableLocales(numLocales);
double values[1000];
for (int32_t i = 0; U_SUCCESS(status) && i < numLocales; ++i) {
PluralRules *rules = PluralRules::forLocale(locales[i], status);
if (U_FAILURE(status)) {
break;
}
StringEnumeration *keywords = rules->getKeywords(status);
if (U_FAILURE(status)) {
delete rules;
break;
}
const UnicodeString* keyword;
while (NULL != (keyword = keywords->snext(status))) {
int32_t count = rules->getSamples(*keyword, values, LENGTHOF(values), status);
if (U_FAILURE(status)) {
errln(UNICODE_STRING_SIMPLE("getSamples() failed for locale ") +
locales[i].getName() +
UNICODE_STRING_SIMPLE(", keyword ") + *keyword);
continue;
}
if (count == 0) {
// TODO: Lots of these.
// errln(UNICODE_STRING_SIMPLE("no samples for keyword ") + *keyword + UNICODE_STRING_SIMPLE(" in locale ") + locales[i].getName() );
}
if (count > LENGTHOF(values)) {
errln(UNICODE_STRING_SIMPLE("getSamples()=") + count +
UNICODE_STRING_SIMPLE(", too many values, for locale ") +
locales[i].getName() +
UNICODE_STRING_SIMPLE(", keyword ") + *keyword);
count = LENGTHOF(values);
}
for (int32_t j = 0; j < count; ++j) {
if (values[j] == UPLRULES_NO_UNIQUE_VALUE) {
errln("got 'no unique value' among values");
} else {
UnicodeString resultKeyword = rules->select(values[j]);
// if (strcmp(locales[i].getName(), "uk") == 0) { // Debug only.
// std::cout << " uk " << US(resultKeyword).cstr() << " " << values[j] << std::endl;
// }
if (*keyword != resultKeyword) {
errln("file %s, line %d, Locale %s, sample for keyword \"%s\": %g, select(%g) returns keyword \"%s\"",
__FILE__, __LINE__, locales[i].getName(), US(*keyword).cstr(), values[j], values[j], US(resultKeyword).cstr());
}
}
}
}
delete keywords;
delete rules;
}
}
示例3: getPluralRules
void
TimeUnitFormat::checkConsistency(UTimeUnitFormatStyle style, const char* key, UErrorCode& err) {
if (U_FAILURE(err)) {
return;
}
// there should be patterns for each plural rule in each time unit.
// For each time unit,
// for each plural rule, following is unit pattern fall-back rule:
// ( for example: "one" hour )
// look for its unit pattern in its locale tree.
// if pattern is not found in its own locale, such as de_DE,
// look for the pattern in its parent, such as de,
// keep looking till found or till root.
// if the pattern is not found in root either,
// fallback to plural count "other",
// look for the pattern of "other" in the locale tree:
// "de_DE" to "de" to "root".
// If not found, fall back to value of
// static variable DEFAULT_PATTERN_FOR_xxx, such as "{0} h".
//
// Following is consistency check to create pattern for each
// plural rule in each time unit using above fall-back rule.
//
StringEnumeration* keywords = getPluralRules().getKeywords(err);
if (U_SUCCESS(err)) {
const UnicodeString* pluralCount;
while ((pluralCount = keywords->snext(err)) != NULL) {
if ( U_SUCCESS(err) ) {
for (int32_t i = 0; i < TimeUnit::UTIMEUNIT_FIELD_COUNT; ++i) {
// for each time unit,
// get all the patterns for each plural rule in this locale.
Hashtable* countToPatterns = fTimeUnitToCountToPatterns[i];
if ( countToPatterns == NULL ) {
countToPatterns = initHash(err);
if (U_FAILURE(err)) {
delete countToPatterns;
return;
}
fTimeUnitToCountToPatterns[i] = countToPatterns;
}
MessageFormat** formatters = (MessageFormat**)countToPatterns->get(*pluralCount);
if( formatters == NULL || formatters[style] == NULL ) {
// look through parents
const char* localeName = getLocaleID(err);
CharString pluralCountChars;
pluralCountChars.appendInvariantChars(*pluralCount, err);
searchInLocaleChain(style, key, localeName,
(TimeUnit::UTimeUnitFields)i,
*pluralCount, pluralCountChars.data(),
countToPatterns, err);
}
}
}
}
}
delete keywords;
}
示例4: checkStringEnumeration
/**
* Iterate through the given iterator, checking to see that all the strings
* in the expected array are present.
* @param expected array of strings we expect to see, or NULL
* @param expectedCount number of elements of expected, or 0
*/
int32_t CollationServiceTest::checkStringEnumeration(const char* msg,
StringEnumeration& iter,
const char** expected,
int32_t expectedCount) {
UErrorCode ec = U_ZERO_ERROR;
U_ASSERT(expectedCount >= 0 && expectedCount < 31); // [sic] 31 not 32
int32_t i = 0, idxAfterReset = 0, n = iter.count(ec);
assertSuccess("count", ec);
UnicodeString buf, buffAfterReset;
int32_t seenMask = 0;
for (;; ++i) {
const UnicodeString* s = iter.snext(ec);
if (!assertSuccess("snext", ec) || s == NULL)
break;
if (i != 0)
buf.append(UNICODE_STRING_SIMPLE(", "));
buf.append(*s);
// check expected list
for (int32_t j=0, bit=1; j<expectedCount; ++j, bit<<=1) {
if ((seenMask&bit)==0) {
UnicodeString exp(expected[j], (char*)NULL);
if (*s == exp) {
seenMask |= bit;
logln((UnicodeString)"Ok: \"" + exp + "\" seen");
}
}
}
}
// can't get pesky operator+(const US&, foo) to cooperate; use toString
#if !UCONFIG_NO_FORMATTING
logln(UnicodeString() + msg + " = [" + buf + "] (" + toString(i) + ")");
#else
logln(UnicodeString() + msg + " = [" + buf + "] (??? NO_FORMATTING)");
#endif
assertTrue("count verified", i==n);
iter.reset(ec);
for (;; ++idxAfterReset) {
const UChar *s = iter.unext(NULL, ec);
if (!assertSuccess("unext", ec) || s == NULL)
break;
if (idxAfterReset != 0)
buffAfterReset.append(UNICODE_STRING_SIMPLE(", "));
buffAfterReset.append(s);
}
assertTrue("idxAfterReset verified", idxAfterReset==n);
assertTrue("buffAfterReset verified", buffAfterReset==buf);
// did we see all expected strings?
if (((1<<expectedCount)-1) != seenMask) {
for (int32_t j=0, bit=1; j<expectedCount; ++j, bit<<=1) {
if ((seenMask&bit)==0) {
errln((UnicodeString)"FAIL: \"" + expected[j] + "\" not seen");
}
}
}
return n;
}
示例5: loadTimeZoneNames
/*
* This method updates the cache and must be called with a lock,
* except initializer.
*/
void
TimeZoneNamesImpl::loadStrings(const UnicodeString& tzCanonicalID) {
loadTimeZoneNames(tzCanonicalID);
UErrorCode status = U_ZERO_ERROR;
StringEnumeration *mzIDs = getAvailableMetaZoneIDs(tzCanonicalID, status);
if (U_SUCCESS(status) && mzIDs != NULL) {
const UnicodeString *mzID;
while ((mzID = mzIDs->snext(status))) {
if (U_FAILURE(status)) {
break;
}
loadMetaZoneNames(*mzID);
}
delete mzIDs;
}
}
示例6: while
void
CurrencyAffixInfo::set(
const char *locale,
const PluralRules *rules,
const UChar *currency,
UErrorCode &status) {
if (U_FAILURE(status)) {
return;
}
fIsDefault = FALSE;
if (currency == NULL) {
fSymbol.setTo(gDefaultSymbols, 1);
fISO.setTo(gDefaultSymbols, 2);
fLong.remove();
fLong.append(gDefaultSymbols, 3);
fIsDefault = TRUE;
return;
}
int32_t len;
UBool unusedIsChoice;
const UChar *symbol = ucurr_getName(
currency, locale, UCURR_SYMBOL_NAME, &unusedIsChoice,
&len, &status);
if (U_FAILURE(status)) {
return;
}
fSymbol.setTo(symbol, len);
fISO.setTo(currency, u_strlen(currency));
fLong.remove();
StringEnumeration* keywords = rules->getKeywords(status);
if (U_FAILURE(status)) {
return;
}
const UnicodeString* pluralCount;
while ((pluralCount = keywords->snext(status)) != NULL) {
CharString pCount;
pCount.appendInvariantChars(*pluralCount, status);
const UChar *pluralName = ucurr_getPluralName(
currency, locale, &unusedIsChoice, pCount.data(),
&len, &status);
fLong.setVariant(pCount.data(), UnicodeString(pluralName, len), status);
}
delete keywords;
}
示例7: pluralCounts
void
TimeUnitFormat::setup(UErrorCode& err) {
initDataMembers(err);
UVector pluralCounts(0, uhash_compareUnicodeString, 6, err);
StringEnumeration* keywords = getPluralRules().getKeywords(err);
if (U_FAILURE(err)) {
return;
}
UnicodeString* pluralCount;
while ((pluralCount = const_cast<UnicodeString*>(keywords->snext(err))) != NULL) {
pluralCounts.addElement(pluralCount, err);
}
readFromCurrentLocale(UTMUTFMT_FULL_STYLE, gUnitsTag, pluralCounts, err);
checkConsistency(UTMUTFMT_FULL_STYLE, gUnitsTag, err);
readFromCurrentLocale(UTMUTFMT_ABBREVIATED_STYLE, gShortUnitsTag, pluralCounts, err);
checkConsistency(UTMUTFMT_ABBREVIATED_STYLE, gShortUnitsTag, err);
delete keywords;
}
示例8: df
/**
* 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;
}
示例9: getGenericLocationName
/*
* This method updates the cache and must be called with a lock,
* except initializer.
*/
void
TZGNCore::loadStrings(const UnicodeString& tzCanonicalID) {
// load the generic location name
getGenericLocationName(tzCanonicalID);
// partial location names
UErrorCode status = U_ZERO_ERROR;
const UnicodeString *mzID;
UnicodeString goldenID;
UnicodeString mzGenName;
UTimeZoneNameType genNonLocTypes[] = {
UTZNM_LONG_GENERIC, UTZNM_SHORT_GENERIC,
UTZNM_UNKNOWN /*terminator*/
};
StringEnumeration *mzIDs = fTimeZoneNames->getAvailableMetaZoneIDs(tzCanonicalID, status);
while ((mzID = mzIDs->snext(status))) {
if (U_FAILURE(status)) {
break;
}
// if this time zone is not the golden zone of the meta zone,
// partial location name (such as "PT (Los Angeles)") might be
// available.
fTimeZoneNames->getReferenceZoneID(*mzID, fTargetRegion, goldenID);
if (tzCanonicalID != goldenID) {
for (int32_t i = 0; genNonLocTypes[i] != UTZNM_UNKNOWN; i++) {
fTimeZoneNames->getMetaZoneDisplayName(*mzID, genNonLocTypes[i], mzGenName);
if (!mzGenName.isEmpty()) {
// getPartialLocationName formats a name and put it into the trie
getPartialLocationName(tzCanonicalID, *mzID,
(genNonLocTypes[i] == UTZNM_LONG_GENERIC), mzGenName);
}
}
}
}
if (mzIDs != NULL) {
delete mzIDs;
}
}
示例10: TestRegister
void CollationServiceTest::TestRegister()
{
#if !UCONFIG_NO_SERVICE
// register a singleton
const Locale& FR = Locale::getFrance();
const Locale& US = Locale::getUS();
const Locale US_FOO("en", "US", "FOO");
UErrorCode status = U_ZERO_ERROR;
Collator* frcol = Collator::createInstance(FR, status);
Collator* uscol = Collator::createInstance(US, status);
if(U_FAILURE(status)) {
errcheckln(status, "Failed to create collators with %s", u_errorName(status));
delete frcol;
delete uscol;
return;
}
{ // try override en_US collator
URegistryKey key = Collator::registerInstance(frcol, US, status);
Collator* ncol = Collator::createInstance(US_FOO, status);
if (*frcol != *ncol) {
errln("register of french collator for en_US failed on request for en_US_FOO");
}
// ensure original collator's params not touched
Locale loc = frcol->getLocale(ULOC_REQUESTED_LOCALE, status);
if (loc != FR) {
errln(UnicodeString("fr collator's requested locale changed to ") + loc.getName());
}
loc = frcol->getLocale(ULOC_VALID_LOCALE, status);
if (loc != FR) {
errln(UnicodeString("fr collator's valid locale changed to ") + loc.getName());
}
loc = ncol->getLocale(ULOC_REQUESTED_LOCALE, status);
if (loc != US_FOO) {
errln(UnicodeString("requested locale for en_US_FOO is not en_US_FOO but ") + loc.getName());
}
loc = ncol->getLocale(ULOC_VALID_LOCALE, status);
if (loc != US) {
errln(UnicodeString("valid locale for en_US_FOO is not en_US but ") + loc.getName());
}
loc = ncol->getLocale(ULOC_ACTUAL_LOCALE, status);
if (loc != US) {
errln(UnicodeString("actual locale for en_US_FOO is not en_US but ") + loc.getName());
}
delete ncol; ncol = NULL;
if (!Collator::unregister(key, status)) {
errln("failed to unregister french collator");
}
// !!! frcol pointer is now invalid !!!
ncol = Collator::createInstance(US, status);
if (*uscol != *ncol) {
errln("collator after unregister does not match original");
}
delete ncol; ncol = NULL;
}
// recreate frcol
frcol = Collator::createInstance(FR, status);
LocalUCollatorPointer frFR(ucol_open("fr_FR", &status));
{ // try create collator for new locale
Locale fu_FU_FOO("fu", "FU", "FOO");
Locale fu_FU("fu", "FU", "");
Collator* fucol = Collator::createInstance(fu_FU, status);
URegistryKey key = Collator::registerInstance(frcol, fu_FU, status);
Collator* ncol = Collator::createInstance(fu_FU_FOO, status);
if (*frcol != *ncol) {
errln("register of fr collator for fu_FU failed");
}
UnicodeString locName = fu_FU.getName();
StringEnumeration* localeEnum = Collator::getAvailableLocales();
UBool found = FALSE;
const UnicodeString* locStr, *ls2;
for (locStr = localeEnum->snext(status);
!found && locStr != NULL;
locStr = localeEnum->snext(status)) {
//
if (locName == *locStr) {
found = TRUE;
}
}
StringEnumeration *le2 = NULL;
localeEnum->reset(status);
int32_t i, count;
count = localeEnum->count(status);
for(i = 0; i < count; ++i) {
if(i == count / 2) {
le2 = localeEnum->clone();
if(le2 == NULL || count != le2->count(status)) {
errln("ServiceEnumeration.clone() failed");
//.........这里部分代码省略.........
示例11: UVector
UnicodeString& U_EXPORT2
ZoneMeta::getSingleCountry(const UnicodeString &tzid, UnicodeString &country) {
// Get canonical country for the zone
const UChar *region = TimeZone::getRegion(tzid);
if (u_strcmp(gWorld, region) == 0) {
// special case - "001"
country.remove();
return country;
}
// Checking the cached results
UErrorCode status = U_ZERO_ERROR;
UBool initialized;
UMTX_CHECK(&gZoneMetaLock, gCountryInfoVectorsInitialized, initialized);
if (!initialized) {
// Create empty vectors
umtx_lock(&gZoneMetaLock);
{
if (!gCountryInfoVectorsInitialized) {
// No deleters for these UVectors, it's a reference to a resource bundle string.
gSingleZoneCountries = new UVector(NULL, uhash_compareUChars, status);
if (gSingleZoneCountries == NULL) {
status = U_MEMORY_ALLOCATION_ERROR;
}
gMultiZonesCountries = new UVector(NULL, uhash_compareUChars, status);
if (gMultiZonesCountries == NULL) {
status = U_MEMORY_ALLOCATION_ERROR;
}
if (U_SUCCESS(status)) {
gCountryInfoVectorsInitialized = TRUE;
} else {
delete gSingleZoneCountries;
delete gMultiZonesCountries;
}
}
}
umtx_unlock(&gZoneMetaLock);
if (U_FAILURE(status)) {
country.remove();
return country;
}
}
// Check if it was already cached
UBool cached = FALSE;
UBool multiZones = FALSE;
umtx_lock(&gZoneMetaLock);
{
multiZones = cached = gMultiZonesCountries->contains((void*)region);
if (!multiZones) {
cached = gSingleZoneCountries->contains((void*)region);
}
}
umtx_unlock(&gZoneMetaLock);
if (!cached) {
// We need to go through all zones associated with the region.
// This is relatively heavy operation.
U_ASSERT(u_strlen(region) == 2);
char buf[] = {0, 0, 0};
u_UCharsToChars(region, buf, 2);
StringEnumeration *ids = TimeZone::createEnumeration(buf);
int32_t idsLen = ids->count(status);
if (U_SUCCESS(status) && idsLen > 1) {
// multiple zones are available for the region
UnicodeString canonical, tmp;
const UnicodeString *id = ids->snext(status);
getCanonicalSystemID(*id, canonical, status);
if (U_SUCCESS(status)) {
// check if there are any other canonical zone in the group
while ((id = ids->snext(status))!=NULL) {
getCanonicalSystemID(*id, tmp, status);
if (U_FAILURE(status)) {
break;
}
if (canonical != tmp) {
// another canonical zone was found
multiZones = TRUE;
break;
}
}
}
}
if (U_FAILURE(status)) {
// no single country by default for any error cases
multiZones = TRUE;
}
delete ids;
// Cache the result
umtx_lock(&gZoneMetaLock);
{
UErrorCode ec = U_ZERO_ERROR;
if (multiZones) {
if (!gMultiZonesCountries->contains((void*)region)) {
//.........这里部分代码省略.........
示例12: while
//.........这里部分代码省略.........
continue;
}
// Create canonical map entry for this alias
entry = (CanonicalMapEntry*)uprv_malloc(sizeof(CanonicalMapEntry));
if (entry == NULL) {
status = U_MEMORY_ALLOCATION_ERROR;
goto error_cleanup;
}
entry->id = canonical;
if (territory == NULL || u_strcmp(territory, gWorld) == 0) {
entry->country = NULL;
} else {
entry->country = territory;
}
// Put this entry in the hashtable. Since this hashtable has no key deleter,
// key is treated as const, but must be passed as non-const.
uhash_put(canonicalMap, (UChar*)alias, entry, &status);
if (U_FAILURE(status)) {
goto error_cleanup;
}
}
}
// Some available Olson zones are not included in CLDR data (such as Asia/Riyadh87).
// Also, when we update Olson tzdata, new zones may be added.
// This code scans all available zones in zoneinfo.res, and if any of them are
// missing, add them to the map.
tzenum = TimeZone::createEnumeration();
numZones = tzenum->count(status);
if (U_SUCCESS(status)) {
int32_t i;
for (i = 0; i < numZones; i++) {
const UnicodeString *zone = tzenum->snext(status);
if (U_FAILURE(status)) {
// We should not get here.
status = U_ZERO_ERROR;
continue;
}
UChar zoneUChars[ZID_KEY_MAX];
int32_t zoneUCharsLen = zone->extract(zoneUChars, ZID_KEY_MAX, status) + 1; // Add one for NUL termination
if (U_FAILURE(status) || status==U_STRING_NOT_TERMINATED_WARNING) {
status = U_ZERO_ERROR;
continue; // zone id is too long to extract
}
CanonicalMapEntry *entry = (CanonicalMapEntry*)uhash_get(canonicalMap, zoneUChars);
if (entry) {
// Already included in CLDR data
continue;
}
// Not in CLDR data, but it could be new one whose alias is available
// in CLDR.
int32_t nTzdataEquivalent = TimeZone::countEquivalentIDs(*zone);
int32_t j;
for (j = 0; j < nTzdataEquivalent; j++) {
UnicodeString alias = TimeZone::getEquivalentID(*zone, j);
if (alias == *zone) {
continue;
}
UChar aliasUChars[ZID_KEY_MAX];
alias.extract(aliasUChars, ZID_KEY_MAX, status);
if (U_FAILURE(status) || status==U_STRING_NOT_TERMINATED_WARNING) {
status = U_ZERO_ERROR;
continue; // zone id is too long to extract
}
entry = (CanonicalMapEntry*)uhash_get(canonicalMap, aliasUChars);
示例13: handler
TimeZoneGenericNameMatchInfo*
TZGNCore::findLocal(const UnicodeString& text, int32_t start, uint32_t types, UErrorCode& status) const {
GNameSearchHandler handler(types);
TZGNCore *nonConstThis = const_cast<TZGNCore *>(this);
umtx_lock(&gLock);
{
fGNamesTrie.search(text, start, (TextTrieMapSearchResultHandler *)&handler, status);
}
umtx_unlock(&gLock);
if (U_FAILURE(status)) {
return NULL;
}
TimeZoneGenericNameMatchInfo *gmatchInfo = NULL;
int32_t maxLen = 0;
UVector *results = handler.getMatches(maxLen);
if (results != NULL && ((maxLen == (text.length() - start)) || fGNamesTrieFullyLoaded)) {
// perfect match
gmatchInfo = new TimeZoneGenericNameMatchInfo(results);
if (gmatchInfo == NULL) {
status = U_MEMORY_ALLOCATION_ERROR;
delete results;
return NULL;
}
return gmatchInfo;
}
if (results != NULL) {
delete results;
}
// All names are not yet loaded into the local trie.
// Load all available names into the trie. This could be very heavy.
umtx_lock(&gLock);
{
if (!fGNamesTrieFullyLoaded) {
StringEnumeration *tzIDs = TimeZone::createTimeZoneIDEnumeration(UCAL_ZONE_TYPE_CANONICAL, NULL, NULL, status);
if (U_SUCCESS(status)) {
const UnicodeString *tzID;
while ((tzID = tzIDs->snext(status))) {
if (U_FAILURE(status)) {
break;
}
nonConstThis->loadStrings(*tzID);
}
}
if (tzIDs != NULL) {
delete tzIDs;
}
if (U_SUCCESS(status)) {
nonConstThis->fGNamesTrieFullyLoaded = TRUE;
}
}
}
umtx_unlock(&gLock);
if (U_FAILURE(status)) {
return NULL;
}
umtx_lock(&gLock);
{
// now try it again
fGNamesTrie.search(text, start, (TextTrieMapSearchResultHandler *)&handler, status);
}
umtx_unlock(&gLock);
results = handler.getMatches(maxLen);
if (results != NULL && maxLen > 0) {
gmatchInfo = new TimeZoneGenericNameMatchInfo(results);
if (gmatchInfo == NULL) {
status = U_MEMORY_ALLOCATION_ERROR;
delete results;
return NULL;
}
}
return gmatchInfo;
}
示例14: testAPI
//.........这里部分代码省略.........
// ======= Test getStaticClassID()
logln("Testing getStaticClassID()");
status = U_ZERO_ERROR;
DateTimePatternGenerator *test= DateTimePatternGenerator::createInstance(status);
if(test->getDynamicClassID() != DateTimePatternGenerator::getStaticClassID()) {
errln("ERROR: getDynamicClassID() didn't return the expected value");
}
delete test;
// ====== Test createEmptyInstance()
logln("Testing createEmptyInstance()");
status = U_ZERO_ERROR;
test = DateTimePatternGenerator::createEmptyInstance(status);
if(U_FAILURE(status)) {
errln("ERROR: Fail to create an empty instance ! - exitting.\n");
delete test;
return;
}
conflictingStatus = test->addPattern(UnicodeString("MMMMd"), true, conflictingPattern, status);
status = U_ZERO_ERROR;
testPattern=test->getBestPattern(UnicodeString("MMMMdd"), status);
conflictingStatus = test->addPattern(UnicodeString("HH:mm"), true, conflictingPattern, status);
conflictingStatus = test->addPattern(UnicodeString("MMMMMd"), true, conflictingPattern, status); //duplicate pattern
StringEnumeration *output=NULL;
output = test->getRedundants(status);
expectedResult=UnicodeString("MMMMd");
if (output != NULL) {
output->reset(status);
const UnicodeString *dupPattern=output->snext(status);
if ( (dupPattern==NULL) || (*dupPattern != expectedResult) ) {
errln("ERROR: Fail in getRedundants !\n");
}
}
// ======== Test getSkeletons and getBaseSkeletons
StringEnumeration* ptrSkeletonEnum = test->getSkeletons(status);
if(U_FAILURE(status)) {
errln("ERROR: Fail to get skeletons !\n");
}
UnicodeString returnPattern, *ptrSkeleton;
ptrSkeletonEnum->reset(status);
int32_t count=ptrSkeletonEnum->count(status);
for (i=0; i<count; ++i) {
ptrSkeleton = (UnicodeString *)ptrSkeletonEnum->snext(status);
returnPattern = test->getPatternForSkeleton(*ptrSkeleton);
if ( returnPattern != testSkeletonsResults[i] ) {
errln(UnicodeString("ERROR: Unexpected result from getSkeletons and getPatternForSkeleton\nGot: ") + returnPattern
+ UnicodeString("\nExpected: ") + testSkeletonsResults[i]
+ UnicodeString("\n"));
}
}
StringEnumeration* ptrBaseSkeletonEnum = test->getBaseSkeletons(status);
if(U_FAILURE(status)) {
errln("ERROR: Fail to get base skeletons !\n");
}
count=ptrBaseSkeletonEnum->count(status);
for (i=0; i<count; ++i) {
ptrSkeleton = (UnicodeString *)ptrBaseSkeletonEnum->snext(status);
if ( *ptrSkeleton != testBaseSkeletonsResults[i] ) {
errln("ERROR: Unexpected result from getBaseSkeletons() !\n");
}
示例15: TestRegisterFactory
void CollationServiceTest::TestRegisterFactory(void)
{
#if !UCONFIG_NO_SERVICE
int32_t n1, n2, n3;
Locale fu_FU("fu", "FU", "");
Locale fu_FU_FOO("fu", "FU", "FOO");
UErrorCode status = U_ZERO_ERROR;
Hashtable* fuFUNames = new Hashtable(FALSE, status);
if (!fuFUNames) {
errln("memory allocation error");
return;
}
fuFUNames->setValueDeleter(uhash_deleteUnicodeString);
fuFUNames->put(fu_FU.getName(), new UnicodeString("ze leetle bunny Fu-Fu"), status);
fuFUNames->put(fu_FU_FOO.getName(), new UnicodeString("zee leetel bunny Foo-Foo"), status);
fuFUNames->put(Locale::getDefault().getName(), new UnicodeString("little bunny Foo Foo"), status);
Collator* frcol = Collator::createInstance(Locale::getFrance(), status);
Collator* gecol = Collator::createInstance(Locale::getGermany(), status);
Collator* jpcol = Collator::createInstance(Locale::getJapan(), status);
if(U_FAILURE(status)) {
errcheckln(status, "Failed to create collators with %s", u_errorName(status));
delete frcol;
delete gecol;
delete jpcol;
delete fuFUNames;
return;
}
CollatorInfo** info = new CollatorInfo*[4];
if (!info) {
errln("memory allocation error");
return;
}
info[0] = new CollatorInfo(Locale::getUS(), frcol, NULL);
info[1] = new CollatorInfo(Locale::getFrance(), gecol, NULL);
info[2] = new CollatorInfo(fu_FU, jpcol, fuFUNames);
info[3] = NULL;
TestFactory* factory = new TestFactory(info);
if (!factory) {
errln("memory allocation error");
return;
}
Collator* uscol = Collator::createInstance(Locale::getUS(), status);
Collator* fucol = Collator::createInstance(fu_FU, status);
{
n1 = checkAvailable("before registerFactory");
URegistryKey key = Collator::registerFactory(factory, status);
n2 = checkAvailable("after registerFactory");
assertTrue("count after > count before", n2 > n1);
Collator* ncol = Collator::createInstance(Locale::getUS(), status);
if (*frcol != *ncol) {
errln("frcoll for en_US failed");
}
delete ncol; ncol = NULL;
ncol = Collator::createInstance(fu_FU_FOO, status);
if (*jpcol != *ncol) {
errln("jpcol for fu_FU_FOO failed");
}
Locale loc = ncol->getLocale(ULOC_REQUESTED_LOCALE, status);
if (loc != fu_FU_FOO) {
errln(UnicodeString("requested locale for fu_FU_FOO is not fu_FU_FOO but ") + loc.getName());
}
loc = ncol->getLocale(ULOC_VALID_LOCALE, status);
if (loc != fu_FU) {
errln(UnicodeString("valid locale for fu_FU_FOO is not fu_FU but ") + loc.getName());
}
delete ncol; ncol = NULL;
UnicodeString locName = fu_FU.getName();
StringEnumeration* localeEnum = Collator::getAvailableLocales();
UBool found = FALSE;
const UnicodeString* locStr;
for (locStr = localeEnum->snext(status);
!found && locStr != NULL;
locStr = localeEnum->snext(status))
{
if (locName == *locStr) {
found = TRUE;
}
}
delete localeEnum;
if (!found) {
errln("new locale fu_FU not reported as supported locale");
}
UnicodeString name;
//.........这里部分代码省略.........