Locale RuleBasedNumberFormat::getRuleSetDisplayNameLocale(int32_t index, UErrorCode& status) const { if (U_FAILURE(status)) { return Locale(""); } if (localizations && index >= 0 && index < localizations->getNumberOfDisplayLocales()) { UnicodeString name(TRUE, localizations->getLocaleName(index), -1); char buffer[64]; int32_t cap = name.length() + 1; char* bp = buffer; if (cap > 64) { bp = (char *)uprv_malloc(cap); if (bp == NULL) { status = U_MEMORY_ALLOCATION_ERROR; return Locale(""); } } name.extract(0, name.length(), bp, cap, UnicodeString::kInvariant); Locale retLocale(bp); if (bp != buffer) { uprv_free(bp); } return retLocale; } status = U_ILLEGAL_ARGUMENT_ERROR; Locale retLocale; return retLocale; }
void IntlTestNumberFormat::monsterTest(/* char* par */) { const char *SEP = "============================================================\n"; int32_t count; const Locale* allLocales = NumberFormat::getAvailableLocales(count); Locale* locales = (Locale*)allLocales; Locale quickLocales[6]; if (allLocales && count) { if (quick && count > 6) { logln("quick test: testing just 6 locales!"); count = 6; locales = quickLocales; locales[0] = allLocales[0]; locales[1] = allLocales[1]; locales[2] = allLocales[2]; // In a quick test, make sure we test locales that use // currency prefix, currency suffix, and choice currency // logic. Otherwise bugs in these areas can slip through. locales[3] = Locale("ar", "AE", ""); locales[4] = Locale("cs", "CZ", ""); locales[5] = Locale("en", "IN", ""); } for (int32_t i=0; i<count; ++i) { UnicodeString name(locales[i].getName(), ""); logln(SEP); testLocale(/* par, */locales[i], name); } } logln(SEP); }
void RBBIAPITest::TestBoilerPlate() { UErrorCode status = U_ZERO_ERROR; BreakIterator* a = BreakIterator::createWordInstance(Locale("hi"), status); BreakIterator* b = BreakIterator::createWordInstance(Locale("hi_IN"),status); if (U_FAILURE(status)) { errcheckln(status, "Creation of break iterator failed %s", u_errorName(status)); return; } if(*a!=*b){ errln("Failed: boilerplate method operator!= does not return correct results"); } // Japanese word break iterators are identical to root with // a dictionary-based break iterator BreakIterator* c = BreakIterator::createCharacterInstance(Locale("ja"),status); BreakIterator* d = BreakIterator::createCharacterInstance(Locale("root"),status); if(c && d){ if(*c!=*d){ errln("Failed: boilerplate method operator== does not return correct results"); } }else{ errln("creation of break iterator failed"); } delete a; delete b; delete c; delete d; }
void NewResourceBundleTest::TestResourceBundles() { UErrorCode status = U_ZERO_ERROR; loadTestData(status); if(U_FAILURE(status)) { dataerrln("Could not load testdata.dat %s " + UnicodeString(u_errorName(status))); return; } /* Make sure that users using te_IN for the default locale don't get test failures. */ Locale originalDefault; if (Locale::getDefault() == Locale("te_IN")) { Locale::setDefault(Locale("en_US"), status); } testTag("only_in_Root", TRUE, FALSE, FALSE); testTag("only_in_te", FALSE, TRUE, FALSE); testTag("only_in_te_IN", FALSE, FALSE, TRUE); testTag("in_Root_te", TRUE, TRUE, FALSE); testTag("in_Root_te_te_IN", TRUE, TRUE, TRUE); testTag("in_Root_te_IN", TRUE, FALSE, TRUE); testTag("in_te_te_IN", FALSE, TRUE, TRUE); testTag("nonexistent", FALSE, FALSE, FALSE); logln("Passed: %d\nFailed: %d", pass, fail); /* Restore the default locale for the other tests. */ Locale::setDefault(originalDefault, status); }
U_CAPI UCalendar* U_EXPORT2 ucal_open( const UChar* zoneID, int32_t len, const char* locale, UCalendarType caltype, UErrorCode* status) { if(U_FAILURE(*status)) return 0; TimeZone* zone = (zoneID==NULL) ? TimeZone::createDefault() : _createTimeZone(zoneID, len, status); if (U_FAILURE(*status)) { return NULL; } if ( caltype == UCAL_GREGORIAN ) { char localeBuf[ULOC_LOCALE_IDENTIFIER_CAPACITY]; if ( locale == NULL ) { locale = uloc_getDefault(); } uprv_strncpy(localeBuf, locale, ULOC_LOCALE_IDENTIFIER_CAPACITY); uloc_setKeywordValue("calendar", "gregorian", localeBuf, ULOC_LOCALE_IDENTIFIER_CAPACITY, status); if (U_FAILURE(*status)) { return NULL; } return (UCalendar*)Calendar::createInstance(zone, Locale(localeBuf), *status); } return (UCalendar*)Calendar::createInstance(zone, Locale(locale), *status); }
U_CAPI UDateFormat* U_EXPORT2 udat_open(UDateFormatStyle timeStyle, UDateFormatStyle dateStyle, const char *locale, const UChar *tzID, int32_t tzIDLength, const UChar *pattern, int32_t patternLength, UErrorCode *status) { DateFormat *fmt; if(U_FAILURE(*status)) { return 0; } if(gOpener!=NULL) { // if it's registered fmt = (DateFormat*) (*gOpener)(timeStyle,dateStyle,locale,tzID,tzIDLength,pattern,patternLength,status); if(fmt!=NULL) { return (UDateFormat*)fmt; } // else fall through. } if(timeStyle != UDAT_PATTERN) { if(locale == 0) { fmt = DateFormat::createDateTimeInstance((DateFormat::EStyle)dateStyle, (DateFormat::EStyle)timeStyle); } else { fmt = DateFormat::createDateTimeInstance((DateFormat::EStyle)dateStyle, (DateFormat::EStyle)timeStyle, Locale(locale)); } } else { UnicodeString pat((UBool)(patternLength == -1), pattern, patternLength); if(locale == 0) { fmt = new SimpleDateFormat(pat, *status); } else { fmt = new SimpleDateFormat(pat, Locale(locale), *status); } } if(fmt == 0) { *status = U_MEMORY_ALLOCATION_ERROR; return 0; } if(tzID != 0) { TimeZone *zone = TimeZone::createTimeZone(UnicodeString((UBool)(tzIDLength == -1), tzID, tzIDLength)); if(zone == 0) { *status = U_MEMORY_ALLOCATION_ERROR; delete fmt; return 0; } fmt->adoptTimeZone(zone); } return (UDateFormat*)fmt; }
//---------------------------------------------------------------------------------------- // // ubrk_open Create a canned type of break iterator based on type (word, line, etc.) // and locale. // //---------------------------------------------------------------------------------------- U_CAPI UBreakIterator* U_EXPORT2 ubrk_open(UBreakIteratorType type, const char *locale, const UChar *text, int32_t textLength, UErrorCode *status) { if(U_FAILURE(*status)) return 0; BreakIterator *result = 0; switch(type) { case UBRK_CHARACTER: result = BreakIterator::createCharacterInstance(Locale(locale), *status); break; case UBRK_WORD: result = BreakIterator::createWordInstance(Locale(locale), *status); break; case UBRK_LINE: result = BreakIterator::createLineInstance(Locale(locale), *status); break; case UBRK_SENTENCE: result = BreakIterator::createSentenceInstance(Locale(locale), *status); break; case UBRK_TITLE: result = BreakIterator::createTitleInstance(Locale(locale), *status); break; } // check for allocation error if (U_FAILURE(*status)) { return 0; } if(result == 0) { *status = U_MEMORY_ALLOCATION_ERROR; return 0; } if (text != NULL) { UCharCharacterIterator *iter = 0; iter = new UCharCharacterIterator(text, textLength); if(iter == 0) { *status = U_MEMORY_ALLOCATION_ERROR; delete result; return 0; } result->adoptText(iter); } return (UBreakIterator*)result; }
void MallocState::print(llvm::raw_ostream &Out, seec::util::IndentationGuide &Indentation) const { std::string AddressString; { llvm::raw_string_ostream AddressStringStream(AddressString); seec::util::write_hex_padded(AddressStringStream, this->getAddress()); } auto const LazyDescription = seec::LazyMessageByRef::create("SeeCClang", {"states", "MallocState"}, std::make_pair("size", int64_t(this->getSize())), std::make_pair("address", AddressString.c_str())); UErrorCode ICUStatus = U_ZERO_ERROR; auto const Description = LazyDescription->get(ICUStatus, Locale()); if (U_FAILURE(ICUStatus)) return; Out << Indentation.getString() << Description << "\n"; auto const Mapping = this->getAllocatorInstMapping(); if (auto const Stmt = Mapping.getStmt()) { Indentation.indent(); auto const &AST = Mapping.getAST()->getASTUnit(); auto const &SrcManager = AST.getSourceManager(); auto const LocStart = Stmt->getLocStart(); auto const Filename = SrcManager.getFilename(LocStart); auto const Line = SrcManager.getSpellingLineNumber(LocStart); auto const Column = SrcManager.getSpellingColumnNumber(LocStart); auto const LazyLocation = seec::LazyMessageByRef::create("SeeCClang", {"states", "MallocStateAllocatedAt"}, std::make_pair("filename", Filename.str().c_str()), std::make_pair("line", int64_t(Line)), std::make_pair("column", int64_t(Column))); auto const Location = LazyLocation->get(ICUStatus, Locale()); if (U_SUCCESS(ICUStatus)) Out << Indentation.getString() << Location << "\n"; Indentation.unindent(); } }
//------------------------------------------------------------------------------ // // ubrk_open Create a canned type of break iterator based on type (word, line, etc.) // and locale. // //------------------------------------------------------------------------------ U_CAPI UBreakIterator* U_EXPORT2 ubrk_open(UBreakIteratorType type, const char *locale, const UChar *text, int32_t textLength, UErrorCode *status) { if(U_FAILURE(*status)) return 0; BreakIterator *result = 0; switch(type) { case UBRK_CHARACTER: result = BreakIterator::createCharacterInstance(Locale(locale), *status); break; case UBRK_WORD: result = BreakIterator::createWordInstance(Locale(locale), *status); break; case UBRK_LINE: result = BreakIterator::createLineInstance(Locale(locale), *status); break; case UBRK_SENTENCE: result = BreakIterator::createSentenceInstance(Locale(locale), *status); break; case UBRK_TITLE: result = BreakIterator::createTitleInstance(Locale(locale), *status); break; default: *status = U_ILLEGAL_ARGUMENT_ERROR; } // check for allocation error if (U_FAILURE(*status)) { return 0; } if(result == 0) { *status = U_MEMORY_ALLOCATION_ERROR; return 0; } UBreakIterator *uBI = (UBreakIterator *)result; if (text != NULL) { ubrk_setText(uBI, text, textLength, status); } return uBI; }
static void U_CALLCONV initAvailableLocaleList(UErrorCode &status) { U_ASSERT(availableLocaleListCount == 0); U_ASSERT(availableLocaleList == NULL); // for now, there is a hardcoded list, so just walk through that list and set it up. UResourceBundle *index = NULL; UResourceBundle installed; int32_t i = 0; ures_initStackObject(&installed); index = ures_openDirect(U_ICUDATA_COLL, "res_index", &status); ures_getByKey(index, "InstalledLocales", &installed, &status); if(U_SUCCESS(status)) { availableLocaleListCount = ures_getSize(&installed); availableLocaleList = new Locale[availableLocaleListCount]; if (availableLocaleList != NULL) { ures_resetIterator(&installed); while(ures_hasNext(&installed)) { const char *tempKey = NULL; ures_getNextString(&installed, NULL, &tempKey, &status); availableLocaleList[i++] = Locale(tempKey); } } U_ASSERT(availableLocaleListCount == i); ures_close(&installed); } ures_close(index); ucln_i18n_registerCleanup(UCLN_I18N_COLLATOR, collator_cleanup); }
/* When the default locale is tr, make sure that the pattern can still be parsed. */ void TestMessageFormat::TestTurkishCasing() { UErrorCode err = U_ZERO_ERROR; Locale saveDefaultLocale; Locale::setDefault( Locale("tr"), err ); Formattable arguments[] = { (int32_t)7, Formattable(UDate(8.71068e+011), Formattable::kIsDate), "a disturbance in the Force" }; UnicodeString result; result = MessageFormat::format( "At {1,TIME} on {1,DATE,SHORT}, there was {2} on planet {0,NUMBER,INTEGER}.", arguments, 3, result, err); if (U_FAILURE(err)) { errln("TestTurkishCasing #1 with error code %s", u_errorName(err)); return; } const UnicodeString expected( "At 12:20:00 on 08.08.1997, there was a disturbance in the Force on planet 7.", ""); if (result != expected) { errln("TestTurkishCasing failed on test"); errln( UnicodeString(" Result: ") + result ); errln( UnicodeString(" Expected: ") + expected ); } Locale::setDefault( saveDefaultLocale, err ); }
void EthiopicCalendar::initializeSystemDefaultCentury() { // lazy-evaluate systemDefaultCenturyStart UBool needsUpdate; UMTX_CHECK(NULL, (fgSystemDefaultCenturyStart == fgSystemDefaultCentury), needsUpdate); if (!needsUpdate) { return; } UErrorCode status = U_ZERO_ERROR; EthiopicCalendar calendar(Locale("@calendar=ethiopic"), status); if (U_SUCCESS(status)) { calendar.setTime(Calendar::getNow(), status); calendar.add(UCAL_YEAR, -80, status); UDate newStart = calendar.getTime(status); int32_t newYear = calendar.get(UCAL_YEAR, status); { umtx_lock(NULL); fgSystemDefaultCenturyStartYear = newYear; fgSystemDefaultCenturyStart = newStart; umtx_unlock(NULL); } } // We have no recourse upon failure unless we want to propagate the failure // out. }
/** * Internal function to look up currency data. Result is an array of * two integers. The first is the fraction digits. The second is the * rounding increment, or 0 if none. The rounding increment is in * units of 10^(-fraction_digits). */ static const int32_t* _findMetaData(const UChar* currency) { // Get CurrencyMeta resource out of root locale file. [This may // move out of the root locale file later; if it does, update this // code.] UErrorCode ec = U_ZERO_ERROR; ResourceBundle currencyMeta = ResourceBundle((char*)0, Locale(""), ec).get(CURRENCY_META, ec); if (U_FAILURE(ec)) { // Config/build error; return hard-coded defaults return LAST_RESORT_DATA; } // Look up our currency, or if that's not available, then DEFAULT char buf[ISO_COUNTRY_CODE_LENGTH+1]; ResourceBundle rb = currencyMeta.get(myUCharsToChars(buf, currency), ec); if (U_FAILURE(ec)) { rb = currencyMeta.get(DEFAULT_META, ec); if (U_FAILURE(ec)) { // Config/build error; return hard-coded defaults return LAST_RESORT_DATA; } } int32_t len; const int32_t *data = rb.getIntVector(len, ec); if (U_FAILURE(ec) || len < 2) { // Config/build error; return hard-coded defaults return LAST_RESORT_DATA; } return data; }
void DateFormatRoundTripTest::TestDateFormatRoundTrip() { UErrorCode status = U_ZERO_ERROR; getFieldCal = Calendar::createInstance(status); failure(status, "Calendar::createInstance"); if(!assertSuccess("trying to construct", status))return; int32_t locCount = 0; const Locale *avail = DateFormat::getAvailableLocales(locCount); logln("DateFormat available locales: %d", locCount); if(quick) { SPARSENESS = 18; logln("Quick mode: only testing SPARSENESS = 18"); } TimeZone *tz = TimeZone::createDefault(); UnicodeString temp; logln("Default TimeZone: " + tz->getID(temp)); delete tz; #ifdef TEST_ONE_LOC // define this to just test ONE locale. Locale loc(TEST_ONE_LOC); test(loc); #if INFINITE for(;;) { test(loc); } #endif #else # if INFINITE // Special infinite loop test mode for finding hard to reproduce errors Locale loc = Locale::getDefault(); logln("ENTERING INFINITE TEST LOOP FOR Locale: " + loc.getDisplayName(temp)); for(;;) test(loc); # else test(Locale::getDefault()); #if 1 // installed locales for (int i=0; i < locCount; ++i) { test(avail[i]); } #endif #if 1 // special locales int32_t jCount = CalendarTest::testLocaleCount(); for (int32_t j=0; j < jCount; ++j) { test(Locale(CalendarTest::testLocaleID(j))); } #endif # endif #endif delete getFieldCal; }
U_CAPI int32_t U_EXPORT2 ucasemap_utf8ToTitle(UCaseMap *csm, char *dest, int32_t destCapacity, const char *src, int32_t srcLength, UErrorCode *pErrorCode) { if (U_FAILURE(*pErrorCode)) { return 0; } UText utext=UTEXT_INITIALIZER; utext_openUTF8(&utext, (const char *)src, srcLength, pErrorCode); if(csm->iter==NULL) { csm->iter=BreakIterator::createWordInstance(Locale(csm->locale), *pErrorCode); } if (U_FAILURE(*pErrorCode)) { return 0; } csm->iter->setText(&utext, *pErrorCode); int32_t length=ucasemap_mapUTF8( csm->caseLocale, csm->options, csm->iter, (uint8_t *)dest, destCapacity, (const uint8_t *)src, srcLength, ucasemap_internalUTF8ToTitle, pErrorCode); utext_close(&utext); return length; }
U_NAMESPACE_USE /* functions available in the common library (for unistr_case.cpp) */ /* public API functions */ U_CAPI int32_t U_EXPORT2 u_strToTitle(UChar *dest, int32_t destCapacity, const UChar *src, int32_t srcLength, UBreakIterator *titleIter, const char *locale, UErrorCode *pErrorCode) { LocalPointer<BreakIterator> ownedIter; BreakIterator *iter; if(titleIter!=NULL) { iter=reinterpret_cast<BreakIterator *>(titleIter); } else { iter=BreakIterator::createWordInstance(Locale(locale), *pErrorCode); ownedIter.adoptInstead(iter); } if(U_FAILURE(*pErrorCode)) { return 0; } UnicodeString s(srcLength<0, src, srcLength); iter->setText(s); return ustrcase_mapWithOverlap( ustrcase_getCaseLocale(locale), 0, iter, dest, destCapacity, src, srcLength, ustrcase_internalToTitle, *pErrorCode); }
void IslamicCalendar::initializeSystemDefaultCentury() { // initialize systemDefaultCentury and systemDefaultCenturyYear based // on the current time. They'll be set to 80 years before // the current time. // No point in locking as it should be idempotent. if (fgSystemDefaultCenturyStart == fgSystemDefaultCentury) { UErrorCode status = U_ZERO_ERROR; Calendar *calendar = new IslamicCalendar(Locale("ar@calendar=islamic-civil"),status); if (calendar != NULL && U_SUCCESS(status)) { calendar->setTime(Calendar::getNow(), status); calendar->add(UCAL_YEAR, -80, status); UDate newStart = calendar->getTime(status); int32_t newYear = calendar->get(UCAL_YEAR, status); { Mutex m; fgSystemDefaultCenturyStart = newStart; fgSystemDefaultCenturyStartYear = newYear; } delete calendar; } // We have no recourse upon failure unless we want to propagate the failure // out. } }
// Verify that Gregorian works like Gregorian void IntlCalendarTest::TestGregorian() { UDate timeA = Calendar::getNow(); int32_t data[] = { GregorianCalendar::AD, 1868, 1868, UCAL_SEPTEMBER, 8, GregorianCalendar::AD, 1868, 1868, UCAL_SEPTEMBER, 9, GregorianCalendar::AD, 1869, 1869, UCAL_JUNE, 4, GregorianCalendar::AD, 1912, 1912, UCAL_JULY, 29, GregorianCalendar::AD, 1912, 1912, UCAL_JULY, 30, GregorianCalendar::AD, 1912, 1912, UCAL_AUGUST, 1, -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1 }; Calendar *cal; UErrorCode status = U_ZERO_ERROR; cal = Calendar::createInstance(/*"de_DE", */ status); CHECK(status, UnicodeString("Creating de_CH calendar")); // Sanity check the calendar UDate timeB = Calendar::getNow(); UDate timeCal = cal->getTime(status); if(!(timeA <= timeCal) || !(timeCal <= timeB)) { errln((UnicodeString)"Error: Calendar time " + timeCal + " is not within sampled times [" + timeA + " to " + timeB + "]!"); } // end sanity check // Note, the following is a good way to test the sanity of the constructed calendars, // using Collation as a delay-loop: // // $ intltest format/IntlCalendarTest collate/G7CollationTest format/IntlCalendarTest quasiGregorianTest(*cal,Locale("fr_FR"),data); delete cal; }
void TaiwanCalendar::initializeSystemDefaultCentury() { // initialize systemDefaultCentury and systemDefaultCenturyYear based // on the current time. They'll be set to 80 years before // the current time. UErrorCode status = U_ZERO_ERROR; TaiwanCalendar calendar(Locale("@calendar=roc"),status); if (U_SUCCESS(status)) { calendar.setTime(Calendar::getNow(), status); calendar.add(UCAL_YEAR, -80, status); UDate newStart = calendar.getTime(status); int32_t newYear = calendar.get(UCAL_YEAR, status); umtx_lock(NULL); if (fgSystemDefaultCenturyStart == fgSystemDefaultCentury) { fgSystemDefaultCenturyStartYear = newYear; fgSystemDefaultCenturyStart = newStart; } umtx_unlock(NULL); } // We have no recourse upon failure unless we want to propagate the failure // out. }
status_t BLanguage::GetName(BString& name, const BLanguage* displayLanguage) const { status_t status = B_OK; BString appLanguage; if (displayLanguage == NULL) { BMessage preferredLanguage; status = BLocaleRoster::Default()->GetPreferredLanguages( &preferredLanguage); if (status == B_OK) status = preferredLanguage.FindString("language", 0, &appLanguage); } else { appLanguage = displayLanguage->Code(); } if (status == B_OK) { UnicodeString string; fICULocale->getDisplayName(Locale(appLanguage), string); name.Truncate(0); BStringByteSink converter(&name); string.toUTF8(converter); } return status; }
void IntlCalendarTest::TestPersianFormat() { UErrorCode status = U_ZERO_ERROR; SimpleDateFormat *fmt = new SimpleDateFormat(UnicodeString("MMMM d, yyyy G"), Locale(" en_US@calendar=persian"), status); CHECK(status, "creating date format instance"); SimpleDateFormat *fmt2 = new SimpleDateFormat(UnicodeString("MMMM d, yyyy G"), Locale("en_US@calendar=gregorian"), status); CHECK(status, "creating gregorian date format instance"); UnicodeString gregorianDate("January 18, 2007 AD"); UDate aDate = fmt2->parse(gregorianDate, status); if(!fmt) { errln("Coudln't create en_US instance"); } else { UnicodeString str; fmt->format(aDate, str); logln(UnicodeString() + "as Persian Calendar: " + escape(str)); UnicodeString expected("Dey 28, 1385 AP"); if(str != expected) { errln("Expected " + escape(expected) + " but got " + escape(str)); } UDate otherDate = fmt->parse(expected, status); if(otherDate != aDate) { UnicodeString str3; fmt->format(otherDate, str3); errln("Parse incorrect of " + escape(expected) + " - wanted " + aDate + " but got " + otherDate + ", " + escape(str3)); } else { logln("Parsed OK: " + expected); } // Two digit year parsing problem #4732 fmt->applyPattern("yy-MM-dd"); str.remove(); fmt->format(aDate, str); expected.setTo("85-10-28"); if(str != expected) { errln("Expected " + escape(expected) + " but got " + escape(str)); } otherDate = fmt->parse(expected, status); if (otherDate != aDate) { errln("Parse incorrect of " + escape(expected) + " - wanted " + aDate + " but got " + otherDate); } else { logln("Parsed OK: " + expected); } delete fmt; } delete fmt2; CHECK(status, "Error occured testing Persian Calendar in English "); }
U_DRAFT UDateTimePatternGenerator * U_EXPORT2 udatpg_open(const char *locale, UErrorCode *pErrorCode) { if(locale==NULL) { return (UDateTimePatternGenerator *)DateTimePatternGenerator::createInstance(*pErrorCode); } else { return (UDateTimePatternGenerator *)DateTimePatternGenerator::createInstance(Locale(locale), *pErrorCode); } }
bool L10n::SaveLocale(const std::string& localeCode) const { if (localeCode == "long" && InDevelopmentCopy()) { g_ConfigDB.SetValueString(CFG_USER, "locale", "long"); return true; } return SaveLocale(Locale(Locale::createCanonical(localeCode.c_str()))); }
static void strToLocale( const UnicodeString &str, void *localePtr, UErrorCode &status) { if (U_FAILURE(status)) { return; } CharString localeStr; localeStr.appendInvariantChars(str, status); *static_cast<Locale *>(localePtr) = Locale(localeStr.data()); }
U_CAPI void U_EXPORT2 umsg_setLocale(UMessageFormat *fmt, const char* locale) { //check arguments if(fmt==NULL){ return; } ((MessageFormat*)fmt)->setLocale(Locale(locale)); }
const Locale RuleBasedCollator::getLocale(ULocDataLocaleType type, UErrorCode &status) const { const char *result = ucol_getLocaleByType(ucollator, type, &status); if(result == NULL) { Locale res(""); res.setToBogus(); return res; } else { return Locale(result); } }
CollationThaiTest::CollationThaiTest() { UErrorCode status = U_ZERO_ERROR; coll = Collator::createInstance(Locale("th", "TH", ""), status); if (coll && U_SUCCESS(status)) { //coll->setStrength(Collator::TERTIARY); } else { delete coll; coll = 0; } }
Boolean IndicationFormatter::_canLocalize( const ContentLanguages & contentLangs, Locale & locale) { PEG_METHOD_ENTER (TRC_IND_FORMATTER, "IndicationFormatter::_canLocalize"); if (!InitializeICU::initICUSuccessful()) { return (false); } Array<ContentLanguageElement> elements; contentLangs.getAllLanguageElements(elements); // If the Content-Languages has multiple language tag, do not localize if (elements.size() > 1) { // there is more then one language tags PEG_METHOD_EXIT(); return (false); } else if (elements.size() == 1) { // get the locale String language = elements[0].getLanguage(); String country = elements[0].getCountry(); String variant = elements[0].getVariant(); locale = Locale((const char *) language.getCString(), (const char *) country.getCString(), (const char *) variant.getCString()); // the locale is bogus state if (locale.isBogus()) { PEG_METHOD_EXIT(); return (false); } else { PEG_METHOD_EXIT(); return (true); } } else { locale = Locale::getDefault(); PEG_METHOD_EXIT(); return (true); } }
static void U_CALLCONV initializeSystemDefaultCentury() { UErrorCode status = U_ZERO_ERROR; CopticCalendar calendar(Locale("@calendar=coptic"), status); if (U_SUCCESS(status)) { calendar.setTime(Calendar::getNow(), status); calendar.add(UCAL_YEAR, -80, status); gSystemDefaultCenturyStart = calendar.getTime(status); gSystemDefaultCenturyStartYear = calendar.get(UCAL_YEAR, status); } // We have no recourse upon failure unless we want to propagate the failure // out. }
U_CAPI ULocaleDisplayNames * U_EXPORT2 uldn_openForContext(const char * locale, UDisplayContext *contexts, int32_t length, UErrorCode *pErrorCode) { if (U_FAILURE(*pErrorCode)) { return 0; } if (locale == NULL) { locale = uloc_getDefault(); } return (ULocaleDisplayNames *)LocaleDisplayNames::createInstance(Locale(locale), contexts, length); }