本文整理汇总了C++中StringEnumeration::count方法的典型用法代码示例。如果您正苦于以下问题:C++ StringEnumeration::count方法的具体用法?C++ StringEnumeration::count怎么用?C++ StringEnumeration::count使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StringEnumeration
的用法示例。
在下文中一共展示了StringEnumeration::count方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: UVector
/**
* Returns an enumeration over the IDs of all the regions that are children of this region anywhere in the region
* hierarchy and match the given type. This API may return an empty enumeration if this region doesn't have any
* sub-regions that match the given type. For example, calling this method with region "150" (Europe) and type
* "URGN_TERRITORY" returns a set containing all the territories in Europe ( "FR" (France) - "IT" (Italy) - "DE" (Germany) etc. )
*/
StringEnumeration*
Region::getContainedRegions( URegionType type, UErrorCode &status ) const {
umtx_initOnce(gRegionDataInitOnce, &loadRegionData, status); // returns immediately if U_FAILURE(status)
if (U_FAILURE(status)) {
return NULL;
}
UVector *result = new UVector(NULL, uhash_compareChars, status);
StringEnumeration *cr = getContainedRegions(status);
for ( int32_t i = 0 ; i < cr->count(status) ; i++ ) {
const char *id = cr->next(NULL,status);
const Region *r = Region::getInstance(id,status);
if ( r->getType() == type ) {
result->addElement((void *)&r->idStr,status);
} else {
StringEnumeration *children = r->getContainedRegions(type, status);
for ( int32_t j = 0 ; j < children->count(status) ; j++ ) {
const char *id2 = children->next(NULL,status);
const Region *r2 = Region::getInstance(id2,status);
result->addElement((void *)&r2->idStr,status);
}
delete children;
}
}
delete cr;
StringEnumeration* resultEnumeration = new RegionNameEnumeration(result,status);
delete result;
return resultEnumeration;
}
示例2: 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;
}
示例3: setup
/**
* Set up ICU, print # of available collators
*/
void setup(UErrorCode &status) {
u_init(&status);
fprintf(stderr, "ICU %s init: %s\n", U_ICU_VERSION, u_errorName(status));
int32_t count;
StringEnumeration *se = Collator::getAvailableLocales();
count = se->count(status);
fprintf(stderr, "# Collators now available: %d,\t%s - %d providers expected.\n", count, u_errorName(status), (int32_t)PROVIDER_COUNT);
}
示例4: UnicodeString
/**
* @bug 4151406
* TimeZone::getAvailableIDs(int32_t) throws exception for certain values,
* due to a faulty constant in TimeZone::java.
*/
void TimeZoneRegressionTest:: Test4151406() {
int32_t max = 0;
for (int32_t h=-28; h<=30; ++h) {
// h is in half-hours from GMT; rawoffset is in millis
int32_t rawoffset = h * 1800000;
int32_t hh = (h<0) ? -h : h;
UnicodeString hname = UnicodeString((h<0) ? "GMT-" : "GMT+") +
((hh/2 < 10) ? "0" : "") +
(hh/2) + ':' +
((hh%2==0) ? "00" : "30");
//try {
UErrorCode ec = U_ZERO_ERROR;
int32_t count;
StringEnumeration* ids = TimeZone::createEnumeration(rawoffset);
if (ids == NULL) {
dataerrln("Fail: TimeZone::createEnumeration(rawoffset)");
continue;
}
count = ids->count(ec);
if (count> max)
max = count;
if (count > 0) {
logln(hname + ' ' + (UnicodeString)count + (UnicodeString)" e.g. " + *ids->snext(ec));
} else {
logln(hname + ' ' + count);
}
// weiv 11/27/2002: why uprv_free? This should be a delete
delete ids;
//delete [] ids;
//uprv_free(ids);
/*} catch (Exception e) {
errln(hname + ' ' + "Fail: " + e);
}*/
}
logln("Maximum zones per offset = %d", max);
}
示例5: testAPI
//.........这里部分代码省略.........
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");
}
}
// ========= DateTimePatternGenerator sample code in Userguide
// set up the generator
Locale locale = Locale::getFrench();
status = U_ZERO_ERROR;
DateTimePatternGenerator *generator = DateTimePatternGenerator::createInstance( locale, status);
// get a pattern for an abbreviated month and day
pattern = generator->getBestPattern(UnicodeString("MMMd"), status);
SimpleDateFormat formatter(pattern, locale, status);
zone = TimeZone::createTimeZone(UnicodeString("GMT"));
formatter.setTimeZone(*zone);
// use it to format (or parse)
UnicodeString formatted;
formatted = formatter.format(Calendar::getNow(), formatted, status);
// for French, the result is "13 sept."
formatted.remove();
// cannot use the result from getNow() because the value change evreyday.
testDate= LocaleTest::date(99, 0, 13, 23, 58, 59);
formatted = formatter.format(testDate, formatted, status);
expectedResult=UnicodeString("14 janv.");
if ( formatted != expectedResult ) {
errln("ERROR: Userguide sample code result!");
errln(UnicodeString(" Got: ")+ formatted + UnicodeString(" Expected: ") + expectedResult);
}
delete zone;
delete output;
delete ptrSkeletonEnum;
delete ptrBaseSkeletonEnum;
delete test;
delete generator;
}
示例6: 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");
//.........这里部分代码省略.........
示例7: 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)) {
//.........这里部分代码省略.........
示例8:
UnicodeString& U_EXPORT2
ZoneMeta::getCanonicalCountry(const UnicodeString &tzid, UnicodeString &country, UBool *isPrimary /* = NULL */) {
if (isPrimary != NULL) {
*isPrimary = FALSE;
}
const UChar *region = TimeZone::getRegion(tzid);
if (region != NULL && u_strcmp(gWorld, region) != 0) {
country.setTo(region, -1);
} else {
country.setToBogus();
return country;
}
if (isPrimary != NULL) {
char regionBuf[] = {0, 0, 0};
// Checking the cached results
UErrorCode status = U_ZERO_ERROR;
umtx_initOnce(gCountryInfoVectorsInitOnce, &countryInfoVectorsInit, status);
if (U_FAILURE(status)) {
return country;
}
// Check if it was already cached
UBool cached = FALSE;
UBool singleZone = FALSE;
umtx_lock(gZoneMetaLock());
{
singleZone = cached = gSingleZoneCountries->contains((void*)region);
if (!cached) {
cached = gMultiZonesCountries->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);
u_UCharsToChars(region, regionBuf, 2);
StringEnumeration *ids = TimeZone::createTimeZoneIDEnumeration(UCAL_ZONE_TYPE_CANONICAL_LOCATION, regionBuf, NULL, status);
int32_t idsLen = ids->count(status);
if (U_SUCCESS(status) && idsLen == 1) {
// only the single zone is available for the region
singleZone = TRUE;
}
delete ids;
// Cache the result
umtx_lock(gZoneMetaLock());
{
UErrorCode ec = U_ZERO_ERROR;
if (singleZone) {
if (!gSingleZoneCountries->contains((void*)region)) {
gSingleZoneCountries->addElement((void*)region, ec);
}
} else {
if (!gMultiZonesCountries->contains((void*)region)) {
gMultiZonesCountries->addElement((void*)region, ec);
}
}
}
umtx_unlock(gZoneMetaLock());
}
if (singleZone) {
*isPrimary = TRUE;
} else {
// Note: We may cache the primary zone map in future.
// Even a country has multiple zones, one of them might be
// dominant and treated as a primary zone
int32_t idLen = 0;
if (regionBuf[0] == 0) {
u_UCharsToChars(region, regionBuf, 2);
}
UResourceBundle *rb = ures_openDirect(NULL, gMetaZones, &status);
ures_getByKey(rb, gPrimaryZonesTag, rb, &status);
const UChar *primaryZone = ures_getStringByKey(rb, regionBuf, &idLen, &status);
if (U_SUCCESS(status)) {
if (tzid.compare(primaryZone, idLen) == 0) {
*isPrimary = TRUE;
} else {
// The given ID might not be a canonical ID
UnicodeString canonicalID;
TimeZone::getCanonicalID(tzid, canonicalID, status);
if (U_SUCCESS(status) && canonicalID.compare(primaryZone, idLen) == 0) {
*isPrimary = TRUE;
}
}
}
ures_close(rb);
}
}
//.........这里部分代码省略.........
示例9: while
UHashtable*
ZoneMeta::createCanonicalMap(void) {
UErrorCode status = U_ZERO_ERROR;
UHashtable *canonicalMap = NULL;
UResourceBundle *zoneFormatting = NULL;
UResourceBundle *tzitem = NULL;
UResourceBundle *aliases = NULL;
StringEnumeration* tzenum = NULL;
int32_t numZones;
canonicalMap = uhash_open(uhash_hashUChars, uhash_compareUChars, NULL, &status);
if (U_FAILURE(status)) {
return NULL;
}
// no key deleter
uhash_setValueDeleter(canonicalMap, deleteCanonicalMapEntry);
zoneFormatting = ures_openDirect(NULL, gSupplementalData, &status);
zoneFormatting = ures_getByKey(zoneFormatting, gZoneFormattingTag, zoneFormatting, &status);
if (U_FAILURE(status)) {
goto error_cleanup;
}
while (ures_hasNext(zoneFormatting)) {
tzitem = ures_getNextResource(zoneFormatting, tzitem, &status);
if (U_FAILURE(status)) {
status = U_ZERO_ERROR;
continue;
}
if (ures_getType(tzitem) != URES_TABLE) {
continue;
}
int32_t canonicalLen;
const UChar *canonical = ures_getStringByKey(tzitem, gCanonicalTag, &canonicalLen, &status);
if (U_FAILURE(status)) {
status = U_ZERO_ERROR;
continue;
}
int32_t territoryLen;
const UChar *territory = ures_getStringByKey(tzitem, gTerritoryTag, &territoryLen, &status);
if (U_FAILURE(status)) {
territory = NULL;
status = U_ZERO_ERROR;
}
// Create canonical map entry
CanonicalMapEntry *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*)canonical, entry, &status);
if (U_FAILURE(status)) {
goto error_cleanup;
}
// Get aliases
aliases = ures_getByKey(tzitem, gAliasesTag, aliases, &status);
if (U_FAILURE(status)) {
// No aliases
status = U_ZERO_ERROR;
continue;
}
while (ures_hasNext(aliases)) {
const UChar* alias = ures_getNextString(aliases, NULL, NULL, &status);
if (U_FAILURE(status)) {
status = U_ZERO_ERROR;
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)) {
//.........这里部分代码省略.........