本文整理汇总了C++中UnicodeString::isBogus方法的典型用法代码示例。如果您正苦于以下问题:C++ UnicodeString::isBogus方法的具体用法?C++ UnicodeString::isBogus怎么用?C++ UnicodeString::isBogus使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UnicodeString
的用法示例。
在下文中一共展示了UnicodeString::isBogus方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: mutex
UVector&
ICUService::getVisibleIDs(UVector& result, const UnicodeString* matchID, UErrorCode& status) const
{
result.removeAllElements();
if (U_FAILURE(status)) {
return result;
}
{
Mutex mutex(&lock);
const Hashtable* map = getVisibleIDMap(status);
if (map != NULL) {
ICUServiceKey* fallbackKey = createKey(matchID, status);
for (int32_t pos = UHASH_FIRST;;) {
const UHashElement* e = map->nextElement(pos);
if (e == NULL) {
break;
}
const UnicodeString* id = (const UnicodeString*)e->key.pointer;
if (fallbackKey != NULL) {
if (!fallbackKey->isFallbackOf(*id)) {
continue;
}
}
UnicodeString* idClone = new UnicodeString(*id);
if (idClone == NULL || idClone->isBogus()) {
delete idClone;
status = U_MEMORY_ALLOCATION_ERROR;
break;
}
result.addElement(idClone, status);
if (U_FAILURE(status)) {
delete idClone;
break;
}
}
delete fallbackKey;
}
}
if (U_FAILURE(status)) {
result.removeAllElements();
}
return result;
}
示例2:
void U_EXPORT2
Normalizer::normalize(const UnicodeString & source,
UNormalizationMode mode, int32_t options,
UnicodeString & result,
UErrorCode & status)
{
if (source.isBogus() || U_FAILURE(status))
{
result.setToBogus();
if (U_SUCCESS(status))
{
status = U_ILLEGAL_ARGUMENT_ERROR;
}
}
else
{
UnicodeString localDest;
UnicodeString * dest;
if (&source != &result)
{
dest = &result;
}
else
{
// the source and result strings are the same object, use a temporary one
dest = &localDest;
}
const Normalizer2 * n2 = Normalizer2Factory::getInstance(mode, status);
if (U_SUCCESS(status))
{
if (options & UNORM_UNICODE_3_2)
{
FilteredNormalizer2(*n2, *uniset_getUnicode32Instance(status)).
normalize(source, *dest, status);
}
else
{
n2->normalize(source, *dest, status);
}
}
if (dest == &localDest && U_SUCCESS(status))
{
result = *dest;
}
}
}
示例3:
UnicodeString& U_EXPORT2
ZoneMeta::getZoneIdByMetazone(const UnicodeString &mzid, const UnicodeString ®ion, UnicodeString &result) {
UErrorCode status = U_ZERO_ERROR;
const UChar *tzid = NULL;
int32_t tzidLen = 0;
char keyBuf[ZID_KEY_MAX + 1];
int32_t keyLen = 0;
if (mzid.isBogus() || mzid.length() > ZID_KEY_MAX) {
result.setToBogus();
return result;
}
keyLen = mzid.extract(0, mzid.length(), keyBuf, ZID_KEY_MAX + 1, US_INV);
keyBuf[keyLen] = 0;
UResourceBundle *rb = ures_openDirect(NULL, gMetaZones, &status);
ures_getByKey(rb, gMapTimezonesTag, rb, &status);
ures_getByKey(rb, keyBuf, rb, &status);
if (U_SUCCESS(status)) {
// check region mapping
if (region.length() == 2 || region.length() == 3) {
keyLen = region.extract(0, region.length(), keyBuf, ZID_KEY_MAX + 1, US_INV);
keyBuf[keyLen] = 0;
tzid = ures_getStringByKey(rb, keyBuf, &tzidLen, &status);
if (status == U_MISSING_RESOURCE_ERROR) {
status = U_ZERO_ERROR;
}
}
if (U_SUCCESS(status) && tzid == NULL) {
// try "001"
tzid = ures_getStringByKey(rb, gWorldTag, &tzidLen, &status);
}
}
ures_close(rb);
if (tzid == NULL) {
result.setToBogus();
} else {
result.setTo(tzid, tzidLen);
}
return result;
}
示例4: topLoc
TransliteratorSpec::TransliteratorSpec(const UnicodeString& theSpec)
: top(theSpec),
res(0)
{
UErrorCode status = U_ZERO_ERROR;
Locale topLoc("");
LocaleUtility::initLocaleFromName(theSpec, topLoc);
if (!topLoc.isBogus()) {
res = new ResourceBundle(U_ICUDATA_TRANSLIT, topLoc, status);
/* test for NULL */
if (res == 0) {
return;
}
if (U_FAILURE(status) || status == U_USING_DEFAULT_WARNING) {
delete res;
res = 0;
}
}
// Canonicalize script name -or- do locale->script mapping
status = U_ZERO_ERROR;
static const int32_t capacity = 10;
UScriptCode script[capacity]={USCRIPT_INVALID_CODE};
int32_t num = uscript_getCode(CharString().appendInvariantChars(theSpec, status).data(),
script, capacity, &status);
if (num > 0 && script[0] != USCRIPT_INVALID_CODE) {
scriptName = UnicodeString(uscript_getName(script[0]), -1, US_INV);
}
// Canonicalize top
if (res != 0) {
// Canonicalize locale name
UnicodeString locStr;
LocaleUtility::initNameFromLocale(topLoc, locStr);
if (!locStr.isBogus()) {
top = locStr;
}
} else if (scriptName.length() != 0) {
// We are a script; use canonical name
top = scriptName;
}
// assert(spec != top);
reset();
}
示例5: handleDefault
//.........这里部分代码省略.........
// first test of cache failed, so we'll have to update
// the cache if we eventually succeed-- that is, if we're
// going to update the cache at all.
putInCache = TRUE;
int32_t index = startIndex;
while (index < limit) {
ICUServiceFactory* f = (ICUServiceFactory*)factories->elementAt(index++);
UObject* service = f->create(key, this, status);
if (U_FAILURE(status)) {
delete service;
return NULL;
}
if (service != NULL) {
result = new CacheEntry(currentDescriptor, service);
if (result == NULL) {
delete service;
status = U_MEMORY_ALLOCATION_ERROR;
return NULL;
}
goto outerEnd;
}
}
// prepare to load the cache with all additional ids that
// will resolve to result, assuming we'll succeed. We
// don't want to keep querying on an id that's going to
// fallback to the one that succeeded, we want to hit the
// cache the first time next goaround.
if (cacheDescriptorList._obj == NULL) {
cacheDescriptorList._obj = new UVector(uprv_deleteUObject, NULL, 5, status);
if (U_FAILURE(status)) {
return NULL;
}
}
UnicodeString* idToCache = new UnicodeString(currentDescriptor);
if (idToCache == NULL || idToCache->isBogus()) {
status = U_MEMORY_ALLOCATION_ERROR;
return NULL;
}
cacheDescriptorList._obj->addElement(idToCache, status);
if (U_FAILURE(status)) {
return NULL;
}
} while (key.fallback());
outerEnd:
if (result != NULL) {
if (putInCache && cacheResult) {
serviceCache->put(result->actualDescriptor, result, status);
if (U_FAILURE(status)) {
delete result;
return NULL;
}
if (cacheDescriptorList._obj != NULL) {
for (int32_t i = cacheDescriptorList._obj->size(); --i >= 0;) {
UnicodeString* desc = (UnicodeString*)cacheDescriptorList._obj->elementAt(i);
serviceCache->put(*desc, result, status);
if (U_FAILURE(status)) {
delete result;
return NULL;
}
result->ref();
cacheDescriptorList._obj->removeElementAt(i);
}
}
}
if (actualReturn != NULL) {
// strip null prefix
if (result->actualDescriptor.indexOf((UChar)0x2f) == 0) { // U+002f=slash (/)
actualReturn->remove();
actualReturn->append(result->actualDescriptor,
1,
result->actualDescriptor.length() - 1);
} else {
*actualReturn = result->actualDescriptor;
}
if (actualReturn->isBogus()) {
status = U_MEMORY_ALLOCATION_ERROR;
delete result;
return NULL;
}
}
UObject* service = cloneInstance(result->service);
if (putInCache && !cacheResult) {
delete result;
}
return service;
}
}
return handleDefault(key, actualReturn, status);
}
示例6: _php_intlgregcal_constructor_body
//.........这里部分代码省略.........
"|z!s!", &tz_object, &locale, &locale_len) == FAILURE) {
intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR,
"intlgregcal_create_instance: bad arguments", 0 TSRMLS_CC);
Z_OBJ_P(return_value) = NULL;
return;
}
}
if (variant > 2 && zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
"lll|lll", &largs[0], &largs[1], &largs[2], &largs[3], &largs[4],
&largs[5]) == FAILURE) {
intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR,
"intlgregcal_create_instance: bad arguments", 0 TSRMLS_CC);
Z_OBJ_P(return_value) = NULL;
return;
}
// instantion of ICU object
GregorianCalendar *gcal = NULL;
if (variant <= 2) {
// From timezone and locale (0 to 2 arguments)
TimeZone *tz = timezone_process_timezone_argument(tz_object, NULL,
"intlgregcal_create_instance" TSRMLS_CC);
if (tz == NULL) {
Z_OBJ_P(return_value) = NULL;
return;
}
if (!locale) {
locale = const_cast<char*>(intl_locale_get_default(TSRMLS_C));
}
gcal = new GregorianCalendar(tz, Locale::createFromName(locale),
status);
if (U_FAILURE(status)) {
intl_error_set(NULL, status, "intlgregcal_create_instance: error "
"creating ICU GregorianCalendar from time zone and locale", 0 TSRMLS_CC);
if (gcal) {
delete gcal;
}
delete tz;
Z_OBJ_P(return_value) = NULL;
return;
}
} else {
// From date/time (3, 5 or 6 arguments)
for (int i = 0; i < variant; i++) {
if (largs[i] < INT32_MIN || largs[i] > INT32_MAX) {
intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR,
"intlgregcal_create_instance: at least one of the arguments"
" has an absolute value that is too large", 0 TSRMLS_CC);
Z_OBJ_P(return_value) = NULL;
return;
}
}
if (variant == 3) {
gcal = new GregorianCalendar((int32_t)largs[0], (int32_t)largs[1],
(int32_t)largs[2], status);
} else if (variant == 5) {
gcal = new GregorianCalendar((int32_t)largs[0], (int32_t)largs[1],
(int32_t)largs[2], (int32_t)largs[3], (int32_t)largs[4], status);
} else if (variant == 6) {
gcal = new GregorianCalendar((int32_t)largs[0], (int32_t)largs[1],
(int32_t)largs[2], (int32_t)largs[3], (int32_t)largs[4], (int32_t)largs[5],
status);
}
if (U_FAILURE(status)) {
intl_error_set(NULL, status, "intlgregcal_create_instance: error "
"creating ICU GregorianCalendar from date", 0 TSRMLS_CC);
if (gcal) {
delete gcal;
}
Z_OBJ_P(return_value) = NULL;
return;
}
timelib_tzinfo *tzinfo = get_timezone_info(TSRMLS_C);
#if U_ICU_VERSION_MAJOR_NUM * 10 + U_ICU_VERSION_MINOR_NUM >= 42
UnicodeString tzstr = UnicodeString::fromUTF8(StringPiece(tzinfo->name));
#else
UnicodeString tzstr = UnicodeString(tzinfo->name,
strlen(tzinfo->name), US_INV);
#endif
if (tzstr.isBogus()) {
intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR,
"intlgregcal_create_instance: could not create UTF-8 string "
"from PHP's default timezone name (see date_default_timezone_get())",
0 TSRMLS_CC);
delete gcal;
Z_OBJ_P(return_value) = NULL;
return;
}
TimeZone *tz = TimeZone::createTimeZone(tzstr);
gcal->adoptTimeZone(tz);
}
Calendar_object *co = Z_INTL_CALENDAR_P(return_value);
co->ucal = gcal;
}
示例7: ids
void
ICUServiceTest::testAPI_Two()
{
UErrorCode status = U_ZERO_ERROR;
TestStringService service;
service.registerFactory(new AnonymousStringFactory(), status);
// anonymous factory will still handle the id
{
UErrorCode status = U_ZERO_ERROR;
const UnicodeString en_US = "en_US";
UnicodeString* result = (UnicodeString*)service.get(en_US, status);
confirmEqual("21) locale", result, &en_US);
delete result;
}
// still normalizes id
{
UErrorCode status = U_ZERO_ERROR;
const UnicodeString en_US_BAR = "en_US_BAR";
UnicodeString resultID;
UnicodeString* result = (UnicodeString*)service.get("EN_us_bar", &resultID, status);
confirmEqual("22) locale", &resultID, &en_US_BAR);
delete result;
}
// we can override for particular ids
UnicodeString* singleton0 = new UnicodeString("Zero");
service.registerInstance(singleton0, "en_US_BAR", status);
{
UErrorCode status = U_ZERO_ERROR;
UnicodeString* result = (UnicodeString*)service.get("en_US_BAR", status);
confirmEqual("23) override super", result, singleton0);
delete result;
}
// empty service should not recognize anything
service.reset();
{
UErrorCode status = U_ZERO_ERROR;
UnicodeString* result = (UnicodeString*)service.get("en_US", status);
confirmIdentical("24) empty", result, NULL);
}
// create a custom multiple key factory
{
UnicodeString xids[] = {
"en_US_VALLEY_GIRL",
"en_US_VALLEY_BOY",
"en_US_SURFER_GAL",
"en_US_SURFER_DUDE"
};
int32_t count = sizeof(xids)/sizeof(UnicodeString);
ICUServiceFactory* f = new TestMultipleKeyStringFactory(xids, count, "Later");
service.registerFactory(f, status);
}
// iterate over the visual ids returned by the multiple factory
{
UErrorCode status = U_ZERO_ERROR;
UVector ids(uhash_deleteUnicodeString, uhash_compareUnicodeString, 0, status);
service.getVisibleIDs(ids, status);
for (int i = 0; i < ids.size(); ++i) {
const UnicodeString* id = (const UnicodeString*)ids[i];
UnicodeString* result = (UnicodeString*)service.get(*id, status);
if (result) {
logln(" " + *id + " --> " + *result);
delete result;
} else {
errln("could not find " + *id);
}
}
// four visible ids
confirmIdentical("25) visible ids", ids.size(), 4);
}
// iterate over the display names
{
UErrorCode status = U_ZERO_ERROR;
UVector names(status);
service.getDisplayNames(names, status);
for (int i = 0; i < names.size(); ++i) {
const StringPair* pair = (const StringPair*)names[i];
logln(" " + pair->displayName + " --> " + pair->id);
}
confirmIdentical("26) display names", names.size(), 4);
}
// no valid display name
{
UnicodeString name;
service.getDisplayName("en_US_VALLEY_GEEK", name);
confirmBoolean("27) get display name", name.isBogus());
}
{
UnicodeString name;
service.getDisplayName("en_US_SURFER_DUDE", name, Locale::getEnglish());
confirmStringsEqual("28) get display name", name, "English (United States, SURFER_DUDE)");
//.........这里部分代码省略.........
示例8: resource
void
LocaleDisplayNamesImpl::initialize(void) {
LocaleDisplayNamesImpl *nonConstThis = (LocaleDisplayNamesImpl *)this;
nonConstThis->locale = langData.getLocale() == Locale::getRoot()
? regionData.getLocale()
: langData.getLocale();
UnicodeString sep;
langData.getNoFallback("localeDisplayPattern", "separator", sep);
if (sep.isBogus()) {
sep = UnicodeString("{0}, {1}", -1, US_INV);
}
UErrorCode status = U_ZERO_ERROR;
separatorFormat.applyPatternMinMaxArguments(sep, 2, 2, status);
UnicodeString pattern;
langData.getNoFallback("localeDisplayPattern", "pattern", pattern);
if (pattern.isBogus()) {
pattern = UnicodeString("{0} ({1})", -1, US_INV);
}
format.applyPatternMinMaxArguments(pattern, 2, 2, status);
if (pattern.indexOf((UChar)0xFF08) >= 0) {
formatOpenParen.setTo((UChar)0xFF08); // fullwidth (
formatReplaceOpenParen.setTo((UChar)0xFF3B); // fullwidth [
formatCloseParen.setTo((UChar)0xFF09); // fullwidth )
formatReplaceCloseParen.setTo((UChar)0xFF3D); // fullwidth ]
} else {
formatOpenParen.setTo((UChar)0x0028); // (
formatReplaceOpenParen.setTo((UChar)0x005B); // [
formatCloseParen.setTo((UChar)0x0029); // )
formatReplaceCloseParen.setTo((UChar)0x005D); // ]
}
UnicodeString ktPattern;
langData.get("localeDisplayPattern", "keyTypePattern", ktPattern);
if (ktPattern.isBogus()) {
ktPattern = UnicodeString("{0}={1}", -1, US_INV);
}
keyTypeFormat.applyPatternMinMaxArguments(ktPattern, 2, 2, status);
uprv_memset(fCapitalization, 0, sizeof(fCapitalization));
#if !UCONFIG_NO_BREAK_ITERATION
// Only get the context data if we need it! This is a const object so we know now...
// Also check whether we will need a break iterator (depends on the data)
UBool needBrkIter = FALSE;
if (capitalizationContext == UDISPCTX_CAPITALIZATION_FOR_UI_LIST_OR_MENU || capitalizationContext == UDISPCTX_CAPITALIZATION_FOR_STANDALONE) {
LocalUResourceBundlePointer resource(ures_open(NULL, locale.getName(), &status));
if (U_FAILURE(status)) { return; }
CapitalizationContextSink sink(*this);
ures_getAllItemsWithFallback(resource.getAlias(), "contextTransforms", sink, status);
if (status == U_MISSING_RESOURCE_ERROR) {
// Silently ignore. Not every locale has contextTransforms.
status = U_ZERO_ERROR;
} else if (U_FAILURE(status)) {
return;
}
needBrkIter = sink.hasCapitalizationUsage;
}
// Get a sentence break iterator if we will need it
if (needBrkIter || capitalizationContext == UDISPCTX_CAPITALIZATION_FOR_BEGINNING_OF_SENTENCE) {
status = U_ZERO_ERROR;
capitalizationBrkIter = BreakIterator::createSentenceInstance(locale, status);
if (U_FAILURE(status)) {
delete capitalizationBrkIter;
capitalizationBrkIter = NULL;
}
}
#endif
}
示例9: while
const UChar* U_EXPORT2
ZoneMeta::getCanonicalCLDRID(const UnicodeString &tzid, UErrorCode& status) {
if (U_FAILURE(status)) {
return NULL;
}
if (tzid.isBogus() || tzid.length() > ZID_KEY_MAX) {
status = U_ILLEGAL_ARGUMENT_ERROR;
return NULL;
}
// Checking the cached results
umtx_initOnce(gCanonicalIDCacheInitOnce, &initCanonicalIDCache, status);
if (U_FAILURE(status)) {
return NULL;
}
const UChar *canonicalID = NULL;
UErrorCode tmpStatus = U_ZERO_ERROR;
UChar utzid[ZID_KEY_MAX + 1];
tzid.extract(utzid, ZID_KEY_MAX + 1, tmpStatus);
U_ASSERT(tmpStatus == U_ZERO_ERROR); // we checked the length of tzid already
if (!uprv_isInvariantUString(utzid, -1)) {
// All of known tz IDs are only containing ASCII invariant characters.
status = U_ILLEGAL_ARGUMENT_ERROR;
return NULL;
}
// Check if it was already cached
umtx_lock(gZoneMetaLock());
{
canonicalID = (const UChar *)uhash_get(gCanonicalIDCache, utzid);
}
umtx_unlock(gZoneMetaLock());
if (canonicalID != NULL) {
return canonicalID;
}
// If not, resolve CLDR canonical ID with resource data
UBool isInputCanonical = FALSE;
char id[ZID_KEY_MAX + 1];
tzid.extract(0, 0x7fffffff, id, UPRV_LENGTHOF(id), US_INV);
// replace '/' with ':'
char *p = id;
while (*p++) {
if (*p == '/') {
*p = ':';
}
}
UResourceBundle *top = ures_openDirect(NULL, gKeyTypeData, &tmpStatus);
UResourceBundle *rb = ures_getByKey(top, gTypeMapTag, NULL, &tmpStatus);
ures_getByKey(rb, gTimezoneTag, rb, &tmpStatus);
ures_getByKey(rb, id, rb, &tmpStatus);
if (U_SUCCESS(tmpStatus)) {
// type entry (canonical) found
// the input is the canonical ID. resolve to const UChar*
canonicalID = TimeZone::findID(tzid);
isInputCanonical = TRUE;
}
if (canonicalID == NULL) {
// If a map element not found, then look for an alias
tmpStatus = U_ZERO_ERROR;
ures_getByKey(top, gTypeAliasTag, rb, &tmpStatus);
ures_getByKey(rb, gTimezoneTag, rb, &tmpStatus);
const UChar *canonical = ures_getStringByKey(rb,id,NULL,&tmpStatus);
if (U_SUCCESS(tmpStatus)) {
// canonical map found
canonicalID = canonical;
}
if (canonicalID == NULL) {
// Dereference the input ID using the tz data
const UChar *derefer = TimeZone::dereferOlsonLink(tzid);
if (derefer == NULL) {
status = U_ILLEGAL_ARGUMENT_ERROR;
} else {
int32_t len = u_strlen(derefer);
u_UCharsToChars(derefer,id,len);
id[len] = (char) 0; // Make sure it is null terminated.
// replace '/' with ':'
char *q = id;
while (*q++) {
if (*q == '/') {
*q = ':';
}
}
// If a dereference turned something up then look for an alias.
// rb still points to the alias table, so we don't have to go looking
// for it.
tmpStatus = U_ZERO_ERROR;
canonical = ures_getStringByKey(rb,id,NULL,&tmpStatus);
if (U_SUCCESS(tmpStatus)) {
//.........这里部分代码省略.........
示例10: adjustForUsageAndContext
UnicodeString&
LocaleDisplayNamesImpl::localeDisplayName(const Locale& locale,
UnicodeString& result) const {
if (locale.isBogus()) {
result.setToBogus();
return result;
}
UnicodeString resultName;
const char* lang = locale.getLanguage();
if (uprv_strlen(lang) == 0) {
lang = "root";
}
const char* script = locale.getScript();
const char* country = locale.getCountry();
const char* variant = locale.getVariant();
UBool hasScript = uprv_strlen(script) > 0;
UBool hasCountry = uprv_strlen(country) > 0;
UBool hasVariant = uprv_strlen(variant) > 0;
if (dialectHandling == ULDN_DIALECT_NAMES) {
char buffer[ULOC_FULLNAME_CAPACITY];
do { // loop construct is so we can break early out of search
if (hasScript && hasCountry) {
ncat(buffer, ULOC_FULLNAME_CAPACITY, lang, "_", script, "_", country, (char *)0);
localeIdName(buffer, resultName);
if (!resultName.isBogus()) {
hasScript = FALSE;
hasCountry = FALSE;
break;
}
}
if (hasScript) {
ncat(buffer, ULOC_FULLNAME_CAPACITY, lang, "_", script, (char *)0);
localeIdName(buffer, resultName);
if (!resultName.isBogus()) {
hasScript = FALSE;
break;
}
}
if (hasCountry) {
ncat(buffer, ULOC_FULLNAME_CAPACITY, lang, "_", country, (char*)0);
localeIdName(buffer, resultName);
if (!resultName.isBogus()) {
hasCountry = FALSE;
break;
}
}
} while (FALSE);
}
if (resultName.isBogus() || resultName.isEmpty()) {
localeIdName(lang, resultName);
}
UnicodeString resultRemainder;
UnicodeString temp;
UErrorCode status = U_ZERO_ERROR;
if (hasScript) {
resultRemainder.append(scriptDisplayName(script, temp, TRUE));
}
if (hasCountry) {
appendWithSep(resultRemainder, regionDisplayName(country, temp, TRUE));
}
if (hasVariant) {
appendWithSep(resultRemainder, variantDisplayName(variant, temp, TRUE));
}
resultRemainder.findAndReplace(formatOpenParen, formatReplaceOpenParen);
resultRemainder.findAndReplace(formatCloseParen, formatReplaceCloseParen);
LocalPointer<StringEnumeration> e(locale.createKeywords(status));
if (e.isValid() && U_SUCCESS(status)) {
UnicodeString temp2;
char value[ULOC_KEYWORD_AND_VALUES_CAPACITY]; // sigh, no ULOC_VALUE_CAPACITY
const char* key;
while ((key = e->next((int32_t *)0, status)) != NULL) {
locale.getKeywordValue(key, value, ULOC_KEYWORD_AND_VALUES_CAPACITY, status);
if (U_FAILURE(status)) {
return result;
}
keyDisplayName(key, temp, TRUE);
temp.findAndReplace(formatOpenParen, formatReplaceOpenParen);
temp.findAndReplace(formatCloseParen, formatReplaceCloseParen);
keyValueDisplayName(key, value, temp2, TRUE);
temp2.findAndReplace(formatOpenParen, formatReplaceOpenParen);
temp2.findAndReplace(formatCloseParen, formatReplaceCloseParen);
if (temp2 != UnicodeString(value, -1, US_INV)) {
appendWithSep(resultRemainder, temp2);
} else if (temp != UnicodeString(key, -1, US_INV)) {
UnicodeString temp3;
keyTypeFormat.format(temp, temp2, temp3, status);
appendWithSep(resultRemainder, temp3);
} else {
appendWithSep(resultRemainder, temp)
.append((UChar)0x3d /* = */)
.append(temp2);
}
}
}
//.........这里部分代码省略.........
示例11: sink
void UTS46Test::TestAPI() {
UErrorCode errorCode=U_ZERO_ERROR;
UnicodeString result;
IDNAInfo info;
UnicodeString input=UNICODE_STRING_SIMPLE("www.eXample.cOm");
UnicodeString expected=UNICODE_STRING_SIMPLE("www.example.com");
trans->nameToASCII(input, result, info, errorCode);
if(U_FAILURE(errorCode) || info.hasErrors() || result!=expected) {
errln("T.nameToASCII(www.example.com) info.errors=%04lx result matches=%d %s",
(long)info.getErrors(), result==expected, u_errorName(errorCode));
}
errorCode=U_USELESS_COLLATOR_ERROR;
trans->nameToUnicode(input, result, info, errorCode);
if(errorCode!=U_USELESS_COLLATOR_ERROR || !result.isBogus()) {
errln("T.nameToUnicode(U_FAILURE) did not preserve the errorCode "
"or not result.setToBogus() - %s",
u_errorName(errorCode));
}
errorCode=U_ZERO_ERROR;
input.setToBogus();
result=UNICODE_STRING_SIMPLE("quatsch");
nontrans->labelToASCII(input, result, info, errorCode);
if(errorCode!=U_ILLEGAL_ARGUMENT_ERROR || !result.isBogus()) {
errln("N.labelToASCII(bogus) did not set illegal-argument-error "
"or not result.setToBogus() - %s",
u_errorName(errorCode));
}
errorCode=U_ZERO_ERROR;
input=UNICODE_STRING_SIMPLE("xn--bcher.de-65a");
expected=UNICODE_STRING_SIMPLE("xn--bcher\\uFFFDde-65a").unescape();
nontrans->labelToASCII(input, result, info, errorCode);
if( U_FAILURE(errorCode) ||
info.getErrors()!=(UIDNA_ERROR_LABEL_HAS_DOT|UIDNA_ERROR_INVALID_ACE_LABEL) ||
result!=expected
) {
errln("N.labelToASCII(label-with-dot) failed with errors %04lx - %s",
info.getErrors(), u_errorName(errorCode));
}
// UTF-8
char buffer[100];
TestCheckedArrayByteSink sink(buffer, UPRV_LENGTHOF(buffer));
errorCode=U_ZERO_ERROR;
nontrans->labelToUnicodeUTF8(StringPiece(NULL, 5), sink, info, errorCode);
if(errorCode!=U_ILLEGAL_ARGUMENT_ERROR || sink.NumberOfBytesWritten()!=0) {
errln("N.labelToUnicodeUTF8(StringPiece(NULL, 5)) did not set illegal-argument-error ",
"or did output something - %s",
u_errorName(errorCode));
}
sink.Reset();
errorCode=U_ZERO_ERROR;
nontrans->nameToASCII_UTF8(StringPiece(), sink, info, errorCode);
if(U_FAILURE(errorCode) || sink.NumberOfBytesWritten()!=0 || !sink.calledFlush) {
errln("N.nameToASCII_UTF8(empty) failed - %s",
u_errorName(errorCode));
}
static const char s[]={ 0x61, (char)0xc3, (char)0x9f };
sink.Reset();
errorCode=U_USELESS_COLLATOR_ERROR;
nontrans->nameToUnicodeUTF8(StringPiece(s, 3), sink, info, errorCode);
if(errorCode!=U_USELESS_COLLATOR_ERROR || sink.NumberOfBytesWritten()!=0) {
errln("N.nameToUnicode_UTF8(U_FAILURE) did not preserve the errorCode "
"or did output something - %s",
u_errorName(errorCode));
}
sink.Reset();
errorCode=U_ZERO_ERROR;
trans->labelToUnicodeUTF8(StringPiece(s, 3), sink, info, errorCode);
if( U_FAILURE(errorCode) || sink.NumberOfBytesWritten()!=3 ||
buffer[0]!=0x61 || buffer[1]!=0x73 || buffer[2]!=0x73 ||
!sink.calledFlush
) {
errln("T.labelToUnicodeUTF8(a sharp-s) failed - %s",
u_errorName(errorCode));
}
sink.Reset();
errorCode=U_ZERO_ERROR;
// "eXampLe.cOm"
static const char eX[]={ 0x65, 0x58, 0x61, 0x6d, 0x70, 0x4c, 0x65, 0x2e, 0x63, 0x4f, 0x6d, 0 };
// "example.com"
static const char ex[]={ 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x2e, 0x63, 0x6f, 0x6d };
trans->nameToUnicodeUTF8(eX, sink, info, errorCode);
if( U_FAILURE(errorCode) || sink.NumberOfBytesWritten()!=11 ||
0!=memcmp(ex, buffer, 11) || !sink.calledFlush
) {
errln("T.nameToUnicodeUTF8(eXampLe.cOm) failed - %s",
u_errorName(errorCode));
}
}
示例12: isSet
inline UBool isSet() const {
return !prefix.isBogus();
}
示例13: match
bool DecimalMatcher::match(StringSegment& segment, ParsedNumber& result, int8_t exponentSign,
UErrorCode&) const {
if (result.seenNumber() && exponentSign == 0) {
// A number has already been consumed.
return false;
} else if (exponentSign != 0) {
// scientific notation always comes after the number
U_ASSERT(!result.quantity.bogus);
}
// Initial offset before any character consumption.
int32_t initialOffset = segment.getOffset();
// Return value: whether to ask for more characters.
bool maybeMore = false;
// All digits consumed so far.
number::impl::DecimalQuantity digitsConsumed;
digitsConsumed.bogus = true;
// The total number of digits after the decimal place, used for scaling the result.
int32_t digitsAfterDecimalPlace = 0;
// The actual grouping and decimal separators used in the string.
// If non-null, we have seen that token.
UnicodeString actualGroupingString;
UnicodeString actualDecimalString;
actualGroupingString.setToBogus();
actualDecimalString.setToBogus();
// Information for two groups: the previous group and the current group.
//
// Each group has three pieces of information:
//
// Offset: the string position of the beginning of the group, including a leading separator
// if there was a leading separator. This is needed in case we need to rewind the parse to
// that position.
//
// Separator type:
// 0 => beginning of string
// 1 => lead separator is a grouping separator
// 2 => lead separator is a decimal separator
//
// Count: the number of digits in the group. If -1, the group has been validated.
int32_t currGroupOffset = 0;
int32_t currGroupSepType = 0;
int32_t currGroupCount = 0;
int32_t prevGroupOffset = -1;
int32_t prevGroupSepType = -1;
int32_t prevGroupCount = -1;
while (segment.length() > 0) {
maybeMore = false;
// Attempt to match a digit.
int8_t digit = -1;
// Try by code point digit value.
UChar32 cp = segment.getCodePoint();
if (u_isdigit(cp)) {
segment.adjustOffset(U16_LENGTH(cp));
digit = static_cast<int8_t>(u_digit(cp, 10));
}
// Try by digit string.
if (digit == -1 && !fLocalDigitStrings.isNull()) {
for (int32_t i = 0; i < 10; i++) {
const UnicodeString& str = fLocalDigitStrings[i];
if (str.isEmpty()) {
continue;
}
int32_t overlap = segment.getCommonPrefixLength(str);
if (overlap == str.length()) {
segment.adjustOffset(overlap);
digit = static_cast<int8_t>(i);
break;
}
maybeMore = maybeMore || (overlap == segment.length());
}
}
if (digit >= 0) {
// Digit was found.
if (digitsConsumed.bogus) {
digitsConsumed.bogus = false;
digitsConsumed.clear();
}
digitsConsumed.appendDigit(digit, 0, true);
currGroupCount++;
if (!actualDecimalString.isBogus()) {
digitsAfterDecimalPlace++;
}
continue;
}
// Attempt to match a literal grouping or decimal separator.
bool isDecimal = false;
bool isGrouping = false;
// 1) Attempt the decimal separator string literal.
//.........这里部分代码省略.........
示例14:
/* {{{ timezone_convert_to_datetimezone
* Convert from TimeZone to DateTimeZone object */
U_CFUNC zval *timezone_convert_to_datetimezone(const TimeZone *timeZone,
intl_error *outside_error,
const char *func, zval *ret)
{
UnicodeString id;
char *message = NULL;
php_timezone_obj *tzobj;
zval arg;
timeZone->getID(id);
if (id.isBogus()) {
spprintf(&message, 0, "%s: could not obtain TimeZone id", func);
intl_errors_set(outside_error, U_ILLEGAL_ARGUMENT_ERROR,
message, 1);
goto error;
}
object_init_ex(ret, php_date_get_timezone_ce());
tzobj = Z_PHPTIMEZONE_P(ret);
if (id.compare(0, 3, UnicodeString("GMT", sizeof("GMT")-1, US_INV)) == 0) {
/* The DateTimeZone constructor doesn't support offset time zones,
* so we must mess with DateTimeZone structure ourselves */
tzobj->initialized = 1;
tzobj->type = TIMELIB_ZONETYPE_OFFSET;
//convert offset from milliseconds to minutes
tzobj->tzi.utc_offset = -1 * timeZone->getRawOffset() / (60 * 1000);
} else {
char *str;
size_t str_len;
/* Call the constructor! */
if (intl_charFromString(id, &str, &str_len, &INTL_ERROR_CODE(*outside_error)) == FAILURE) {
spprintf(&message, 0, "%s: could not convert id to UTF-8", func);
intl_errors_set(outside_error, INTL_ERROR_CODE(*outside_error),
message, 1);
goto error;
}
ZVAL_STRINGL(&arg, str, str_len);
//???
efree(str);
zend_call_method_with_1_params(ret, NULL, NULL, "__construct", NULL, &arg);
if (EG(exception)) {
spprintf(&message, 0,
"%s: DateTimeZone constructor threw exception", func);
intl_errors_set(outside_error, U_ILLEGAL_ARGUMENT_ERROR,
message, 1);
zend_object_store_ctor_failed(Z_OBJ_P(ret));
zval_ptr_dtor(&arg);
goto error;
}
zval_ptr_dtor(&arg);
}
if (0) {
error:
if (ret) {
zval_ptr_dtor(ret);
}
ret = NULL;
}
if (message) {
efree(message);
}
return ret;
}
示例15: UnicodeString
void
LocaleDisplayNamesImpl::initialize(void) {
LocaleDisplayNamesImpl *nonConstThis = (LocaleDisplayNamesImpl *)this;
nonConstThis->locale = langData.getLocale() == Locale::getRoot()
? regionData.getLocale()
: langData.getLocale();
UnicodeString sep;
langData.getNoFallback("localeDisplayPattern", "separator", sep);
if (sep.isBogus()) {
sep = UnicodeString("{0}, {1}", -1, US_INV);
}
UErrorCode status = U_ZERO_ERROR;
separatorFormat.applyPatternMinMaxArguments(sep, 2, 2, status);
UnicodeString pattern;
langData.getNoFallback("localeDisplayPattern", "pattern", pattern);
if (pattern.isBogus()) {
pattern = UnicodeString("{0} ({1})", -1, US_INV);
}
format.applyPatternMinMaxArguments(pattern, 2, 2, status);
if (pattern.indexOf((UChar)0xFF08) >= 0) {
formatOpenParen.setTo((UChar)0xFF08); // fullwidth (
formatReplaceOpenParen.setTo((UChar)0xFF3B); // fullwidth [
formatCloseParen.setTo((UChar)0xFF09); // fullwidth )
formatReplaceCloseParen.setTo((UChar)0xFF3D); // fullwidth ]
} else {
formatOpenParen.setTo((UChar)0x0028); // (
formatReplaceOpenParen.setTo((UChar)0x005B); // [
formatCloseParen.setTo((UChar)0x0029); // )
formatReplaceCloseParen.setTo((UChar)0x005D); // ]
}
UnicodeString ktPattern;
langData.get("localeDisplayPattern", "keyTypePattern", ktPattern);
if (ktPattern.isBogus()) {
ktPattern = UnicodeString("{0}={1}", -1, US_INV);
}
keyTypeFormat.applyPatternMinMaxArguments(ktPattern, 2, 2, status);
uprv_memset(fCapitalization, 0, sizeof(fCapitalization));
#if !UCONFIG_NO_BREAK_ITERATION
// The following is basically copied from DateFormatSymbols::initializeData
typedef struct {
const char * usageName;
LocaleDisplayNamesImpl::CapContextUsage usageEnum;
} ContextUsageNameToEnum;
const ContextUsageNameToEnum contextUsageTypeMap[] = {
// Entries must be sorted by usageTypeName; entry with NULL name terminates list.
{ "key", kCapContextUsageKey },
{ "keyValue", kCapContextUsageKeyValue },
{ "languages", kCapContextUsageLanguage },
{ "script", kCapContextUsageScript },
{ "territory", kCapContextUsageTerritory },
{ "variant", kCapContextUsageVariant },
{ NULL, (CapContextUsage)0 },
};
// Only get the context data if we need it! This is a const object so we know now...
// Also check whether we will need a break iterator (depends on the data)
UBool needBrkIter = FALSE;
if (capitalizationContext == UDISPCTX_CAPITALIZATION_FOR_UI_LIST_OR_MENU || capitalizationContext == UDISPCTX_CAPITALIZATION_FOR_STANDALONE) {
int32_t len = 0;
UResourceBundle *localeBundle = ures_open(NULL, locale.getName(), &status);
if (U_SUCCESS(status)) {
UResourceBundle *contextTransforms = ures_getByKeyWithFallback(localeBundle, "contextTransforms", NULL, &status);
if (U_SUCCESS(status)) {
UResourceBundle *contextTransformUsage;
while ( (contextTransformUsage = ures_getNextResource(contextTransforms, NULL, &status)) != NULL ) {
const int32_t * intVector = ures_getIntVector(contextTransformUsage, &len, &status);
if (U_SUCCESS(status) && intVector != NULL && len >= 2) {
const char* usageKey = ures_getKey(contextTransformUsage);
if (usageKey != NULL) {
const ContextUsageNameToEnum * typeMapPtr = contextUsageTypeMap;
int32_t compResult = 0;
// linear search; list is short and we cannot be sure that bsearch is available
while ( typeMapPtr->usageName != NULL && (compResult = uprv_strcmp(usageKey, typeMapPtr->usageName)) > 0 ) {
++typeMapPtr;
}
if (typeMapPtr->usageName != NULL && compResult == 0) {
int32_t titlecaseInt = (capitalizationContext == UDISPCTX_CAPITALIZATION_FOR_UI_LIST_OR_MENU)? intVector[0]: intVector[1];
if (titlecaseInt != 0) {
fCapitalization[typeMapPtr->usageEnum] = TRUE;;
needBrkIter = TRUE;
}
}
}
}
status = U_ZERO_ERROR;
ures_close(contextTransformUsage);
}
ures_close(contextTransforms);
}
ures_close(localeBundle);
}
}
// Get a sentence break iterator if we will need it
if (needBrkIter || capitalizationContext == UDISPCTX_CAPITALIZATION_FOR_BEGINNING_OF_SENTENCE) {
status = U_ZERO_ERROR;
capitalizationBrkIter = BreakIterator::createSentenceInstance(locale, status);
if (U_FAILURE(status)) {
//.........这里部分代码省略.........