本文整理汇总了C++中StringEnumeration::reset方法的典型用法代码示例。如果您正苦于以下问题:C++ StringEnumeration::reset方法的具体用法?C++ StringEnumeration::reset怎么用?C++ StringEnumeration::reset使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StringEnumeration
的用法示例。
在下文中一共展示了StringEnumeration::reset方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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;
}
示例2: 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;
}
示例3: NFTestFactory
//.........这里部分代码省略.........
NumberFormat* f3 = NumberFormat::createCurrencyInstance(SRC_LOC, status);
NumberFormat* f3a = NumberFormat::createCurrencyInstance(SRC_LOC, status);
NumberFormat* f4 = NumberFormat::createInstance(SRC_LOC, status);
StringEnumeration* locs = NumberFormat::getAvailableLocales();
UNumberFormat* uf3 = unum_open(UNUM_CURRENCY, NULL, 0, SRC_LOC.getName(),NULL, &status);
UNumberFormat* uf4 = unum_open(UNUM_DEFAULT, NULL, 0, SRC_LOC.getName(), NULL, &status);
const UnicodeString* res;
for (res = locs->snext(status); res; res = locs->snext(status)) {
logln(*res); // service is still in synch
}
NumberFormat::unregister(key, status); // restore for other tests
NumberFormat* f5 = NumberFormat::createCurrencyInstance(SRC_LOC, status);
UNumberFormat* uf5 = unum_open(UNUM_CURRENCY, NULL, 0, SRC_LOC.getName(),NULL, &status);
if (U_FAILURE(status)) {
dataerrln("Error creating instnaces.");
return;
} else {
float n = 1234.567f;
UnicodeString res0, res1, res2, res3, res4, res5;
UChar ures3[50];
UChar ures4[50];
UChar ures5[50];
f0->format(n, res0);
f1->format(n, res1);
f2->format(n, res2);
f3->format(n, res3);
f4->format(n, res4);
f5->format(n, res5);
unum_formatDouble(uf3, n, ures3, 50, NULL, &status);
unum_formatDouble(uf4, n, ures4, 50, NULL, &status);
unum_formatDouble(uf5, n, ures5, 50, NULL, &status);
logln((UnicodeString)"f0 swap int: " + res0);
logln((UnicodeString)"f1 src int: " + res1);
logln((UnicodeString)"f2 src cur: " + res2);
logln((UnicodeString)"f3 reg cur: " + res3);
logln((UnicodeString)"f4 reg int: " + res4);
logln((UnicodeString)"f5 unreg cur: " + res5);
log("uf3 reg cur: ");
logln(ures3);
log("uf4 reg int: ");
logln(ures4);
log("uf5 ureg cur: ");
logln(ures5);
if (f3 == f3a) {
errln("did not get new instance from service");
} else {
delete f3a;
}
if (res3 != res0) {
errln("registered service did not match");
}
if (res4 != res1) {
errln("registered service did not inherit");
}
if (res5 != res2) {
errln("unregistered service did not match original");
}
if (res0 != ures3) {
errln("registered service did not match / unum");
}
if (res1 != ures4) {
errln("registered service did not inherit / unum");
}
if (res2 != ures5) {
errln("unregistered service did not match original / unum");
}
}
unum_close(uf5);
delete f5;
unum_close(uf4);
unum_close(uf3);
delete f4;
delete f3;
delete f2;
delete f1;
delete f0;
for (res = locs->snext(status); res; res = locs->snext(status)) {
errln(*res); // service should be out of synch
}
locs->reset(status); // now in synch again, we hope
for (res = locs->snext(status); res; res = locs->snext(status)) {
logln(*res);
}
delete locs;
#endif
}
示例4: testAPI
//.........这里部分代码省略.........
// UnicodeString randomString=Unicode
// ======= 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");
示例5: 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");
//.........这里部分代码省略.........
示例6: testAvailbleLocales
void PluralRulesTest::testAvailbleLocales() {
// Hash set of (char *) strings.
UErrorCode status = U_ZERO_ERROR;
UHashtable *localeSet = uhash_open(uhash_hashUnicodeString, uhash_compareUnicodeString, uhash_compareLong, &status);
uhash_setKeyDeleter(localeSet, uprv_deleteUObject);
if (U_FAILURE(status)) {
errln("file %s, line %d: Error status = %s", __FILE__, __LINE__, u_errorName(status));
return;
}
// Check that each locale returned by the iterator is unique.
StringEnumeration *localesEnum = PluralRules::getAvailableLocales(status);
int localeCount = 0;
for (;;) {
const char *locale = localesEnum->next(NULL, status);
if (U_FAILURE(status)) {
dataerrln("file %s, line %d: Error status = %s", __FILE__, __LINE__, u_errorName(status));
return;
}
if (locale == NULL) {
break;
}
localeCount++;
int32_t oldVal = uhash_puti(localeSet, new UnicodeString(locale), 1, &status);
if (oldVal != 0) {
errln("file %s, line %d: locale %s was seen before.", __FILE__, __LINE__, locale);
}
}
// Reset the iterator, verify that we get the same count.
localesEnum->reset(status);
int32_t localeCount2 = 0;
while (localesEnum->next(NULL, status) != NULL) {
if (U_FAILURE(status)) {
errln("file %s, line %d: Error status = %s", __FILE__, __LINE__, u_errorName(status));
break;
}
localeCount2++;
}
if (localeCount != localeCount2) {
errln("file %s, line %d: locale counts differ. They are (%d, %d)",
__FILE__, __LINE__, localeCount, localeCount2);
}
// Instantiate plural rules for each available locale.
localesEnum->reset(status);
for (;;) {
status = U_ZERO_ERROR;
const char *localeName = localesEnum->next(NULL, status);
if (U_FAILURE(status)) {
errln("file %s, line %d: Error status = %s, locale = %s",
__FILE__, __LINE__, u_errorName(status), localeName);
return;
}
if (localeName == NULL) {
break;
}
Locale locale = Locale::createFromName(localeName);
PluralRules *pr = PluralRules::forLocale(locale, status);
if (U_FAILURE(status)) {
errln("file %s, line %d: Error %s creating plural rules for locale %s",
__FILE__, __LINE__, u_errorName(status), localeName);
continue;
}
if (pr == NULL) {
errln("file %s, line %d: Null plural rules for locale %s", __FILE__, __LINE__, localeName);
continue;
}
// Pump some numbers through the plural rules. Can't check for correct results,
// mostly this to tickle any asserts or crashes that may be lurking.
for (double n=0; n<120.0; n+=0.5) {
UnicodeString keyword = pr->select(n);
if (keyword.length() == 0) {
errln("file %s, line %d, empty keyword for n = %g, locale %s",
__FILE__, __LINE__, n, localeName);
}
}
delete pr;
}
uhash_close(localeSet);
delete localesEnum;
}