static ICULocaleService* getService(void) { UBool needInit; { Mutex mutex; needInit = (UBool)(gService == NULL); } if(needInit) { ICULocaleService *newservice = new ICUCollatorService(); if(newservice) { Mutex mutex; if(gService == NULL) { gService = newservice; newservice = NULL; } } if(newservice) { delete newservice; } else { ucln_i18n_registerCleanup(); } } return gService; }
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); }
double IslamicCalendar::moonAge(UDate time, UErrorCode &status) { double age = 0; umtx_lock(&astroLock); if(gIslamicCalendarAstro == NULL) { gIslamicCalendarAstro = new CalendarAstronomer(); if (gIslamicCalendarAstro == NULL) { status = U_MEMORY_ALLOCATION_ERROR; return age; } ucln_i18n_registerCleanup(UCLN_I18N_ISLAMIC_CALENDAR, calendar_islamic_cleanup); } gIslamicCalendarAstro->setTime(time); age = gIslamicCalendarAstro->getMoonAge(); umtx_unlock(&astroLock); // Convert to degrees and normalize... age = age * 180 / CalendarAstronomer::PI; if (age > 180) { age = age - 360; } return age; }
U_CDECL_END void SimpleDateFormatStaticSets::initSets(UErrorCode *status) { SimpleDateFormatStaticSets *p; UMTX_CHECK(NULL, gStaticSets, p); if (p == NULL) { p = new SimpleDateFormatStaticSets(status); if (p == NULL) { *status = U_MEMORY_ALLOCATION_ERROR; return; } if (U_FAILURE(*status)) { delete p; return; } umtx_lock(NULL); if (gStaticSets == NULL) { gStaticSets = p; p = NULL; } umtx_unlock(NULL); if (p != NULL) { delete p; } ucln_i18n_registerCleanup(UCLN_I18N_SMPDTFMT, smpdtfmt_cleanup); } }
U_CDECL_END U_NAMESPACE_BEGIN void U_CALLCONV GenderInfo_initCache(UErrorCode &status) { ucln_i18n_registerCleanup(UCLN_I18N_GENDERINFO, gender_cleanup); U_ASSERT(gGenderInfoCache == NULL); if (U_FAILURE(status)) { return; } gObjs = new GenderInfo[GENDER_STYLE_LENGTH]; if (gObjs == NULL) { status = U_MEMORY_ALLOCATION_ERROR; return; } for (int i = 0; i < GENDER_STYLE_LENGTH; i++) { gObjs[i]._style = i; } gGenderInfoCache = uhash_open(uhash_hashChars, uhash_compareChars, NULL, &status); if (U_FAILURE(status)) { delete [] gObjs; return; } uhash_setKeyDeleter(gGenderInfoCache, uprv_free); }
static void U_CALLCONV initAvailableMetaZoneIDs () { U_ASSERT(gMetaZoneIDs == NULL); U_ASSERT(gMetaZoneIDTable == NULL); ucln_i18n_registerCleanup(UCLN_I18N_ZONEMETA, zoneMeta_cleanup); UErrorCode status = U_ZERO_ERROR; gMetaZoneIDTable = uhash_open(uhash_hashUnicodeString, uhash_compareUnicodeString, NULL, &status); if (U_FAILURE(status) || gMetaZoneIDTable == NULL) { gMetaZoneIDTable = NULL; return; } uhash_setKeyDeleter(gMetaZoneIDTable, uprv_deleteUObject); // No valueDeleter, because the vector maintain the value objects gMetaZoneIDs = new UVector(NULL, uhash_compareUChars, status); if (U_FAILURE(status) || gMetaZoneIDs == NULL) { gMetaZoneIDs = NULL; uhash_close(gMetaZoneIDTable); gMetaZoneIDTable = NULL; return; } gMetaZoneIDs->setDeleter(uprv_free); UResourceBundle *rb = ures_openDirect(NULL, gMetaZones, &status); UResourceBundle *bundle = ures_getByKey(rb, gMapTimezonesTag, NULL, &status); UResourceBundle res; ures_initStackObject(&res); while (U_SUCCESS(status) && ures_hasNext(bundle)) { ures_getNextResource(bundle, &res, &status); if (U_FAILURE(status)) { break; } const char *mzID = ures_getKey(&res); int32_t len = uprv_strlen(mzID); UChar *uMzID = (UChar*)uprv_malloc(sizeof(UChar) * (len + 1)); if (uMzID == NULL) { status = U_MEMORY_ALLOCATION_ERROR; break; } u_charsToUChars(mzID, uMzID, len); uMzID[len] = 0; UnicodeString *usMzID = new UnicodeString(uMzID); if (uhash_get(gMetaZoneIDTable, usMzID) == NULL) { gMetaZoneIDs->addElement((void *)uMzID, status); uhash_put(gMetaZoneIDTable, (void *)usMzID, (void *)uMzID, &status); } else { uprv_free(uMzID); delete usMzID; } } ures_close(&res); ures_close(bundle); ures_close(rb); if (U_FAILURE(status)) { uhash_close(gMetaZoneIDTable); delete gMetaZoneIDs; gMetaZoneIDTable = NULL; gMetaZoneIDs = NULL; } }
/** * Finds the day # of the first day in the given Hebrew year. * To do this, we want to calculate the time of the Tishri 1 new moon * in that year. * <p> * The algorithm here is similar to ones described in a number of * references, including: * <ul> * <li>"Calendrical Calculations", by Nachum Dershowitz & Edward Reingold, * Cambridge University Press, 1997, pages 85-91. * * <li>Hebrew Calendar Science and Myths, * <a href="http://www.geocities.com/Athens/1584/"> * http://www.geocities.com/Athens/1584/</a> * * <li>The Calendar FAQ, * <a href="http://www.faqs.org/faqs/calendars/faq/"> * http://www.faqs.org/faqs/calendars/faq/</a> * </ul> */ int32_t HebrewCalendar::startOfYear(int32_t year, UErrorCode &status) { ucln_i18n_registerCleanup(UCLN_I18N_HEBREW_CALENDAR, calendar_hebrew_cleanup); int32_t day = CalendarCache::get(&gCache, year, status); if (day == 0) { int32_t months = (235 * year - 234) / 19; // # of months before year int64_t frac = (int64_t)months * MONTH_FRACT + BAHARAD; // Fractional part of day # day = months * 29 + (int32_t)(frac / DAY_PARTS); // Whole # part of calculation frac = frac % DAY_PARTS; // Time of day int32_t wd = (day % 7); // Day of week (0 == Monday) if (wd == 2 || wd == 4 || wd == 6) { // If the 1st is on Sun, Wed, or Fri, postpone to the next day day += 1; wd = (day % 7); } if (wd == 1 && frac > 15*HOUR_PARTS+204 && !isLeapYear(year) ) { // If the new moon falls after 3:11:20am (15h204p from the previous noon) // on a Tuesday and it is not a leap year, postpone by 2 days. // This prevents 356-day years. day += 2; } else if (wd == 0 && frac > 21*HOUR_PARTS+589 && isLeapYear(year-1) ) { // If the new moon falls after 9:32:43 1/3am (21h589p from yesterday noon) // on a Monday and *last* year was a leap year, postpone by 1 day. // Prevents 382-day years. day += 1; } CalendarCache::put(&gCache, year, day, status); } return day; }
U_CDECL_END void U_CALLCONV CollationRoot::load(UErrorCode &errorCode) { if(U_FAILURE(errorCode)) { return; } LocalPointer<CollationTailoring> t(new CollationTailoring(NULL)); if(t.isNull() || t->isBogus()) { errorCode = U_MEMORY_ALLOCATION_ERROR; return; } t->memory = udata_openChoice(U_ICUDATA_NAME U_TREE_SEPARATOR_STRING "coll", "icu", "ucadata", CollationDataReader::isAcceptable, t->version, &errorCode); if(U_FAILURE(errorCode)) { return; } const uint8_t *inBytes = static_cast<const uint8_t *>(udata_getMemory(t->memory)); CollationDataReader::read(NULL, inBytes, udata_getLength(t->memory), *t, errorCode); if(U_FAILURE(errorCode)) { return; } ucln_i18n_registerCleanup(UCLN_I18N_COLLATION_ROOT, uprv_collation_root_cleanup); CollationCacheEntry *entry = new CollationCacheEntry(Locale::getRoot(), t.getAlias()); if(entry != NULL) { t.orphan(); // The rootSingleton took ownership of the tailoring. entry->addRef(); rootSingleton = entry; } }
static ICULocaleService* getService(void) { UBool needInit; { Mutex mutex; needInit = (UBool)(gService == NULL); } if (needInit) { ICULocaleService * newservice = new ICUNumberFormatService(); if (newservice) { Mutex mutex; if (gService == NULL) { gService = newservice; newservice = NULL; } } if (newservice) { delete newservice; } else { // we won the contention, this thread can register cleanup. ucln_i18n_registerCleanup(); } } return gService; }
/** * Return the major solar term on or after December 15 of the given * Gregorian year, that is, the winter solstice of the given year. * Computations are relative to Asia/Shanghai time zone. * @param gyear a Gregorian year * @return days after January 1, 1970 0:00 Asia/Shanghai of the * winter solstice of the given year */ int32_t ChineseCalendar::winterSolstice(int32_t gyear) const { UErrorCode status = U_ZERO_ERROR; int32_t cacheValue = CalendarCache::get(&gChineseCalendarWinterSolsticeCache, gyear, status); if (cacheValue == 0) { // In books December 15 is used, but it fails for some years // using our algorithms, e.g.: 1298 1391 1492 1553 1560. That // is, winterSolstice(1298) starts search at Dec 14 08:00:00 // PST 1298 with a final result of Dec 14 10:31:59 PST 1299. double ms = daysToMillis(Grego::fieldsToDay(gyear, UCAL_DECEMBER, 1)); umtx_lock(&astroLock); if(gChineseCalendarAstro == NULL) { gChineseCalendarAstro = new CalendarAstronomer(); ucln_i18n_registerCleanup(UCLN_I18N_CHINESE_CALENDAR, calendar_chinese_cleanup); } gChineseCalendarAstro->setTime(ms); UDate solarLong = gChineseCalendarAstro->getSunTime(CalendarAstronomer::WINTER_SOLSTICE(), TRUE); umtx_unlock(&astroLock); // Winter solstice is 270 degrees solar longitude aka Dongzhi cacheValue = (int32_t)millisToDays(solarLong); CalendarCache::put(&gChineseCalendarWinterSolsticeCache, gyear, cacheValue, status); } if(U_FAILURE(status)) { cacheValue = 0; } return cacheValue; }
/** * Initialize static memory. */ void TransliteratorIDParser::init(UErrorCode & status) { if (SPECIAL_INVERSES != NULL) { return; } Hashtable * special_inverses = new Hashtable(TRUE, status); // Null pointer check if (special_inverses == NULL) { status = U_MEMORY_ALLOCATION_ERROR; return; } special_inverses->setValueDeleter(uhash_deleteUnicodeString); umtx_lock(&LOCK); if (SPECIAL_INVERSES == NULL) { SPECIAL_INVERSES = special_inverses; special_inverses = NULL; } umtx_unlock(&LOCK); delete special_inverses; /*null instance*/ ucln_i18n_registerCleanup(UCLN_I18N_TRANSLITERATOR, utrans_transliterator_cleanup); }
TitlecaseTransliterator::TitlecaseTransliterator(const Locale& theLoc) : Transliterator(_ID, 0), loc(theLoc), buffer(0) { buffer = (UChar *)uprv_malloc(u_getMaxCaseExpansion()*sizeof(buffer[0])); // Need to look back 2 characters in the case of "can't" setMaximumContextLength(2); umtx_lock(NULL); UBool f = (SKIP == NULL); umtx_unlock(NULL); if (f) { UErrorCode ec = U_ZERO_ERROR; UnicodeSet* skip = new UnicodeSet(UNICODE_STRING_SIMPLE("[\\u00AD \\u2019 \\' [:Mn:] [:Me:] [:Cf:] [:Lm:] [:Sk:]]"), ec); UnicodeSet* cased = new UnicodeSet(UNICODE_STRING_SIMPLE("[[:Lu:] [:Ll:] [:Lt:]]"), ec); if (skip != NULL && cased != NULL && U_SUCCESS(ec)) { umtx_lock(NULL); if (SKIP == NULL) { SKIP = skip; CASED = cased; skip = cased = NULL; } umtx_unlock(NULL); } delete skip; delete cased; ucln_i18n_registerCleanup(); } }
const char* TimeZone::getTZDataVersion(UErrorCode& status) { /* This is here to prevent race conditions. */ UBool needsInit; UMTX_CHECK(&LOCK, !TZDataVersionInitialized, needsInit); if (needsInit) { int32_t len = 0; UResourceBundle *bundle = ures_openDirect(NULL, "zoneinfo", &status); const UChar *tzver = ures_getStringByKey(bundle, "TZVersion", &len, &status); if (U_SUCCESS(status)) { if (len >= (int32_t)sizeof(TZDATA_VERSION)) { // Ensure that there is always space for a trailing nul in TZDATA_VERSION len = sizeof(TZDATA_VERSION) - 1; } umtx_lock(&LOCK); if (!TZDataVersionInitialized) { u_UCharsToChars(tzver, TZDATA_VERSION, len); TZDataVersionInitialized = TRUE; } umtx_unlock(&LOCK); ucln_i18n_registerCleanup(UCLN_I18N_TIMEZONE, timeZone_cleanup); } ures_close(bundle); } if (U_FAILURE(status)) { return NULL; } return (const char*)TZDATA_VERSION; }
static void U_CALLCONV smpdtfmt_initSets(UErrorCode &status) { ucln_i18n_registerCleanup(UCLN_I18N_SMPDTFMT, smpdtfmt_cleanup); U_ASSERT(gStaticSets == NULL); gStaticSets = new SimpleDateFormatStaticSets(status); if (gStaticSets == NULL) { status = U_MEMORY_ALLOCATION_ERROR; return; } }
// C Locale initialization func static void U_CALLCONV initCLocale(void) { ucln_i18n_registerCleanup(UCLN_I18N_DIGITLIST, digitList_cleanup); #if U_USE_STRTOD_L # if U_PLATFORM_USES_ONLY_WIN32_API gCLocale = _create_locale(LC_ALL, "C"); # else gCLocale = newlocale(LC_ALL_MASK, "C", (locale_t)0); # endif #endif }
static void U_CALLCONV initCanonicalIDCache(UErrorCode &status) { gCanonicalIDCache = uhash_open(uhash_hashUChars, uhash_compareUChars, NULL, &status); if (gCanonicalIDCache == NULL) { status = U_MEMORY_ALLOCATION_ERROR; } if (U_FAILURE(status)) { gCanonicalIDCache = NULL; } // No key/value deleters - keys/values are from a resource bundle ucln_i18n_registerCleanup(UCLN_I18N_ZONEMETA, zoneMeta_cleanup); }
/** * Initialize static memory. Called through umtx_initOnce only. */ void U_CALLCONV TransliteratorIDParser::init(UErrorCode &status) { U_ASSERT(SPECIAL_INVERSES == NULL); ucln_i18n_registerCleanup(UCLN_I18N_TRANSLITERATOR, utrans_transliterator_cleanup); SPECIAL_INVERSES = new Hashtable(TRUE, status); if (SPECIAL_INVERSES == NULL) { status = U_MEMORY_ALLOCATION_ERROR; return; } SPECIAL_INVERSES->setValueDeleter(uprv_deleteUObject); }
static void U_CALLCONV olsonToMetaInit(UErrorCode &status) { U_ASSERT(gOlsonToMeta == NULL); ucln_i18n_registerCleanup(UCLN_I18N_ZONEMETA, zoneMeta_cleanup); gOlsonToMeta = uhash_open(uhash_hashUChars, uhash_compareUChars, NULL, &status); if (U_FAILURE(status)) { gOlsonToMeta = NULL; } else { uhash_setKeyDeleter(gOlsonToMeta, deleteUCharString); uhash_setValueDeleter(gOlsonToMeta, deleteUVector); } }
static void U_CALLCONV initStaticSets(UErrorCode &status) { U_ASSERT(RegexStaticSets::gStaticSets == NULL); ucln_i18n_registerCleanup(UCLN_I18N_REGEX, regex_cleanup); RegexStaticSets::gStaticSets = new RegexStaticSets(&status); if (U_FAILURE(status)) { delete RegexStaticSets::gStaticSets; RegexStaticSets::gStaticSets = NULL; } if (RegexStaticSets::gStaticSets == NULL && U_SUCCESS(status)) { status = U_MEMORY_ALLOCATION_ERROR; } }
static UBool loadOlsonIDs() { if (OLSON_IDS != 0) { return TRUE; } UErrorCode ec = U_ZERO_ERROR; UnicodeString* ids = 0; int32_t count = 0; UResourceBundle *top = ures_openDirect(0, kZONEINFO, &ec); UResourceBundle *nres = ures_getByKey(top, kNAMES, NULL, &ec); // dereference Names section if (U_SUCCESS(ec)) { getOlsonMeta(top); int32_t start = 0; count = ures_getSize(nres); ids = new UnicodeString[(count > 0) ? count : 1]; // Null pointer check if (ids != NULL) { for (int32_t i=0; i<count; ++i) { int32_t idLen = 0; const UChar* id = ures_getStringByIndex(nres, i, &idLen, &ec); ids[i].fastCopyFrom(UnicodeString(TRUE, id, idLen)); if (U_FAILURE(ec)) { break; } } } else { ec = U_MEMORY_ALLOCATION_ERROR; } } ures_close(nres); ures_close(top); if (U_FAILURE(ec)) { delete[] ids; return FALSE; } // Keep mutexed operations as short as possible by doing all // computations first, then doing pointer copies within the mutex. umtx_lock(&LOCK); if (OLSON_IDS == 0) { OLSON_IDS = ids; ids = 0; ucln_i18n_registerCleanup(UCLN_I18N_TIMEZONE, timeZone_cleanup); } umtx_unlock(&LOCK); // If another thread initialized the statics first, then delete // our unused data. delete[] ids; return TRUE; }
static void U_CALLCONV initSets(UErrorCode &status) { U_ASSERT(gStaticSets == NULL); ucln_i18n_registerCleanup(UCLN_I18N_DECFMT, decimfmt_cleanup); gStaticSets = new DecimalFormatStaticSets(status); if (U_FAILURE(status)) { delete gStaticSets; gStaticSets = NULL; return; } if (gStaticSets == NULL) { status = U_MEMORY_ALLOCATION_ERROR; } }
/** * Return the closest new moon to the given date, searching either * forward or backward in time. * @param days days after January 1, 1970 0:00 Asia/Shanghai * @param after if true, search for a new moon on or after the given * date; otherwise, search for a new moon before it * @return days after January 1, 1970 0:00 Asia/Shanghai of the nearest * new moon after or before <code>days</code> */ int32_t ChineseCalendar::newMoonNear(double days, UBool after) const { umtx_lock(&astroLock); if(gChineseCalendarAstro == NULL) { gChineseCalendarAstro = new CalendarAstronomer(); ucln_i18n_registerCleanup(UCLN_I18N_CHINESE_CALENDAR, calendar_chinese_cleanup); } gChineseCalendarAstro->setTime(daysToMillis(days)); UDate newMoon = gChineseCalendarAstro->getMoonTime(CalendarAstronomer::NEW_MOON(), after); umtx_unlock(&astroLock); return (int32_t) millisToDays(newMoon); }
static ICULocaleService* getService(void) { UBool needInit; { Mutex mutex; needInit = (UBool)(gService == NULL); } if (needInit) { UErrorCode status = U_ZERO_ERROR; #ifdef U_DEBUG_CALSVC fprintf(stderr, "Spinning up Calendar Service\n"); #endif ICULocaleService * newservice = new CalendarService(); #ifdef U_DEBUG_CALSVC fprintf(stderr, "Registering classes..\n"); #endif // Register all basic instances. newservice->registerFactory(new BasicCalendarFactory("japanese"),status); newservice->registerFactory(new BasicCalendarFactory("buddhist"),status); newservice->registerFactory(new BasicCalendarFactory("gregorian"),status); #ifdef U_DEBUG_CALSVC fprintf(stderr, "Done..\n"); #endif if(U_FAILURE(status)) { #ifdef U_DEBUG_CALSVC fprintf(stderr, "err (%s) registering classes, deleting service.....\n", u_errorName(status)); #endif delete newservice; newservice = NULL; } if (newservice) { Mutex mutex; if (gService == NULL) { gService = newservice; newservice = NULL; } } if (newservice) { delete newservice; } else { // we won the contention - we can register the cleanup. ucln_i18n_registerCleanup(); } } return gService; }
static UBool isAvailableLocaleListInitialized(UErrorCode &status) { // for now, there is a hardcoded list, so just walk through that list and set it up. UBool needInit; UMTX_CHECK(NULL, availableLocaleList == NULL, needInit); if (needInit) { UResourceBundle *index = NULL; UResourceBundle installed; Locale * temp; int32_t i = 0; int32_t localeCount; ures_initStackObject(&installed); index = ures_openDirect(U_ICUDATA_COLL, "res_index", &status); ures_getByKey(index, "InstalledLocales", &installed, &status); if(U_SUCCESS(status)) { localeCount = ures_getSize(&installed); temp = new Locale[localeCount]; if (temp != NULL) { ures_resetIterator(&installed); while(ures_hasNext(&installed)) { const char *tempKey = NULL; ures_getNextString(&installed, NULL, &tempKey, &status); temp[i++] = Locale(tempKey); } umtx_lock(NULL); if (availableLocaleList == NULL) { availableLocaleListCount = localeCount; availableLocaleList = temp; temp = NULL; ucln_i18n_registerCleanup(UCLN_I18N_COLLATOR, collator_cleanup); } umtx_unlock(NULL); needInit = FALSE; if (temp) { delete []temp; } } ures_close(&installed); } ures_close(index); } return !needInit; }
static void U_CALLCONV nscacheInit() { U_ASSERT(NumberingSystem_cache == NULL); ucln_i18n_registerCleanup(UCLN_I18N_NUMFMT, numfmt_cleanup); UErrorCode status = U_ZERO_ERROR; NumberingSystem_cache = uhash_open(uhash_hashLong, uhash_compareLong, NULL, &status); if (U_FAILURE(status)) { // Number Format code will run with no cache if creation fails. NumberingSystem_cache = NULL; return; } uhash_setValueDeleter(NumberingSystem_cache, deleteNumberingSystem); }
void U_EXPORT2 TimeZone::adoptDefault(TimeZone* zone) { if (zone != NULL) { TimeZone* old = NULL; umtx_lock(&LOCK); old = DEFAULT_ZONE; DEFAULT_ZONE = zone; umtx_unlock(&LOCK); delete old; ucln_i18n_registerCleanup(UCLN_I18N_TIMEZONE, timeZone_cleanup); } }
U_CDECL_END IdentifierInfo::IdentifierInfo(UErrorCode &status): fIdentifier(NULL), fRequiredScripts(NULL), fScriptSetSet(NULL), fCommonAmongAlternates(NULL), fNumerics(NULL), fIdentifierProfile(NULL) { if (U_FAILURE(status)) { return; } { Mutex lock(&gInitMutex); if (!gStaticsAreInitialized) { ASCII = new UnicodeSet(0, 0x7f); JAPANESE = new ScriptSet(); CHINESE = new ScriptSet(); KOREAN = new ScriptSet(); CONFUSABLE_WITH_LATIN = new ScriptSet(); if (ASCII == NULL || JAPANESE == NULL || CHINESE == NULL || KOREAN == NULL || CONFUSABLE_WITH_LATIN == NULL) { status = U_MEMORY_ALLOCATION_ERROR; return; } ASCII->freeze(); JAPANESE->set(USCRIPT_LATIN, status).set(USCRIPT_HAN, status).set(USCRIPT_HIRAGANA, status) .set(USCRIPT_KATAKANA, status); CHINESE->set(USCRIPT_LATIN, status).set(USCRIPT_HAN, status).set(USCRIPT_BOPOMOFO, status); KOREAN->set(USCRIPT_LATIN, status).set(USCRIPT_HAN, status).set(USCRIPT_HANGUL, status); CONFUSABLE_WITH_LATIN->set(USCRIPT_CYRILLIC, status).set(USCRIPT_GREEK, status) .set(USCRIPT_CHEROKEE, status); ucln_i18n_registerCleanup(UCLN_I18N_IDENTIFIER_INFO, IdentifierInfo_cleanup); gStaticsAreInitialized = TRUE; } } fIdentifier = new UnicodeString(); fRequiredScripts = new ScriptSet(); fScriptSetSet = uhash_open(uhash_hashScriptSet, uhash_compareScriptSet, NULL, &status); uhash_setKeyDeleter(fScriptSetSet, uhash_deleteScriptSet); fCommonAmongAlternates = new ScriptSet(); fNumerics = new UnicodeSet(); fIdentifierProfile = new UnicodeSet(0, 0x10FFFF); if (U_SUCCESS(status) && (fIdentifier == NULL || fRequiredScripts == NULL || fScriptSetSet == NULL || fCommonAmongAlternates == NULL || fNumerics == NULL || fIdentifierProfile == NULL)) { status = U_MEMORY_ALLOCATION_ERROR; } }
U_CDECL_END /* do not close UCA returned by ucol_initUCA! */ UCollator * ucol_initUCA(UErrorCode *status) { if(U_FAILURE(*status)) { return NULL; } UBool needsInit; UMTX_CHECK(NULL, (_staticUCA == NULL), needsInit); if(needsInit) { UDataMemory *result = udata_openChoice(U_ICUDATA_COLL, UCA_DATA_TYPE, UCA_DATA_NAME, isAcceptableUCA, NULL, status); if(U_SUCCESS(*status)){ UCollator *newUCA = ucol_initCollator((const UCATableHeader *)udata_getMemory(result), NULL, NULL, status); if(U_SUCCESS(*status)){ // Initalize variables for implicit generation uprv_uca_initImplicitConstants(status); umtx_lock(NULL); if(_staticUCA == NULL) { UCA_DATA_MEM = result; _staticUCA = newUCA; newUCA = NULL; result = NULL; } umtx_unlock(NULL); ucln_i18n_registerCleanup(UCLN_I18N_UCOL_RES, ucol_res_cleanup); if(newUCA != NULL) { ucol_close(newUCA); udata_close(result); } }else{ ucol_close(newUCA); udata_close(result); } } else { udata_close(result); } } return _staticUCA; }
/** * Return the major solar term on or before a given date. This * will be an integer from 1..12, with 1 corresponding to 330 degrees, * 2 to 0 degrees, 3 to 30 degrees,..., and 12 to 300 degrees. * @param days days after January 1, 1970 0:00 Asia/Shanghai */ int32_t ChineseCalendar::majorSolarTerm(int32_t days) const { umtx_lock(&astroLock); if(gChineseCalendarAstro == NULL) { gChineseCalendarAstro = new CalendarAstronomer(); ucln_i18n_registerCleanup(UCLN_I18N_CHINESE_CALENDAR, calendar_chinese_cleanup); } gChineseCalendarAstro->setTime(daysToMillis(days)); UDate solarLongitude = gChineseCalendarAstro->getSunLongitude(); umtx_unlock(&astroLock); // Compute (floor(solarLongitude / (pi/6)) + 2) % 12 int32_t term = ( ((int32_t)(6 * solarLongitude / CalendarAstronomer::PI)) + 2 ) % 12; if (term < 1) { term += 12; } return term; }
static void U_CALLCONV uspoof_loadDefaultData(UErrorCode& status) { UDataMemory *udm = udata_openChoice(nullptr, "cfu", "confusables", spoofDataIsAcceptable, nullptr, // context, would receive dataVersion if supplied. &status); if (U_FAILURE(status)) { return; } gDefaultSpoofData = new SpoofData(udm, status); if (U_FAILURE(status)) { delete gDefaultSpoofData; gDefaultSpoofData = nullptr; return; } if (gDefaultSpoofData == nullptr) { status = U_MEMORY_ALLOCATION_ERROR; return; } ucln_i18n_registerCleanup(UCLN_I18N_SPOOFDATA, uspoof_cleanupDefaultData); }