/* Function: GetCalendars Returns the list of CalendarIds that are available for the specified locale. */ int32_t GlobalizationNative_GetCalendars( const UChar* localeName, CalendarId* calendars, int32_t calendarsCapacity) { UErrorCode err = U_ZERO_ERROR; char locale[ULOC_FULLNAME_CAPACITY]; GetLocale(localeName, locale, ULOC_FULLNAME_CAPACITY, FALSE, &err); UEnumeration* pEnum = ucal_getKeywordValuesForLocale("calendar", locale, TRUE, &err); int stringEnumeratorCount = uenum_count(pEnum, &err); int calendarsReturned = 0; for (int i = 0; i < stringEnumeratorCount && calendarsReturned < calendarsCapacity; i++) { int32_t calendarNameLength = 0; const char* calendarName = uenum_next(pEnum, &calendarNameLength, &err); if (U_SUCCESS(err)) { CalendarId calendarId = GetCalendarId(calendarName); if (calendarId != UNINITIALIZED_VALUE) { calendars[calendarsReturned] = calendarId; calendarsReturned++; } } } uenum_close(pEnum); return calendarsReturned; }
static Vector<String> localeData(const String& locale, size_t keyIndex) { Vector<String> keyLocaleData; switch (keyIndex) { case indexOfExtensionKeyCa: { UErrorCode status = U_ZERO_ERROR; UEnumeration* calendars = ucal_getKeywordValuesForLocale("calendar", locale.utf8().data(), false, &status); ASSERT(U_SUCCESS(status)); int32_t nameLength; while (const char* availableName = uenum_next(calendars, &nameLength, &status)) { ASSERT(U_SUCCESS(status)); String calendar = String(availableName, nameLength); keyLocaleData.append(calendar); // Ensure aliases used in language tag are allowed. if (calendar == "gregorian") keyLocaleData.append(ASCIILiteral("gregory")); else if (calendar == "islamic-civil") keyLocaleData.append(ASCIILiteral("islamicc")); else if (calendar == "ethiopic-amete-alem") keyLocaleData.append(ASCIILiteral("ethioaa")); } uenum_close(calendars); break; } case indexOfExtensionKeyNu: keyLocaleData = numberingSystemsForLocale(locale); break; default: ASSERT_NOT_REACHED(); } return keyLocaleData; }
static Variant HHVM_STATIC_METHOD(IntlCalendar, getKeywordValuesForLocale, const String& key, const String& locale, bool common) { UErrorCode error = U_ZERO_ERROR; UEnumeration *uenum = ucal_getKeywordValuesForLocale(key.c_str(), ULOC_DEFAULT(locale).c_str(), common, &error); if (U_FAILURE(error)) { if (uenum) { uenum_close(uenum); } s_intl_error->set(error, "intlcal_get_keyword_values_for_locale: " "error calling underlying method"); return false; } return IntlIterator::newInstance(new BugStringCharEnumeration(uenum)); }
U_CFUNC PHP_FUNCTION(intlcal_get_keyword_values_for_locale) { UErrorCode status = U_ZERO_ERROR; char *key, *locale; int key_len, locale_len; zend_bool commonly_used; intl_error_reset(NULL TSRMLS_CC); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ssb", &key, &key_len, &locale, &locale_len, &commonly_used) == FAILURE) { intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, "intlcal_get_keyword_values_for_locale: bad arguments", 0 TSRMLS_CC); RETURN_FALSE; } //does not work; see ICU bug 9194 #if 0 StringEnumeration *se = Calendar::getKeywordValuesForLocale(key, Locale::createFromName(locale), (UBool)commonly_used, status); if (se == NULL) { intl_error_set(NULL, status, "intlcal_get_keyword_values_for_locale: " "error calling underlying method", 0 TSRMLS_CC); RETURN_FALSE; } #else UEnumeration *uenum = ucal_getKeywordValuesForLocale( key, locale, !!commonly_used, &status); if (U_FAILURE(status)) { uenum_close(uenum); intl_error_set(NULL, status, "intlcal_get_keyword_values_for_locale: " "error calling underlying method", 0 TSRMLS_CC); RETURN_FALSE; } StringEnumeration *se = new BugStringCharEnumeration(uenum); #endif IntlIterator_from_StringEnumeration(se, return_value TSRMLS_CC); }