Пример #1
0
U_CFUNC PHP_FUNCTION(intltz_create_enumeration)
{
	zval				*arg = NULL;
	StringEnumeration	*se	  = NULL;
	intl_error_reset(NULL);

	/* double indirection to have the zend engine destroy the new zval that
	 * results from separation */
	if (zend_parse_parameters(ZEND_NUM_ARGS(), "|z", &arg) == FAILURE) {
		intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR,
			"intltz_create_enumeration: bad arguments", 0);
		RETURN_FALSE;
	}

	if (arg == NULL || Z_TYPE_P(arg) == IS_NULL) {
		se = TimeZone::createEnumeration();
	} else if (Z_TYPE_P(arg) == IS_LONG) {
int_offset:
		if (Z_LVAL_P(arg) < (zend_long)INT32_MIN ||
				Z_LVAL_P(arg) > (zend_long)INT32_MAX) {
			intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR,
				"intltz_create_enumeration: value is out of range", 0);
			RETURN_FALSE;
		} else {
			se = TimeZone::createEnumeration((int32_t) Z_LVAL_P(arg));
		}
	} else if (Z_TYPE_P(arg) == IS_DOUBLE) {
double_offset:
		convert_to_long_ex(arg);
		goto int_offset;
	} else if (Z_TYPE_P(arg) == IS_OBJECT || Z_TYPE_P(arg) == IS_STRING) {
		zend_long lval;
		double dval;
		convert_to_string_ex(arg);
		switch (is_numeric_string(Z_STRVAL_P(arg), Z_STRLEN_P(arg), &lval, &dval, 0)) {
		case IS_DOUBLE:
			zval_ptr_dtor(arg);
			ZVAL_DOUBLE(arg, dval);
			goto double_offset;
		case IS_LONG:
			zval_ptr_dtor(arg);
			ZVAL_LONG(arg, lval);
			goto int_offset;
		}
		/* else call string version */
		se = TimeZone::createEnumeration(Z_STRVAL_P(arg));
	} else {
		intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR,
			"intltz_create_enumeration: invalid argument type", 0);
		RETURN_FALSE;
	}

	if (se) {
		IntlIterator_from_StringEnumeration(se, return_value);
	} else {
		intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR,
			"intltz_create_enumeration: error obtaining enumeration", 0);
		RETVAL_FALSE;
	}
}
Пример #2
0
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, &region, &region_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);
}
Пример #3
0
U_CFUNC PHP_FUNCTION(intltz_create_time_zone_id_enumeration)
{
	zend_long zoneType,
			  offset_arg;
	char	 *region		= NULL;
	size_t	  region_len	= 0;
	int32_t	  offset,
			 *offsetp	= NULL;
	zend_bool arg3isnull = 1;

	intl_error_reset(NULL);

	if (zend_parse_parameters(ZEND_NUM_ARGS(), "l|s!l!",
			&zoneType, &region, &region_len, &offset_arg, &arg3isnull) == FAILURE) {
		intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR,
			"intltz_create_time_zone_id_enumeration: bad arguments", 0);
		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);
		RETURN_FALSE;
	}

	if (!arg3isnull) {
		if (offset_arg < (zend_long)INT32_MIN || offset_arg > (zend_long)INT32_MAX) {
			intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR,
				"intltz_create_time_zone_id_enumeration: offset out of bounds", 0);
			RETURN_FALSE;
		}
		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);
}
Пример #4
0
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);
}