static UResourceBundle* openOlsonResource(const UnicodeString& id, UResourceBundle& res, UErrorCode& ec) { #if U_DEBUG_TZ char buf[128]; id.extract(0, sizeof(buf)-1, buf, sizeof(buf), ""); #endif UResourceBundle *top = ures_openDirect(0, kZONEINFO, &ec); U_DEBUG_TZ_MSG(("pre: res sz=%d\n", ures_getSize(&res))); /* &res = */ getZoneByName(top, id, &res, ec); // Dereference if this is an alias. Docs say result should be 1 // but it is 0 in 2.8 (?). U_DEBUG_TZ_MSG(("Loading zone '%s' (%s, size %d) - %s\n", buf, ures_getKey((UResourceBundle*)&res), ures_getSize(&res), u_errorName(ec))); if (ures_getSize(&res) <= 1 && getOlsonMeta(top)) { int32_t deref = ures_getInt(&res, &ec) + 0; U_DEBUG_TZ_MSG(("getInt: %s - type is %d\n", u_errorName(ec), ures_getType(&res))); UResourceBundle *ares = ures_getByKey(top, kZONES, NULL, &ec); // dereference Zones section ures_getByIndex(ares, deref, &res, &ec); ures_close(ares); U_DEBUG_TZ_MSG(("alias to #%d (%s) - %s\n", deref, "??", u_errorName(ec))); } else { U_DEBUG_TZ_MSG(("not an alias - size %d\n", ures_getSize(&res))); } U_DEBUG_TZ_MSG(("%s - final status is %s\n", buf, u_errorName(ec))); return top; }
RBTestData::RBTestData(UResourceBundle *data, UResourceBundle *headers, UErrorCode& status) : TestData(ures_getKey(data)), fData(data), fHeaders(headers), fSettings(NULL), fCases(NULL) { UErrorCode intStatus = U_ZERO_ERROR; UResourceBundle *currHeaders = ures_getByKey(data, "Headers", NULL, &intStatus); if(intStatus == U_ZERO_ERROR) { ures_close(fHeaders); fHeaders = currHeaders; } else { intStatus = U_ZERO_ERROR; } fSettings = ures_getByKey(data, "Settings", NULL, &intStatus); fSettingsSize = ures_getSize(fSettings); UResourceBundle *info = ures_getByKey(data, "Info", NULL, &intStatus); if(U_SUCCESS(intStatus)) { fInfo = new RBDataMap(info, status); } else { intStatus = U_ZERO_ERROR; } fCases = ures_getByKey(data, "Cases", NULL, &status); fCasesSize = ures_getSize(fCases); ures_close(info); }
static UResourceBundle* getZoneByName(const UResourceBundle* top, const UnicodeString& id, UResourceBundle *oldbundle, UErrorCode& status) { // load the Rules object UResourceBundle *tmp = ures_getByKey(top, kNAMES, NULL, &status); // search for the string int32_t idx = findInStringArray(tmp, id, status); if((idx == -1) && U_SUCCESS(status)) { // not found status = U_MISSING_RESOURCE_ERROR; //ures_close(oldbundle); //oldbundle = NULL; } else { U_DEBUG_TZ_MSG(("gzbn: oldbundle= size %d, type %d, %s\n", ures_getSize(tmp), ures_getType(tmp), u_errorName(status))); tmp = ures_getByKey(top, kZONES, tmp, &status); // get Zones object from top U_DEBUG_TZ_MSG(("gzbn: loaded ZONES, size %d, type %d, path %s %s\n", ures_getSize(tmp), ures_getType(tmp), ures_getPath(tmp), u_errorName(status))); oldbundle = ures_getByIndex(tmp, idx, oldbundle, &status); // get nth Zone object U_DEBUG_TZ_MSG(("gzbn: loaded z#%d, size %d, type %d, path %s, %s\n", idx, ures_getSize(oldbundle), ures_getType(oldbundle), ures_getPath(oldbundle), u_errorName(status))); } ures_close(tmp); if(U_FAILURE(status)) { //ures_close(oldbundle); return NULL; } else { return oldbundle; } }
TZEnumeration(const char* country) : map(NULL), len(0), pos(0) { if (!getOlsonMeta()) { return; } UErrorCode ec = U_ZERO_ERROR; UResourceBundle *res = ures_openDirect(0, kZONEINFO, &ec); ures_getByKey(res, kREGIONS, res, &ec); if (U_SUCCESS(ec) && ures_getType(res) == URES_ARRAY) { UChar uCountry[] = {0, 0, 0, 0}; if (country) { u_charsToUChars(country, uCountry, 2); } else { u_strcpy(uCountry, WORLD); } // count matches int32_t count = 0; int32_t i; const UChar *region; for (i = 0; i < ures_getSize(res); i++) { region = ures_getStringByIndex(res, i, NULL, &ec); if (U_FAILURE(ec)) { break; } if (u_strcmp(uCountry, region) == 0) { count++; } } if (count > 0) { map = (int32_t*)uprv_malloc(sizeof(int32_t) * count); if (map != NULL) { int32_t idx = 0; for (i = 0; i < ures_getSize(res); i++) { region = ures_getStringByIndex(res, i, NULL, &ec); if (U_FAILURE(ec)) { break; } if (u_strcmp(uCountry, region) == 0) { map[idx++] = i; } } if (U_SUCCESS(ec)) { len = count; } else { uprv_free(map); map = NULL; } } else { U_DEBUG_TZ_MSG(("Failed to load tz for region %s: %s\n", country, u_errorName(ec))); } } } ures_close(res); }
static jobjectArray getNames(JNIEnv* env, UResourceBundle* namesBundle, bool months, NameType type, NameWidth width) { const char* typeKey = (type == REGULAR) ? "format" : "stand-alone"; const char* widthKey = (width == LONG) ? "wide" : "abbreviated"; UErrorCode status = U_ZERO_ERROR; ScopedResourceBundle formatBundle(ures_getByKey(namesBundle, typeKey, NULL, &status)); ScopedResourceBundle valuesBundle(ures_getByKey(formatBundle.get(), widthKey, NULL, &status)); if (U_FAILURE(status)) { return NULL; } // The months array has a trailing empty string. The days array has a leading empty string. int count = ures_getSize(valuesBundle.get()); jobjectArray result = env->NewObjectArray(count + 1, JniConstants::stringClass, NULL); env->SetObjectArrayElement(result, months ? count : 0, env->NewStringUTF("")); int arrayOffset = months ? 0 : 1; for (int i = 0; i < count; ++i) { int nameLength; const jchar* name = ures_getStringByIndex(valuesBundle.get(), i, &nameLength, &status); if (U_FAILURE(status)) { return NULL; } ScopedLocalRef<jstring> nameString(env, env->NewString(name, nameLength)); env->SetObjectArrayElement(result, arrayOffset++, nameString.get()); } return result; }
/* {{{ resourcebundle_get_iterator */ zend_object_iterator *resourcebundle_get_iterator( zend_class_entry *ce, zval *object, int byref ) { ResourceBundle_object *rb = Z_INTL_RESOURCEBUNDLE_P(object ); ResourceBundle_iterator *iterator = emalloc( sizeof( ResourceBundle_iterator ) ); if (byref) { php_error( E_ERROR, "ResourceBundle does not support writable iterators" ); } zend_iterator_init(&iterator->intern); ZVAL_COPY(&iterator->intern.data, object); iterator->intern.funcs = &resourcebundle_iterator_funcs; iterator->subject = rb; /* The iterated rb can only be either URES_TABLE or URES_ARRAY * All other types are returned as php primitives! */ iterator->is_table = (ures_getType( rb->me ) == URES_TABLE); iterator->length = ures_getSize( rb->me ); ZVAL_UNDEF(&iterator->current); iterator->currentkey = NULL; iterator->i = 0; return (zend_object_iterator *) iterator; }
static jobjectArray getEras(JNIEnv* env, UResourceBundle* gregorian) { UErrorCode status = U_ZERO_ERROR; ScopedResourceBundle gregorianElems(ures_getByKey(gregorian, "eras", NULL, &status)); if (U_FAILURE(status)) { return NULL; } ScopedResourceBundle eraElems(ures_getByKey(gregorianElems.get(), "abbreviated", NULL, &status)); if (U_FAILURE(status)) { return NULL; } int eraCount = ures_getSize(eraElems.get()); jobjectArray eras = env->NewObjectArray(eraCount, string_class, NULL); ures_resetIterator(eraElems.get()); for (int i = 0; i < eraCount; ++i) { int eraLength; const jchar* era = ures_getStringByIndex(eraElems.get(), i, &eraLength, &status); if (U_FAILURE(status)) { return NULL; } jstring eraU = env->NewString(era, eraLength); env->SetObjectArrayElement(eras, i, eraU); env->DeleteLocalRef(eraU); } return eras; }
static jobjectArray getWeekdayNames(JNIEnv* env, UResourceBundle* gregorian, bool longNames) { UErrorCode status = U_ZERO_ERROR; ScopedResourceBundle gregorianElems(ures_getByKey(gregorian, "dayNames", NULL, &status)); if (U_FAILURE(status)) { return NULL; } ScopedResourceBundle dayNameElems(ures_getByKey(gregorianElems.get(), "format", NULL, &status)); if (U_FAILURE(status)) { return NULL; } ScopedResourceBundle dayNameElemsFormat(ures_getByKey(dayNameElems.get(), longNames ? "wide" : "abbreviated", NULL, &status)); if (U_FAILURE(status)) { return NULL; } ures_resetIterator(dayNameElemsFormat.get()); int dayCount = ures_getSize(dayNameElemsFormat.get()); jobjectArray weekdays = env->NewObjectArray(dayCount + 1, string_class, NULL); // first entry in the weekdays array is an empty string env->SetObjectArrayElement(weekdays, 0, env->NewStringUTF("")); for(int i = 0; i < dayCount; i++) { int dayNameLength; const jchar* day = ures_getStringByIndex(dayNameElemsFormat.get(), i, &dayNameLength, &status); if(U_FAILURE(status)) { return NULL; } jstring dayU = env->NewString(day, dayNameLength); env->SetObjectArrayElement(weekdays, i + 1, dayU); env->DeleteLocalRef(dayU); } return weekdays; }
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); }
int32_t U_EXPORT2 TimeZone::countEquivalentIDs(const UnicodeString& id) { int32_t result = 0; UErrorCode ec = U_ZERO_ERROR; UResourceBundle res; ures_initStackObject(&res); U_DEBUG_TZ_MSG(("countEquivalentIDs..\n")); UResourceBundle *top = openOlsonResource(id, res, ec); if (U_SUCCESS(ec)) { int32_t size = ures_getSize(&res); U_DEBUG_TZ_MSG(("cEI: success (size %d, key %s)..\n", size, ures_getKey(&res))); if (size == 4 || size == 6) { UResourceBundle r; ures_initStackObject(&r); ures_getByIndex(&res, size-1, &r, &ec); //result = ures_getSize(&r); // doesn't work ures_getIntVector(&r, &result, &ec); U_DEBUG_TZ_MSG(("ceI: result %d, err %s\n", result, u_errorName(ec))); ures_close(&r); } } else { U_DEBUG_TZ_MSG(("cEI: fail, %s\n", u_errorName(ec))); } ures_close(&res); ures_close(top); return result; }
void RBDataMap::init(UResourceBundle *data, UErrorCode &status) { int32_t i = 0; fData->removeAll(); UResourceBundle *t = NULL; for(i = 0; i < ures_getSize(data); i++) { t = ures_getByIndex(data, i, t, &status); fData->put(UnicodeString(ures_getKey(t), -1, US_INV), new ResourceBundle(t, status), status); } ures_close(t); }
void RBDataMap::init(UResourceBundle *headers, UResourceBundle *data, UErrorCode &status) { int32_t i = 0; fData->removeAll(); UResourceBundle *t = NULL; const UChar *key = NULL; int32_t keyLen = 0; if(ures_getSize(headers) == ures_getSize(data)) { for(i = 0; i < ures_getSize(data); i++) { t = ures_getByIndex(data, i, t, &status); key = ures_getStringByIndex(headers, i, &keyLen, &status); fData->put(UnicodeString(key, keyLen), new ResourceBundle(t, status), status); } } else { // error status = U_INVALID_FORMAT_ERROR; } ures_close(t); }
static jobjectArray getShortMonthNames(JNIEnv *env, UResourceBundle *gregorian) { UErrorCode status = U_ZERO_ERROR; const jchar* shortMonth; jstring shortMonthU; UResourceBundle *gregorianElems = ures_getByKey(gregorian, "monthNames", NULL, &status); if(U_FAILURE(status)) { return NULL; } UResourceBundle *monthNameElems = ures_getByKey(gregorianElems, "format", NULL, &status); if(U_FAILURE(status)) { ures_close(gregorianElems); return NULL; } UResourceBundle *monthNameElemsFormat = ures_getByKey(monthNameElems, "abbreviated", NULL, &status); if(U_FAILURE(status)) { ures_close(monthNameElems); ures_close(gregorianElems); return NULL; } int shortMonthNameLength; ures_resetIterator(monthNameElemsFormat); int shortMonthCount = ures_getSize(monthNameElemsFormat); // the array length is +1 because the harmony locales had an empty string at the end of their month name array jobjectArray shortMonths = env->NewObjectArray(shortMonthCount + 1, string_class, NULL); for(int i = 0; i < shortMonthCount; i++) { shortMonth = ures_getStringByIndex(monthNameElemsFormat, i, &shortMonthNameLength, &status); if(U_FAILURE(status)) { ures_close(monthNameElemsFormat); ures_close(monthNameElems); ures_close(gregorianElems); return NULL; } shortMonthU = env->NewString(shortMonth, shortMonthNameLength); env->SetObjectArrayElement(shortMonths, i, shortMonthU); env->DeleteLocalRef(shortMonthU); } shortMonthU = env->NewStringUTF(""); env->SetObjectArrayElement(shortMonths, shortMonthCount, shortMonthU); env->DeleteLocalRef(shortMonthU); ures_close(monthNameElemsFormat); ures_close(monthNameElems); ures_close(gregorianElems); return shortMonths; }
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 jobjectArray getMonthNames(JNIEnv *env, UResourceBundle *gregorian) { UErrorCode status = U_ZERO_ERROR; const jchar* month; jstring monthU; UResourceBundle *gregorianElems = ures_getByKey(gregorian, "monthNames", NULL, &status); if(U_FAILURE(status)) { return NULL; } UResourceBundle *monthNameElems = ures_getByKey(gregorianElems, "format", NULL, &status); if(U_FAILURE(status)) { ures_close(gregorianElems); return NULL; } UResourceBundle *monthNameElemsFormat = ures_getByKey(monthNameElems, "wide", NULL, &status); if(U_FAILURE(status)) { ures_close(monthNameElems); ures_close(gregorianElems); return NULL; } int monthNameLength; ures_resetIterator(monthNameElemsFormat); int monthCount = ures_getSize(monthNameElemsFormat); jobjectArray months = env->NewObjectArray(monthCount + 1, string_class, NULL); for(int i = 0; i < monthCount; i++) { month = ures_getStringByIndex(monthNameElemsFormat, i, &monthNameLength, &status); if(U_FAILURE(status)) { ures_close(monthNameElemsFormat); ures_close(monthNameElems); ures_close(gregorianElems); return NULL; } monthU = env->NewString(month, monthNameLength); env->SetObjectArrayElement(months, i, monthU); env->DeleteLocalRef(monthU); } monthU = env->NewStringUTF(""); env->SetObjectArrayElement(months, monthCount, monthU); env->DeleteLocalRef(monthU); ures_close(monthNameElemsFormat); ures_close(monthNameElems); ures_close(gregorianElems); return months; }
static jobjectArray getWeekdayNames(JNIEnv *env, UResourceBundle *gregorian) { UErrorCode status = U_ZERO_ERROR; const jchar* day; jstring dayU; UResourceBundle *gregorianElems = ures_getByKey(gregorian, "dayNames", NULL, &status); if(U_FAILURE(status)) { return NULL; } UResourceBundle *dayNameElems = ures_getByKey(gregorianElems, "format", NULL, &status); if(U_FAILURE(status)) { ures_close(gregorianElems); return NULL; } UResourceBundle *dayNameElemsFormat = ures_getByKey(dayNameElems, "wide", NULL, &status); if(U_FAILURE(status)) { ures_close(dayNameElems); ures_close(gregorianElems); return NULL; } int dayNameLength; ures_resetIterator(dayNameElemsFormat); int dayCount = ures_getSize(dayNameElemsFormat); jobjectArray weekdays = env->NewObjectArray(dayCount + 1, string_class, NULL); // first entry in the weekdays array is an empty string env->SetObjectArrayElement(weekdays, 0, env->NewStringUTF("")); for(int i = 0; i < dayCount; i++) { day = ures_getStringByIndex(dayNameElemsFormat, i, &dayNameLength, &status); if(U_FAILURE(status)) { ures_close(dayNameElemsFormat); ures_close(dayNameElems); ures_close(gregorianElems); return NULL; } dayU = env->NewString(day, dayNameLength); env->SetObjectArrayElement(weekdays, i + 1, dayU); env->DeleteLocalRef(dayU); } ures_close(dayNameElemsFormat); ures_close(dayNameElems); ures_close(gregorianElems); return weekdays; }
/* {{{ resourcebundle_array_count */ int resourcebundle_array_count(zend_object *object, zend_long *count) { ResourceBundle_object *rb = php_intl_resourcebundle_fetch_object(object); if (rb->me == NULL) { intl_errors_set(&rb->error, U_ILLEGAL_ARGUMENT_ERROR, "Found unconstructed ResourceBundle", 0); return 0; } *count = ures_getSize( rb->me ); return SUCCESS; }
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 UBool getOlsonMeta(const UResourceBundle* top) { if (OLSON_ZONE_COUNT == 0) { UErrorCode ec = U_ZERO_ERROR; UResourceBundle res; ures_initStackObject(&res); ures_getByKey(top, kZONES, &res, &ec); if(U_SUCCESS(ec)) { OLSON_ZONE_COUNT = ures_getSize(&res); U_DEBUG_TZ_MSG(("OZC%d\n",OLSON_ZONE_COUNT)); } ures_close(&res); } return (OLSON_ZONE_COUNT > 0); }
/* {{{ resourcebundle_array_count */ int resourcebundle_array_count(zval *object, zend_long *count) { ResourceBundle_object *rb; RESOURCEBUNDLE_METHOD_FETCH_OBJECT_NO_CHECK; if (rb->me == NULL) { intl_errors_set(&rb->error, U_ILLEGAL_ARGUMENT_ERROR, "Found unconstructed ResourceBundle", 0); return 0; } *count = ures_getSize( rb->me ); return SUCCESS; }
static jobjectArray getShortWeekdayNames(JNIEnv *env, UResourceBundle *gregorian) { UErrorCode status = U_ZERO_ERROR; const jchar* shortDay; jstring shortDayU; UResourceBundle *gregorianElems = ures_getByKey(gregorian, "dayNames", NULL, &status); if(U_FAILURE(status)) { return NULL; } UResourceBundle *dayNameElems = ures_getByKey(gregorianElems, "format", NULL, &status); if(U_FAILURE(status)) { ures_close(gregorianElems); return NULL; } UResourceBundle *dayNameElemsFormat = ures_getByKey(dayNameElems, "abbreviated", NULL, &status); if(U_FAILURE(status)) { ures_close(dayNameElems); ures_close(gregorianElems); return NULL; } int shortDayNameLength; ures_resetIterator(dayNameElemsFormat); int shortDayCount = ures_getSize(dayNameElemsFormat); jobjectArray shortWeekdays = env->NewObjectArray(shortDayCount + 1, string_class, NULL); env->SetObjectArrayElement(shortWeekdays, 0, env->NewStringUTF("")); for(int i = 0; i < shortDayCount; i++) { shortDay = ures_getStringByIndex(dayNameElemsFormat, i, &shortDayNameLength, &status); if(U_FAILURE(status)) { ures_close(dayNameElemsFormat); ures_close(dayNameElems); ures_close(gregorianElems); return NULL; } shortDayU = env->NewString(shortDay, shortDayNameLength); env->SetObjectArrayElement(shortWeekdays, i + 1, shortDayU); env->DeleteLocalRef(shortDayU); } ures_close(dayNameElemsFormat); ures_close(dayNameElems); ures_close(gregorianElems); return shortWeekdays; }
static void EnumUResourceBundle(const UResourceBundle* bundle, EnumCalendarInfoCallback callback, const void* context) { int32_t eraNameCount = ures_getSize(bundle); for (int i = 0; i < eraNameCount; i++) { UErrorCode status = U_ZERO_ERROR; int32_t ignore; // We don't care about the length of the string as it is null terminated. const UChar* eraName = ures_getStringByIndex(bundle, i, &ignore, &status); if (U_SUCCESS(status)) { callback(eraName, context); } } }
static jobjectArray getEras(JNIEnv* env, UResourceBundle *gregorian) { jobjectArray eras; jstring eraU; const jchar* era; UErrorCode status = U_ZERO_ERROR; UResourceBundle *gregorianElems; UResourceBundle *eraElems; gregorianElems = ures_getByKey(gregorian, "eras", NULL, &status); if(U_FAILURE(status)) { return NULL; } eraElems = ures_getByKey(gregorianElems, "abbreviated", NULL, &status); if(U_FAILURE(status)) { ures_close(gregorianElems); return NULL; } int eraLength; int eraCount = ures_getSize(eraElems); eras = env->NewObjectArray(eraCount, string_class, NULL); ures_resetIterator(eraElems); for(int i = 0; i < eraCount; i++) { era = ures_getStringByIndex(eraElems, i, &eraLength, &status); if(U_FAILURE(status)) { ures_close(gregorianElems); ures_close(eraElems); return NULL; } eraU = env->NewString(era, eraLength); env->SetObjectArrayElement(eras, i, eraU); env->DeleteLocalRef(eraU); } ures_close(eraElems); ures_close(gregorianElems); return eras; }
void RelativeDateFormat::loadDates(UErrorCode &status) { UResourceBundle *rb = ures_open(NULL, fLocale.getBaseName(), &status); LocalUResourceBundlePointer dateTimePatterns( ures_getByKeyWithFallback(rb, "calendar/gregorian/DateTimePatterns", (UResourceBundle*)NULL, &status)); if(U_SUCCESS(status)) { int32_t patternsSize = ures_getSize(dateTimePatterns.getAlias()); if (patternsSize > kDateTime) { int32_t resStrLen = 0; int32_t glueIndex = kDateTime; if (patternsSize >= (kDateTimeOffset + kShort + 1)) { int32_t offsetIncrement = (fDateStyle & ~kRelative); // Remove relative bit. if (offsetIncrement >= (int32_t)kFull && offsetIncrement <= (int32_t)kShortRelative) { glueIndex = kDateTimeOffset + offsetIncrement; } } const UChar *resStr = ures_getStringByIndex(dateTimePatterns.getAlias(), glueIndex, &resStrLen, &status); if (U_SUCCESS(status) && resStrLen >= patItem1Len && u_strncmp(resStr,patItem1,patItem1Len)==0) { fCombinedHasDateAtStart = TRUE; } fCombinedFormat = new SimpleFormatter(UnicodeString(TRUE, resStr, resStrLen), 2, 2, status); } } // Data loading for relative names, e.g., "yesterday", "today", "tomorrow". fDatesLen = UDAT_DIRECTION_COUNT; // Maximum defined by data. fDates = (URelativeString*) uprv_malloc(sizeof(fDates[0])*fDatesLen); RelDateFmtDataSink sink(fDates, fDatesLen); ures_getAllItemsWithFallback(rb, "fields/day/relative", sink, status); ures_close(rb); if(U_FAILURE(status)) { fDatesLen=0; return; } }
const UnicodeString U_EXPORT2 TimeZone::getEquivalentID(const UnicodeString& id, int32_t index) { U_DEBUG_TZ_MSG(("gEI(%d)\n", index)); UnicodeString result; UErrorCode ec = U_ZERO_ERROR; UResourceBundle res; ures_initStackObject(&res); UResourceBundle *top = openOlsonResource(id, res, ec); int32_t zone = -1; if (U_SUCCESS(ec)) { int32_t size = ures_getSize(&res); if (size == 4 || size == 6) { UResourceBundle r; ures_initStackObject(&r); ures_getByIndex(&res, size-1, &r, &ec); const int32_t* v = ures_getIntVector(&r, &size, &ec); if (index >= 0 && index < size && getOlsonMeta()) { zone = v[index]; } ures_close(&r); } } ures_close(&res); if (zone >= 0) { UResourceBundle *ares = ures_getByKey(top, kNAMES, NULL, &ec); // dereference Zones section if (U_SUCCESS(ec)) { int32_t idLen = 0; const UChar* id = ures_getStringByIndex(ares, zone, &idLen, &ec); result.fastCopyFrom(UnicodeString(TRUE, id, idLen)); U_DEBUG_TZ_MSG(("gei(%d) -> %d, len%d, %s\n", index, zone, result.length(), u_errorName(ec))); } ures_close(ares); } ures_close(top); #if defined(U_DEBUG_TZ) if(result.length() ==0) { U_DEBUG_TZ_MSG(("equiv [__, #%d] -> 0 (%s)\n", index, u_errorName(ec))); } #endif return result; }
static int32_t findInStringArray(UResourceBundle* array, const UnicodeString& id, UErrorCode &status) { UnicodeString copy; const UChar *u; int32_t len; int32_t start = 0; int32_t limit = ures_getSize(array); int32_t mid; int32_t lastMid = INT32_MAX; if(U_FAILURE(status) || (limit < 1)) { return -1; } U_DEBUG_TZ_MSG(("fisa: Looking for %s, between %d and %d\n", U_DEBUG_TZ_STR(UnicodeString(id).getTerminatedBuffer()), start, limit)); for (;;) { mid = (int32_t)((start + limit) / 2); if (lastMid == mid) { /* Have we moved? */ break; /* We haven't moved, and it wasn't found. */ } lastMid = mid; u = ures_getStringByIndex(array, mid, &len, &status); if (U_FAILURE(status)) { break; } U_DEBUG_TZ_MSG(("tz: compare to %s, %d .. [%d] .. %d\n", U_DEBUG_TZ_STR(u), start, mid, limit)); copy.setTo(TRUE, u, len); int r = id.compare(copy); if(r==0) { U_DEBUG_TZ_MSG(("fisa: found at %d\n", mid)); return mid; } else if(r<0) { limit = mid; } else { start = mid; } } U_DEBUG_TZ_MSG(("fisa: not found\n")); return -1; }
// initCDFLocaleStyleData loads formatting data for a particular style. // decimalFormatBundle is the "decimalFormat" resource bundle in CLDR. // Loaded data stored in result. static void initCDFLocaleStyleData(const UResourceBundle* decimalFormatBundle, CDFLocaleStyleData* result, UErrorCode& status) { if (U_FAILURE(status)) { return; } // Iterate through all the powers of 10. int32_t size = ures_getSize(decimalFormatBundle); UResourceBundle* power10 = NULL; for (int32_t i = 0; i < size; ++i) { power10 = ures_getByIndex(decimalFormatBundle, i, power10, &status); if (U_FAILURE(status)) { ures_close(power10); return; } populatePower10(power10, result, status); if (U_FAILURE(status)) { ures_close(power10); return; } } ures_close(power10); fillInMissing(result); }
RBTestDataModule::RBTestDataModule(const char* name, TestLog& log, UErrorCode& status) : TestDataModule(name, log, status), fModuleBundle(NULL), fTestData(NULL), fInfoRB(NULL), tdpath(NULL) { fNumberOfTests = 0; fDataTestValid = TRUE; fModuleBundle = getTestBundle(name, status); if(fDataTestValid) { fTestData = ures_getByKey(fModuleBundle, "TestData", NULL, &status); fNumberOfTests = ures_getSize(fTestData); fInfoRB = ures_getByKey(fModuleBundle, "Info", NULL, &status); if(status != U_ZERO_ERROR) { log.errln(UNICODE_STRING_SIMPLE("Unable to initalize test data - missing mandatory description resources!")); fDataTestValid = FALSE; } else { fInfo = new RBDataMap(fInfoRB, status); } } }
static jobjectArray getMonthNames(JNIEnv* env, UResourceBundle* gregorian, bool longNames) { UErrorCode status = U_ZERO_ERROR; ScopedResourceBundle gregorianElems(ures_getByKey(gregorian, "monthNames", NULL, &status)); if (U_FAILURE(status)) { return NULL; } ScopedResourceBundle monthNameElems(ures_getByKey(gregorianElems.get(), "format", NULL, &status)); if (U_FAILURE(status)) { return NULL; } ScopedResourceBundle monthNameElemsFormat(ures_getByKey(monthNameElems.get(), longNames ? "wide" : "abbreviated", NULL, &status)); if (U_FAILURE(status)) { return NULL; } ures_resetIterator(monthNameElemsFormat.get()); int monthCount = ures_getSize(monthNameElemsFormat.get()); // the array length is +1 because the harmony locales had an empty string at the end of their month name array jobjectArray months = env->NewObjectArray(monthCount + 1, string_class, NULL); for (int i = 0; i < monthCount; ++i) { int monthNameLength; const jchar* month = ures_getStringByIndex(monthNameElemsFormat.get(), i, &monthNameLength, &status); if (U_FAILURE(status)) { return NULL; } jstring monthU = env->NewString(month, monthNameLength); env->SetObjectArrayElement(months, i, monthU); env->DeleteLocalRef(monthU); } jstring monthU = env->NewStringUTF(""); env->SetObjectArrayElement(months, monthCount, monthU); env->DeleteLocalRef(monthU); return months; }
UnicodeString& TimeZone::dereferOlsonLink(const UnicodeString& linkTo, UnicodeString& linkFrom) { UErrorCode ec = U_ZERO_ERROR; linkFrom.remove(); UResourceBundle *top = ures_openDirect(0, kZONEINFO, &ec); UResourceBundle *res = getZoneByName(top, linkTo, NULL, ec); if (U_SUCCESS(ec)) { if (ures_getSize(res) == 1) { int32_t deref = ures_getInt(res, &ec); UResourceBundle *nres = ures_getByKey(top, kNAMES, NULL, &ec); // dereference Names section int32_t len; const UChar* tmp = ures_getStringByIndex(nres, deref, &len, &ec); if (U_SUCCESS(ec)) { linkFrom.setTo(tmp, len); } ures_close(nres); } else { linkFrom.setTo(linkTo); } } ures_close(res); ures_close(top); return linkFrom; }