U_CFUNC PHP_FUNCTION(intlcal_add) { long field, amount; CALENDAR_METHOD_INIT_VARS; if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Oll", &object, Calendar_ce_ptr, &field, &amount) == FAILURE) { intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, "intlcal_add: bad arguments", 0 TSRMLS_CC); RETURN_FALSE; } if (field < 0 || field >= UCAL_FIELD_COUNT) { intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, "intlcal_add: invalid field", 0 TSRMLS_CC); RETURN_FALSE; } if (amount < INT32_MIN || amount > INT32_MAX) { intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, "intlcal_add: amount out of bounds", 0 TSRMLS_CC); RETURN_FALSE; } CALENDAR_METHOD_FETCH_OBJECT; co->ucal->add((UCalendarDateFields)field, (int32_t)amount, CALENDAR_ERROR_CODE(co)); INTL_METHOD_CHECK_STATUS(co, "intlcal_add: Call to underlying method failed"); RETURN_TRUE; }
U_CFUNC PHP_FUNCTION(intlcal_set_minimal_days_in_first_week) { long num_days; CALENDAR_METHOD_INIT_VARS; if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Ol", &object, Calendar_ce_ptr, &num_days) == FAILURE) { intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, "intlcal_set_minimal_days_in_first_week: bad arguments", 0 TSRMLS_CC); RETURN_FALSE; } if (num_days < 1 || num_days > 7) { intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, "intlcal_set_minimal_days_in_first_week: invalid number of days; " "must be between 1 and 7", 0 TSRMLS_CC); RETURN_FALSE; } CALENDAR_METHOD_FETCH_OBJECT; co->ucal->setMinimalDaysInFirstWeek((uint8_t)num_days); RETURN_TRUE; }
U_CFUNC PHP_FUNCTION(intlcal_get_weekend_transition) { long dow; CALENDAR_METHOD_INIT_VARS; if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Ol", &object, Calendar_ce_ptr, &dow) == FAILURE) { intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, "intlcal_get_weekend_transition: bad arguments", 0 TSRMLS_CC); RETURN_FALSE; } if (dow < UCAL_SUNDAY || dow > UCAL_SATURDAY) { intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, "intlcal_get_weekend_transition: invalid day of week", 0 TSRMLS_CC); RETURN_FALSE; } CALENDAR_METHOD_FETCH_OBJECT; int32_t res = co->ucal->getWeekendTransition((UCalendarDaysOfWeek)dow, CALENDAR_ERROR_CODE(co)); INTL_METHOD_CHECK_STATUS(co, "intlcal_get_weekend_transition: " "Error calling ICU method"); RETURN_LONG((long)res); }
U_CFUNC PHP_FUNCTION(intlcal_is_equivalent_to) { zval *other_object; Calendar_object *other_co; CALENDAR_METHOD_INIT_VARS; if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "OO", &object, Calendar_ce_ptr, &other_object, Calendar_ce_ptr) == FAILURE) { intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, "intlcal_is_equivalent_to: bad arguments", 0 TSRMLS_CC); RETURN_FALSE; } other_co = Z_INTL_CALENDAR_P(other_object); if (other_co->ucal == NULL) { intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, "intlcal_is_equivalent_to:" " Other IntlCalendar is unconstructed", 0 TSRMLS_CC); RETURN_FALSE; } CALENDAR_METHOD_FETCH_OBJECT; RETURN_BOOL((int)co->ucal->isEquivalentTo(*other_co->ucal)); }
U_CFUNC PHP_FUNCTION(intlcal_get_locale) { long locale_type; CALENDAR_METHOD_INIT_VARS; if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Ol", &object, Calendar_ce_ptr, &locale_type) == FAILURE) { intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, "intlcal_get_locale: bad arguments", 0 TSRMLS_CC); RETURN_FALSE; } if (locale_type != ULOC_ACTUAL_LOCALE && locale_type != ULOC_VALID_LOCALE) { intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, "intlcal_get_locale: invalid locale type", 0 TSRMLS_CC); RETURN_FALSE; } CALENDAR_METHOD_FETCH_OBJECT; Locale locale = co->ucal->getLocale((ULocDataLocaleType)locale_type, CALENDAR_ERROR_CODE(co)); INTL_METHOD_CHECK_STATUS(co, "intlcal_get_locale: Call to ICU method has failed"); RETURN_STRING(locale.getName()); }
static void _php_intlcal_field_ret_in32t_method( int32_t (Calendar::*func)(UCalendarDateFields) const, const char *method_name, INTERNAL_FUNCTION_PARAMETERS) { long field; char *message; CALENDAR_METHOD_INIT_VARS; if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Ol", &object, Calendar_ce_ptr, &field) == FAILURE) { spprintf(&message, 0, "%s: bad arguments", method_name); intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, message, 1 TSRMLS_CC); efree(message); RETURN_FALSE; } if (field < 0 || field >= UCAL_FIELD_COUNT) { spprintf(&message, 0, "%s: invalid field", method_name); intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, message, 1 TSRMLS_CC); efree(message); RETURN_FALSE; } CALENDAR_METHOD_FETCH_OBJECT; int32_t result = (co->ucal->*func)((UCalendarDateFields)field); INTL_METHOD_CHECK_STATUS(co, "Call to ICU method has failed"); RETURN_LONG((long)result); }
U_CFUNC PHP_FUNCTION(intlcal_field_difference) { long field; double when; CALENDAR_METHOD_INIT_VARS; if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Odl", &object, Calendar_ce_ptr, &when, &field) == FAILURE) { intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, "intlcal_field_difference: bad arguments", 0 TSRMLS_CC); RETURN_FALSE; } if (field < 0 || field >= UCAL_FIELD_COUNT) { intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, "intlcal_field_difference: invalid field", 0 TSRMLS_CC); RETURN_FALSE; } CALENDAR_METHOD_FETCH_OBJECT; int32_t result = co->ucal->fieldDifference((UDate)when, (UCalendarDateFields)field, CALENDAR_ERROR_CODE(co)); INTL_METHOD_CHECK_STATUS(co, "intlcal_field_difference: Call to ICU method has failed"); RETURN_LONG((long)result); }
U_CFUNC PHP_FUNCTION(intlcal_set_skipped_wall_time_option) { long option; CALENDAR_METHOD_INIT_VARS; if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Ol", &object, Calendar_ce_ptr, &option) == FAILURE) { intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, "intlcal_set_skipped_wall_time_option: bad arguments", 0 TSRMLS_CC); RETURN_FALSE; } if (option != UCAL_WALLTIME_FIRST && option != UCAL_WALLTIME_LAST && option != UCAL_WALLTIME_NEXT_VALID) { intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, "intlcal_set_skipped_wall_time_option: invalid option", 0 TSRMLS_CC); RETURN_FALSE; } CALENDAR_METHOD_FETCH_OBJECT; co->ucal->setSkippedWallTimeOption((UCalendarWallTimeOption)option); RETURN_TRUE; }
U_CFUNC PHP_FUNCTION(intlcal_roll) { zend_long field, value; zval args_a[3] = {0}, *args = args_a; zend_bool bool_variant_val = (zend_bool)-1; CALENDAR_METHOD_INIT_VARS; if (ZEND_NUM_ARGS() > (getThis() ? 2 :3) || zend_get_parameters_array_ex(ZEND_NUM_ARGS(), args) == FAILURE) { intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, "intlcal_set: too many arguments", 0 TSRMLS_CC); RETURN_FALSE; } if (!getThis()) { args++; } if (!Z_ISUNDEF(args[1]) && (Z_TYPE(args[1]) == IS_TRUE || Z_TYPE(args[1]) == IS_FALSE)) { if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Olb", &object, Calendar_ce_ptr, &field, &bool_variant_val) == FAILURE) { intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, "intlcal_roll: bad arguments", 0 TSRMLS_CC); RETURN_FALSE; } bool_variant_val = Z_TYPE(args[1]) == IS_TRUE? 1 : 0; } else if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Oll", &object, Calendar_ce_ptr, &field, &value) == FAILURE) { intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, "intlcal_roll: bad arguments", 0 TSRMLS_CC); RETURN_FALSE; } if (field < 0 || field >= UCAL_FIELD_COUNT) { intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, "intlcal_roll: invalid field", 0 TSRMLS_CC); RETURN_FALSE; } if (bool_variant_val == (zend_bool)-1 && (value < INT32_MIN || value > INT32_MAX)) { intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, "intlcal_roll: value out of bounds", 0 TSRMLS_CC); RETURN_FALSE; } CALENDAR_METHOD_FETCH_OBJECT; if (bool_variant_val != (zend_bool)-1) { co->ucal->roll((UCalendarDateFields)field, (UBool)bool_variant_val, CALENDAR_ERROR_CODE(co)); } else { co->ucal->roll((UCalendarDateFields)field, (int32_t)value, CALENDAR_ERROR_CODE(co)); } INTL_METHOD_CHECK_STATUS(co, "intlcal_roll: Error calling ICU Calendar::roll"); RETURN_TRUE; }
/* {{{ ResourceBundle_ctor */ static int resourcebundle_ctor(INTERNAL_FUNCTION_PARAMETERS, zend_bool is_constructor) { const char *bundlename; size_t bundlename_len = 0; const char *locale; size_t locale_len = 0; zend_bool fallback = 1; int zpp_flags = is_constructor ? ZEND_PARSE_PARAMS_THROW : 0; zval *object = return_value; ResourceBundle_object *rb = Z_INTL_RESOURCEBUNDLE_P( object ); intl_error_reset( NULL ); if( zend_parse_parameters_ex( zpp_flags, ZEND_NUM_ARGS(), "s!s!|b", &locale, &locale_len, &bundlename, &bundlename_len, &fallback ) == FAILURE ) { intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, "resourcebundle_ctor: unable to parse input parameters", 0 ); return FAILURE; } INTL_CHECK_LOCALE_LEN_OR_FAILURE(locale_len); if (locale == NULL) { locale = intl_locale_get_default(); } if (bundlename_len >= MAXPATHLEN) { intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, "Bundle name too long", 0 ); zval_ptr_dtor(return_value); ZVAL_NULL(return_value); return FAILURE; } if (fallback) { rb->me = ures_open(bundlename, locale, &INTL_DATA_ERROR_CODE(rb)); } else { rb->me = ures_openDirect(bundlename, locale, &INTL_DATA_ERROR_CODE(rb)); } INTL_CTOR_CHECK_STATUS(rb, "resourcebundle_ctor: Cannot load libICU resource bundle"); if (!fallback && (INTL_DATA_ERROR_CODE(rb) == U_USING_FALLBACK_WARNING || INTL_DATA_ERROR_CODE(rb) == U_USING_DEFAULT_WARNING)) { char *pbuf; intl_errors_set_code(NULL, INTL_DATA_ERROR_CODE(rb)); spprintf(&pbuf, 0, "resourcebundle_ctor: Cannot load libICU resource " "'%s' without fallback from %s to %s", bundlename ? bundlename : "(default data)", locale, ures_getLocaleByType( rb->me, ULOC_ACTUAL_LOCALE, &INTL_DATA_ERROR_CODE(rb))); intl_errors_set_custom_msg(INTL_DATA_ERROR_P(rb), pbuf, 1); efree(pbuf); return FAILURE; } return SUCCESS; }
/* {{{ * Gets the value from ICU , called when PHP userspace function is called * common code shared by get_primary_language,get_script or get_region or get_variant */ static void get_icu_value_src_php( char* tag_name, INTERNAL_FUNCTION_PARAMETERS) { const char* loc_name = NULL; size_t loc_name_len = 0; char* tag_value = NULL; char* empty_result = ""; int result = 0; char* msg = NULL; UErrorCode status = U_ZERO_ERROR; intl_error_reset( NULL ); if(zend_parse_parameters( ZEND_NUM_ARGS(), "s", &loc_name ,&loc_name_len ) == FAILURE) { spprintf(&msg , 0, "locale_get_%s : unable to parse input params", tag_name ); intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, msg , 1 ); efree(msg); RETURN_FALSE; } if(loc_name_len == 0) { loc_name = intl_locale_get_default(); } /* Call ICU get */ tag_value = get_icu_value_internal( loc_name , tag_name , &result ,0); /* No value found */ if( result == -1 ) { if( tag_value){ efree( tag_value); } RETURN_STRING( empty_result); } /* value found */ if( tag_value){ RETVAL_STRING( tag_value ); //??? efree(tag_value); return; } /* Error encountered while fetching the value */ if( result ==0) { spprintf(&msg , 0, "locale_get_%s : unable to get locale %s", tag_name , tag_name ); intl_error_set( NULL, status, msg , 1 ); efree(msg); RETURN_NULL(); } }
U_CFUNC PHP_FUNCTION(intltz_create_time_zone_id_enumeration) { long zoneType, offset_arg; char *region = NULL; int region_len = 0; int32_t offset, *offsetp = NULL; int arg3isnull = 0; intl_error_reset(NULL TSRMLS_CC); /* must come before zpp because zpp would convert the arg in the stack to 0 */ if (ZEND_NUM_ARGS() == 3) { zval **dummy, **zvoffset; arg3isnull = zend_get_parameters_ex(3, &dummy, &dummy, &zvoffset) != FAILURE && Z_TYPE_PP(zvoffset) == IS_NULL; } if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l|s!l", &zoneType, ®ion, ®ion_len, &offset_arg) == FAILURE) { intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, "intltz_create_time_zone_id_enumeration: bad arguments", 0 TSRMLS_CC); RETURN_FALSE; } if (zoneType != UCAL_ZONE_TYPE_ANY && zoneType != UCAL_ZONE_TYPE_CANONICAL && zoneType != UCAL_ZONE_TYPE_CANONICAL_LOCATION) { intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, "intltz_create_time_zone_id_enumeration: bad zone type", 0 TSRMLS_CC); RETURN_FALSE; } if (ZEND_NUM_ARGS() == 3) { if (offset_arg < (long)INT32_MIN || offset_arg > (long)INT32_MAX) { intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, "intltz_create_time_zone_id_enumeration: offset out of bounds", 0 TSRMLS_CC); RETURN_FALSE; } if (!arg3isnull) { offset = (int32_t)offset_arg; offsetp = &offset; } //else leave offsetp NULL } StringEnumeration *se; UErrorCode uec = UErrorCode(); se = TimeZone::createTimeZoneIDEnumeration((USystemTimeZoneType)zoneType, region, offsetp, uec); INTL_CHECK_STATUS(uec, "intltz_create_time_zone_id_enumeration: " "Error obtaining time zone id enumeration") IntlIterator_from_StringEnumeration(se, return_value TSRMLS_CC); }
U_CFUNC PHP_FUNCTION(intlcal_clear) { zval args_a[2] = {0}, *args = &args_a[0]; zend_long field; int variant; CALENDAR_METHOD_INIT_VARS; if (ZEND_NUM_ARGS() > (getThis() ? 1 : 2) || zend_get_parameters_array_ex(ZEND_NUM_ARGS(), args) == FAILURE) { intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, "intlcal_clear: too many arguments", 0 TSRMLS_CC); RETURN_FALSE; } if (!getThis()) { args++; } if (Z_ISUNDEF(args[0]) || Z_TYPE(args[0]) == IS_NULL) { zval *dummy; /* we know it's null */ if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O|z", &object, Calendar_ce_ptr, &dummy) == FAILURE) { intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, "intlcal_clear: bad arguments", 0 TSRMLS_CC); RETURN_FALSE; } variant = 0; } else if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Ol", &object, Calendar_ce_ptr, &field) == FAILURE) { intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, "intlcal_clear: bad arguments", 0 TSRMLS_CC); RETURN_FALSE; } else if (field < 0 || field >= UCAL_FIELD_COUNT) { intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, "intlcal_clear: invalid field", 0 TSRMLS_CC); RETURN_FALSE; } else { variant = 1; } CALENDAR_METHOD_FETCH_OBJECT; if (variant == 0) { co->ucal->clear(); } else { co->ucal->clear((UCalendarDateFields)field); } RETURN_TRUE; }
U_CFUNC PHP_FUNCTION(intlcal_set_time_zone) { zval *zv_timezone; TimeZone *timeZone; CALENDAR_METHOD_INIT_VARS; if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Oz!", &object, Calendar_ce_ptr, &zv_timezone) == FAILURE) { intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, "intlcal_set_time_zone: bad arguments", 0 TSRMLS_CC); RETURN_FALSE; } CALENDAR_METHOD_FETCH_OBJECT; if (zv_timezone == NULL) { RETURN_TRUE; /* the method does nothing if passed null */ } timeZone = timezone_process_timezone_argument(zv_timezone, CALENDAR_ERROR_P(co), "intlcal_set_time_zone" TSRMLS_CC); if (timeZone == NULL) { RETURN_FALSE; } co->ucal->adoptTimeZone(timeZone); RETURN_TRUE; }
/* {{{ */ static int collator_ctor(INTERNAL_FUNCTION_PARAMETERS, zend_bool is_constructor) { const char* locale; size_t locale_len = 0; zval* object; Collator_object* co; int zpp_flags = is_constructor ? ZEND_PARSE_PARAMS_THROW : 0; intl_error_reset( NULL ); object = return_value; /* Parse parameters. */ if( zend_parse_parameters_ex( zpp_flags, ZEND_NUM_ARGS(), "s", &locale, &locale_len ) == FAILURE ) { intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, "collator_create: unable to parse input params", 0 ); return FAILURE; } INTL_CHECK_LOCALE_LEN_OR_FAILURE(locale_len); COLLATOR_METHOD_FETCH_OBJECT; if(locale_len == 0) { locale = intl_locale_get_default(); } /* Open ICU collator. */ co->ucoll = ucol_open( locale, COLLATOR_ERROR_CODE_P( co ) ); INTL_CTOR_CHECK_STATUS(co, "collator_create: unable to open ICU collator"); return SUCCESS; }
U_CFUNC PHP_FUNCTION(intlcal_equals) { zval *other_object; Calendar_object *other_co; CALENDAR_METHOD_INIT_VARS; if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "OO", &object, Calendar_ce_ptr, &other_object, Calendar_ce_ptr) == FAILURE) { intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, "intlcal_equals: bad arguments", 0 TSRMLS_CC); RETURN_FALSE; } CALENDAR_METHOD_FETCH_OBJECT; other_co = Z_INTL_CALENDAR_P(other_object); if (other_co->ucal == NULL) { intl_errors_set(&co->err, U_ILLEGAL_ARGUMENT_ERROR, "intlcal_equals: The second IntlCalendar is unconstructed", 0 TSRMLS_CC); RETURN_FALSE; } UBool result = co->ucal->equals(*other_co->ucal, CALENDAR_ERROR_CODE(co)); INTL_METHOD_CHECK_STATUS(co, "intlcal_equals: error calling ICU Calendar::equals"); RETURN_BOOL((int)result); }
U_CFUNC PHP_FUNCTION(intltz_get_offset) { double date; zend_bool local; zval *rawOffsetArg, *dstOffsetArg; int32_t rawOffset, dstOffset; TIMEZONE_METHOD_INIT_VARS; if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "Odbz/z/", &object, TimeZone_ce_ptr, &date, &local, &rawOffsetArg, &dstOffsetArg) == FAILURE) { intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, "intltz_get_offset: bad arguments", 0); RETURN_FALSE; } TIMEZONE_METHOD_FETCH_OBJECT; to->utimezone->getOffset((UDate) date, (UBool) local, rawOffset, dstOffset, TIMEZONE_ERROR_CODE(to)); INTL_METHOD_CHECK_STATUS(to, "intltz_get_offset: error obtaining offset"); ZVAL_DEREF(rawOffsetArg); zval_dtor(rawOffsetArg); ZVAL_LONG(rawOffsetArg, rawOffset); ZVAL_DEREF(dstOffsetArg); zval_dtor(dstOffsetArg); ZVAL_LONG(dstOffsetArg, dstOffset); RETURN_TRUE; }
/* {{{ */ static void collator_ctor(INTERNAL_FUNCTION_PARAMETERS) { const char* locale; size_t locale_len = 0; zval* object; Collator_object* co; intl_error_reset( NULL ); object = return_value; /* Parse parameters. */ if( zend_parse_parameters( ZEND_NUM_ARGS(), "s", &locale, &locale_len ) == FAILURE ) { intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, "collator_create: unable to parse input params", 0 ); zval_dtor(return_value); RETURN_NULL(); } INTL_CHECK_LOCALE_LEN_OBJ(locale_len, return_value); COLLATOR_METHOD_FETCH_OBJECT; if(locale_len == 0) { locale = intl_locale_get_default(); } /* Open ICU collator. */ co->ucoll = ucol_open( locale, COLLATOR_ERROR_CODE_P( co ) ); INTL_CTOR_CHECK_STATUS(co, "collator_create: unable to open ICU collator"); }
U_CFUNC PHP_FUNCTION(intltz_get_id) { TIMEZONE_METHOD_INIT_VARS; if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &object, TimeZone_ce_ptr) == FAILURE) { intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, "intltz_get_id: bad arguments", 0 TSRMLS_CC); RETURN_FALSE; } TIMEZONE_METHOD_FETCH_OBJECT; UnicodeString id_us; to->utimezone->getID(id_us); char *id = NULL; int id_len = 0; intl_convert_utf16_to_utf8(&id, &id_len, id_us.getBuffer(), id_us.length(), TIMEZONE_ERROR_CODE_P(to)); INTL_METHOD_CHECK_STATUS(to, "intltz_get_id: Could not convert id to UTF-8"); RETURN_STRINGL(id, id_len, 0); }
/* {{{ */ static void msgfmt_ctor(INTERNAL_FUNCTION_PARAMETERS) { char* locale; char* pattern; int locale_len = 0, pattern_len = 0; UChar* spattern = NULL; int spattern_len = 0; zval* object; MessageFormatter_object* mfo; intl_error_reset( NULL TSRMLS_CC ); object = return_value; /* Parse parameters. */ if( zend_parse_parameters( ZEND_NUM_ARGS() TSRMLS_CC, "ss", &locale, &locale_len, &pattern, &pattern_len ) == FAILURE ) { intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, "msgfmt_create: unable to parse input parameters", 0 TSRMLS_CC ); zval_dtor(return_value); RETURN_NULL(); } INTL_CHECK_LOCALE_LEN_OBJ(locale_len, return_value); MSG_FORMAT_METHOD_FETCH_OBJECT; /* Convert pattern (if specified) to UTF-16. */ if(pattern && pattern_len) { intl_convert_utf8_to_utf16(&spattern, &spattern_len, pattern, pattern_len, &INTL_DATA_ERROR_CODE(mfo)); INTL_CTOR_CHECK_STATUS(mfo, "msgfmt_create: error converting pattern to UTF-16"); } else { spattern_len = 0; spattern = NULL; } if(locale_len == 0) { locale = INTL_G(default_locale); } #ifdef MSG_FORMAT_QUOTE_APOS if(msgformat_fix_quotes(&spattern, &spattern_len, &INTL_DATA_ERROR_CODE(mfo)) != SUCCESS) { INTL_CTOR_CHECK_STATUS(mfo, "msgfmt_create: error converting pattern to quote-friendly format"); } #endif if ((mfo)->mf_data.orig_format) { msgformat_data_free(&mfo->mf_data TSRMLS_CC); } (mfo)->mf_data.orig_format = estrndup(pattern, pattern_len); (mfo)->mf_data.orig_format_len = pattern_len; /* Create an ICU message formatter. */ MSG_FORMAT_OBJECT(mfo) = umsg_open(spattern, spattern_len, locale, NULL, &INTL_DATA_ERROR_CODE(mfo)); if(spattern) { efree(spattern); } INTL_CTOR_CHECK_STATUS(mfo, "msgfmt_create: message formatter creation failed"); }
U_CFUNC PHP_FUNCTION(rbbi_get_rules) { BREAKITER_METHOD_INIT_VARS; object = getThis(); if (zend_parse_parameters_none() == FAILURE) { intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, "rbbi_get_rules: bad arguments", 0); RETURN_FALSE; } BREAKITER_METHOD_FETCH_OBJECT; char *str; int str_len; const UnicodeString rules = fetch_rbbi(bio)->getRules(); if (intl_charFromString(rules, &str, &str_len, BREAKITER_ERROR_CODE_P(bio)) == FAILURE) { intl_errors_set(BREAKITER_ERROR_P(bio), BREAKITER_ERROR_CODE(bio), "rbbi_hash_code: Error converting result to UTF-8 string", 0); RETURN_FALSE; } RETVAL_STRINGL(str, str_len); //??? efree(str); }
U_CFUNC PHP_FUNCTION(rbbi_get_rules) { BREAKITER_METHOD_INIT_VARS; object = getThis(); if (zend_parse_parameters_none() == FAILURE) { intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, "rbbi_get_rules: bad arguments", 0 TSRMLS_CC); RETURN_FALSE; } BREAKITER_METHOD_FETCH_OBJECT; const UnicodeString rules = fetch_rbbi(bio)->getRules(); Z_TYPE_P(return_value) = IS_STRING; if (intl_charFromString(rules, &Z_STRVAL_P(return_value), &Z_STRLEN_P(return_value), BREAKITER_ERROR_CODE_P(bio)) == FAILURE) { intl_errors_set(BREAKITER_ERROR_P(bio), BREAKITER_ERROR_CODE(bio), "rbbi_hash_code: Error converting result to UTF-8 string", 0 TSRMLS_CC); RETURN_FALSE; } }
U_CFUNC PHP_FUNCTION(rbbi_get_binary_rules) { BREAKITER_METHOD_INIT_VARS; object = getThis(); if (zend_parse_parameters_none() == FAILURE) { intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, "rbbi_get_binary_rules: bad arguments", 0 TSRMLS_CC); RETURN_FALSE; } BREAKITER_METHOD_FETCH_OBJECT; uint32_t rules_len; const uint8_t *rules = fetch_rbbi(bio)->getBinaryRules(rules_len); if (rules_len > INT_MAX - 1) { intl_errors_set(BREAKITER_ERROR_P(bio), BREAKITER_ERROR_CODE(bio), "rbbi_get_binary_rules: the rules are too large", 0 TSRMLS_CC); RETURN_FALSE; } char *ret_rules = static_cast<char*>(emalloc(rules_len + 1)); memcpy(ret_rules, rules, rules_len); ret_rules[rules_len] = '\0'; RETURN_STRINGL(ret_rules, rules_len, 0); }
/* {{{ proto IntlCalendar datefmt_get_calendar_object(IntlDateFormatter $mf) * Get formatter calendar. */ U_CFUNC PHP_FUNCTION(datefmt_get_calendar_object) { DATE_FORMAT_METHOD_INIT_VARS; if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &object, IntlDateFormatter_ce_ptr ) == FAILURE) { intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, "datefmt_get_calendar_object: unable to parse input params", 0 TSRMLS_CC); RETURN_FALSE; } DATE_FORMAT_METHOD_FETCH_OBJECT; const Calendar *cal = fetch_datefmt(dfo)->getCalendar(); if (cal == NULL) { RETURN_NULL(); } Calendar *cal_clone = cal->clone(); if (cal_clone == NULL) { intl_errors_set(INTL_DATA_ERROR_P(dfo), U_MEMORY_ALLOCATION_ERROR, "datefmt_get_calendar_object: Out of memory when cloning " "calendar", 0 TSRMLS_CC); RETURN_FALSE; } calendar_object_create(return_value, cal_clone TSRMLS_CC); }
static void _php_intlcal_before_after( UBool (Calendar::*func)(const Calendar&, UErrorCode&) const, INTERNAL_FUNCTION_PARAMETERS) { zval *when_object; Calendar_object *when_co; CALENDAR_METHOD_INIT_VARS; if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "OO", &object, Calendar_ce_ptr, &when_object, Calendar_ce_ptr) == FAILURE) { intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, "intlcal_before/after: bad arguments", 0 TSRMLS_CC); RETURN_FALSE; } CALENDAR_METHOD_FETCH_OBJECT; when_co = Z_INTL_CALENDAR_P(when_object); if (when_co->ucal == NULL) { intl_errors_set(&co->err, U_ILLEGAL_ARGUMENT_ERROR, "intlcal_before/after: Other IntlCalendar was unconstructed", 0 TSRMLS_CC); RETURN_FALSE; } UBool res = (co->ucal->*func)(*when_co->ucal, CALENDAR_ERROR_CODE(co)); INTL_METHOD_CHECK_STATUS(co, "intlcal_before/after: Error calling ICU method"); RETURN_BOOL((int)res); }
/* {{{ */ static void collator_ctor(INTERNAL_FUNCTION_PARAMETERS) { char* locale; int locale_len = 0; zval* object; Collator_object* co; intl_error_reset( NULL TSRMLS_CC ); object = return_value; /* Parse parameters. */ if( zend_parse_parameters( ZEND_NUM_ARGS() TSRMLS_CC, "s", &locale, &locale_len ) == FAILURE ) { intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, "collator_create: unable to parse input params", 0 TSRMLS_CC ); zval_dtor(return_value); RETURN_NULL(); } INTL_CHECK_LOCALE_LEN_OBJ(locale_len, return_value); co = (Collator_object *) zend_object_store_get_object( object TSRMLS_CC ); intl_error_reset( COLLATOR_ERROR_P( co ) TSRMLS_CC ); if(locale_len == 0) { locale = UG(default_locale); } /* Open ICU collator. */ co->ucoll = ucol_open( locale, COLLATOR_ERROR_CODE_P( co ) ); INTL_CTOR_CHECK_STATUS(co, "collator_create: unable to open ICU collator"); }
/* {{{ proto IntlTimeZone datefmt_get_timezone(IntlDateFormatter $mf) * Get formatter timezone. */ U_CFUNC PHP_FUNCTION(datefmt_get_timezone) { DATE_FORMAT_METHOD_INIT_VARS; if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &object, IntlDateFormatter_ce_ptr ) == FAILURE) { intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, "datefmt_get_timezone: unable to parse input params", 0 TSRMLS_CC ); RETURN_FALSE; } DATE_FORMAT_METHOD_FETCH_OBJECT; const TimeZone& tz = fetch_datefmt(dfo)->getTimeZone(); TimeZone *tz_clone = tz.clone(); if (tz_clone == NULL) { intl_errors_set(INTL_DATA_ERROR_P(dfo), U_MEMORY_ALLOCATION_ERROR, "datefmt_get_timezone: Out of memory when cloning time zone", 0 TSRMLS_CC); RETURN_FALSE; } object_init_ex(return_value, TimeZone_ce_ptr); timezone_object_construct(tz_clone, return_value, 1 TSRMLS_CC); }
U_CFUNC PHP_FUNCTION(intlcal_is_weekend) { double date; zval *rawDate = NULL; CALENDAR_METHOD_INIT_VARS; if (zend_parse_method_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O|z!", &object, Calendar_ce_ptr, &rawDate) == FAILURE || (rawDate != NULL && zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O|d", &object, Calendar_ce_ptr, &date) == FAILURE)) { intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, "intlcal_is_weekend: bad arguments", 0 TSRMLS_CC); RETURN_FALSE; } CALENDAR_METHOD_FETCH_OBJECT; if (rawDate == NULL) { RETURN_BOOL((int)co->ucal->isWeekend()); } else { UBool ret = co->ucal->isWeekend((UDate)date, CALENDAR_ERROR_CODE(co)); INTL_METHOD_CHECK_STATUS(co, "intlcal_is_weekend: " "Error calling ICU method"); RETURN_BOOL((int)ret); } }
U_CFUNC PHP_FUNCTION(intltz_get_display_name) { zend_bool daylight = 0; zend_long display_type = TimeZone::LONG; const char *locale_str = NULL; size_t dummy = 0; TIMEZONE_METHOD_INIT_VARS; if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O|bls!", &object, TimeZone_ce_ptr, &daylight, &display_type, &locale_str, &dummy) == FAILURE) { intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, "intltz_get_display_name: bad arguments", 0); RETURN_FALSE; } bool found = false; for (int i = 0; !found && i < sizeof(display_types)/sizeof(*display_types); i++) { if (display_types[i] == display_type) found = true; } if (!found) { intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, "intltz_get_display_name: wrong display type", 0); RETURN_FALSE; } if (!locale_str) { locale_str = intl_locale_get_default(); } TIMEZONE_METHOD_FETCH_OBJECT; UnicodeString result; to->utimezone->getDisplayName((UBool)daylight, (TimeZone::EDisplayType)display_type, Locale::createFromName(locale_str), result); char *str; int str_len; intl_convert_utf16_to_utf8(&str, &str_len, result.getBuffer(), result.length(), TIMEZONE_ERROR_CODE_P(to)); INTL_METHOD_CHECK_STATUS(to, "intltz_get_display_name: " "could not convert resulting time zone id to UTF-16"); RETVAL_STRINGL(str, str_len); //???? efree(str); }
static void php_intl_idn_to(INTERNAL_FUNCTION_PARAMETERS, const char *domain, int32_t domain_len, uint32_t option, int mode) { UChar* ustring = NULL; int ustring_len = 0; UErrorCode status; char *converted_utf8; size_t converted_utf8_len; UChar converted[MAXPATHLEN]; int32_t converted_ret_len; /* convert the string to UTF-16. */ status = U_ZERO_ERROR; intl_convert_utf8_to_utf16(&ustring, &ustring_len, domain, domain_len, &status); if (U_FAILURE(status)) { intl_error_set_code(NULL, status); /* Set error messages. */ intl_error_set_custom_msg( NULL, "Error converting input string to UTF-16", 0 ); if (ustring) { efree(ustring); } RETURN_FALSE; } else { UParseError parse_error; status = U_ZERO_ERROR; if (mode == INTL_IDN_TO_ASCII) { converted_ret_len = uidna_IDNToASCII(ustring, ustring_len, converted, MAXPATHLEN, (int32_t)option, &parse_error, &status); } else { converted_ret_len = uidna_IDNToUnicode(ustring, ustring_len, converted, MAXPATHLEN, (int32_t)option, &parse_error, &status); } efree(ustring); if (U_FAILURE(status)) { intl_error_set( NULL, status, "idn_to_ascii: cannot convert to ASCII", 0 ); RETURN_FALSE; } status = U_ZERO_ERROR; intl_convert_utf16_to_utf8(&converted_utf8, &converted_utf8_len, converted, converted_ret_len, &status); if (U_FAILURE(status)) { /* Set global error code. */ intl_error_set_code(NULL, status); /* Set error messages. */ intl_error_set_custom_msg( NULL, "Error converting output string to UTF-8", 0 ); efree(converted_utf8); RETURN_FALSE; } } /* return the allocated string, not a duplicate */ RETVAL_STRINGL(converted_utf8, converted_utf8_len); //???? efree(converted_utf8); }