diff options
Diffstat (limited to 'ext/intl/common')
-rw-r--r-- | ext/intl/common/common_date.cpp | 250 | ||||
-rw-r--r-- | ext/intl/common/common_date.h | 40 | ||||
-rw-r--r-- | ext/intl/common/common_enum.cpp | 342 | ||||
-rw-r--r-- | ext/intl/common/common_enum.h | 77 | ||||
-rw-r--r-- | ext/intl/common/common_error.c | 2 |
5 files changed, 709 insertions, 2 deletions
diff --git a/ext/intl/common/common_date.cpp b/ext/intl/common/common_date.cpp new file mode 100644 index 0000000000..ee998818d9 --- /dev/null +++ b/ext/intl/common/common_date.cpp @@ -0,0 +1,250 @@ +/* + +----------------------------------------------------------------------+ + | PHP Version 5 | + +----------------------------------------------------------------------+ + | This source file is subject to version 3.01 of the PHP license, | + | that is bundled with this package in the file LICENSE, and is | + | available through the world-wide-web at the following url: | + | http://www.php.net/license/3_01.txt | + | If you did not receive a copy of the PHP license and are unable to | + | obtain it through the world-wide-web, please send a note to | + | license@php.net so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + | Authors: Gustavo Lopes <cataphract@php.net> | + +----------------------------------------------------------------------+ +*/ + +#include "../intl_cppshims.h" + +#include <unicode/calendar.h> + +extern "C" { +#include "../php_intl.h" +#define USE_CALENDAR_POINTER 1 +#include "../calendar/calendar_class.h" +#include <ext/date/php_date.h> +} + +#ifndef INFINITY +#define INFINITY (DBL_MAX+DBL_MAX) +#endif + +#ifndef NAN +#define NAN (INFINITY-INFINITY) +#endif + +/* {{{ timezone_convert_datetimezone + * The timezone in DateTime and DateTimeZone is not unified. */ +U_CFUNC TimeZone *timezone_convert_datetimezone(int type, + void *object, + int is_datetime, + intl_error *outside_error, + const char *func TSRMLS_DC) +{ + char *id = NULL, + offset_id[] = "GMT+00:00"; + int id_len = 0; + char *message; + TimeZone *timeZone; + + switch (type) { + case TIMELIB_ZONETYPE_ID: + id = is_datetime + ? ((php_date_obj*)object)->time->tz_info->name + : ((php_timezone_obj*)object)->tzi.tz->name; + id_len = strlen(id); + break; + case TIMELIB_ZONETYPE_OFFSET: { + int offset_mins = is_datetime + ? -((php_date_obj*)object)->time->z + : -(int)((php_timezone_obj*)object)->tzi.utc_offset, + hours = offset_mins / 60, + minutes = offset_mins - hours * 60; + minutes *= minutes > 0 ? 1 : -1; + + if (offset_mins <= -24 * 60 || offset_mins >= 24 * 60) { + spprintf(&message, 0, "%s: object has an time zone offset " + "that's too large", func); + intl_errors_set(outside_error, U_ILLEGAL_ARGUMENT_ERROR, + message, 1 TSRMLS_CC); + efree(message); + return NULL; + } + + id = offset_id; + id_len = slprintf(id, sizeof(offset_id), "GMT%+03d:%02d", + hours, minutes); + break; + } + case TIMELIB_ZONETYPE_ABBR: + id = is_datetime + ? ((php_date_obj*)object)->time->tz_abbr + : ((php_timezone_obj*)object)->tzi.z.abbr; + id_len = strlen(id); + break; + } + + UnicodeString s = UnicodeString(id, id_len, US_INV); + timeZone = TimeZone::createTimeZone(s); +#if U_ICU_VERSION_MAJOR_NUM >= 49 + if (*timeZone == TimeZone::getUnknown()) { +#else + UnicodeString resultingId; + timeZone->getID(resultingId); + if (resultingId == UnicodeString("Etc/Unknown", -1, US_INV) + || resultingId == UnicodeString("GMT", -1, US_INV)) { +#endif + spprintf(&message, 0, "%s: time zone id '%s' " + "extracted from ext/date DateTimeZone not recognized", func, id); + intl_errors_set(outside_error, U_ILLEGAL_ARGUMENT_ERROR, + message, 1 TSRMLS_CC); + efree(message); + delete timeZone; + return NULL; + } + return timeZone; +} +/* }}} */ + +U_CFUNC int intl_datetime_decompose(zval *z, double *millis, TimeZone **tz, + intl_error *err, const char *func TSRMLS_DC) +{ + zval retval; + zval *zfuncname; + char *message; + + if (err && U_FAILURE(err->code)) { + return FAILURE; + } + + if (millis) { + *millis = NAN; + } + if (tz) { + *tz = NULL; + } + + if (millis) { + INIT_ZVAL(retval); + MAKE_STD_ZVAL(zfuncname); + ZVAL_STRING(zfuncname, "getTimestamp", 1); + if (call_user_function(NULL, &(z), zfuncname, &retval, 0, NULL TSRMLS_CC) + != SUCCESS || Z_TYPE(retval) != IS_LONG) { + spprintf(&message, 0, "%s: error calling ::getTimeStamp() on the " + "object", func); + intl_errors_set(err, U_INTERNAL_PROGRAM_ERROR, + message, 1 TSRMLS_CC); + efree(message); + zval_ptr_dtor(&zfuncname); + return FAILURE; + } + + *millis = U_MILLIS_PER_SECOND * (double)Z_LVAL(retval); + zval_ptr_dtor(&zfuncname); + } + + if (tz) { + php_date_obj *datetime; + datetime = (php_date_obj*)zend_object_store_get_object(z TSRMLS_CC); + if (!datetime->time) { + spprintf(&message, 0, "%s: the DateTime object is not properly " + "initialized", func); + intl_errors_set(err, U_ILLEGAL_ARGUMENT_ERROR, + message, 1 TSRMLS_CC); + efree(message); + return FAILURE; + } + if (!datetime->time->is_localtime) { + *tz = TimeZone::getGMT()->clone(); + } else { + *tz = timezone_convert_datetimezone(datetime->time->zone_type, + datetime, 1, NULL, func TSRMLS_CC); + if (*tz == NULL) { + spprintf(&message, 0, "%s: could not convert DateTime's " + "time zone", func); + intl_errors_set(err, U_ILLEGAL_ARGUMENT_ERROR, + message, 1 TSRMLS_CC); + efree(message); + return FAILURE; + } + } + } + + return SUCCESS; +} + +U_CFUNC double intl_zval_to_millis(zval *z, intl_error *err, const char *func TSRMLS_DC) +{ + double rv = NAN; + long lv; + int type; + char *message; + + if (err && U_FAILURE(err->code)) { + return NAN; + } + + switch (Z_TYPE_P(z)) { + case IS_STRING: + type = is_numeric_string(Z_STRVAL_P(z), Z_STRLEN_P(z), &lv, &rv, 0); + if (type == IS_DOUBLE) { + rv *= U_MILLIS_PER_SECOND; + } else if (type == IS_LONG) { + rv = U_MILLIS_PER_SECOND * (double)lv; + } else { + spprintf(&message, 0, "%s: string '%s' is not numeric, " + "which would be required for it to be a valid date", func, + Z_STRVAL_P(z)); + intl_errors_set(err, U_ILLEGAL_ARGUMENT_ERROR, + message, 1 TSRMLS_CC); + efree(message); + } + break; + case IS_LONG: + rv = U_MILLIS_PER_SECOND * (double)Z_LVAL_P(z); + break; + case IS_DOUBLE: + rv = U_MILLIS_PER_SECOND * Z_DVAL_P(z); + break; + case IS_OBJECT: + if (instanceof_function(Z_OBJCE_P(z), php_date_get_date_ce() TSRMLS_CC)) { + intl_datetime_decompose(z, &rv, NULL, err, func TSRMLS_CC); + } else if (instanceof_function(Z_OBJCE_P(z), Calendar_ce_ptr TSRMLS_CC)) { + Calendar_object *co = (Calendar_object *) + zend_object_store_get_object(z TSRMLS_CC ); + if (co->ucal == NULL) { + spprintf(&message, 0, "%s: IntlCalendar object is not properly " + "constructed", func); + intl_errors_set(err, U_ILLEGAL_ARGUMENT_ERROR, + message, 1 TSRMLS_CC); + efree(message); + } else { + UErrorCode status = UErrorCode(); + rv = (double)co->ucal->getTime(status); + if (U_FAILURE(status)) { + spprintf(&message, 0, "%s: call to internal " + "Calendar::getTime() has failed", func); + intl_errors_set(err, status, message, 1 TSRMLS_CC); + efree(message); + } + } + } else { + /* TODO: try with cast(), get() to obtain a number */ + spprintf(&message, 0, "%s: invalid object type for date/time " + "(only IntlCalendar and DateTime permitted)", func); + intl_errors_set(err, U_ILLEGAL_ARGUMENT_ERROR, + message, 1 TSRMLS_CC); + efree(message); + } + break; + default: + spprintf(&message, 0, "%s: invalid PHP type for date", func); + intl_errors_set(err, U_ILLEGAL_ARGUMENT_ERROR, + message, 1 TSRMLS_CC); + efree(message); + break; + } + + return rv; +} + diff --git a/ext/intl/common/common_date.h b/ext/intl/common/common_date.h new file mode 100644 index 0000000000..d2396cbf5a --- /dev/null +++ b/ext/intl/common/common_date.h @@ -0,0 +1,40 @@ +/* + +----------------------------------------------------------------------+ + | PHP Version 5 | + +----------------------------------------------------------------------+ + | This source file is subject to version 3.01 of the PHP license, | + | that is bundled with this package in the file LICENSE, and is | + | available through the world-wide-web at the following url: | + | http://www.php.net/license/3_01.txt | + | If you did not receive a copy of the PHP license and are unable to | + | obtain it through the world-wide-web, please send a note to | + | license@php.net so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + | Authors: Gustavo Lopes <cataphract@php.net> | + +----------------------------------------------------------------------+ +*/ + +#ifndef COMMON_DATE_H +#define COMMON_DATE_H + +#include <unicode/umachine.h> + +U_CDECL_BEGIN +#include <php.h> +#include "../intl_error.h" +U_CDECL_END + +#ifdef __cplusplus + +#include <unicode/timezone.h> + +U_CFUNC TimeZone *timezone_convert_datetimezone(int type, void *object, int is_datetime, intl_error *outside_error, const char *func TSRMLS_DC); +U_CFUNC int intl_datetime_decompose(zval *z, double *millis, TimeZone **tz, + intl_error *err, const char *func TSRMLS_DC); + +#endif + +U_CFUNC double intl_zval_to_millis(zval *z, intl_error *err, const char *func TSRMLS_DC); + +#endif /* COMMON_DATE_H */ + diff --git a/ext/intl/common/common_enum.cpp b/ext/intl/common/common_enum.cpp new file mode 100644 index 0000000000..3ba7855827 --- /dev/null +++ b/ext/intl/common/common_enum.cpp @@ -0,0 +1,342 @@ +/* + +----------------------------------------------------------------------+ + | PHP Version 5 | + +----------------------------------------------------------------------+ + | This source file is subject to version 3.01 of the PHP license, | + | that is bundled with this package in the file LICENSE, and is | + | available through the world-wide-web at the following url: | + | http://www.php.net/license/3_01.txt | + | If you did not receive a copy of the PHP license and are unable to | + | obtain it through the world-wide-web, please send a note to | + | license@php.net so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + | Authors: Gustavo Lopes <cataphract@php.net> | + +----------------------------------------------------------------------+ +*/ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "../intl_cppshims.h" + +// Fix build on Windows/old versions of ICU +#include <stdio.h> + +#include "common_enum.h" + +extern "C" { +#include <zend_interfaces.h> +#include <zend_exceptions.h> +} + +zend_class_entry *IntlIterator_ce_ptr; +zend_object_handlers IntlIterator_handlers; + +void zoi_with_current_dtor(zend_object_iterator *iter TSRMLS_DC) +{ + zoi_with_current *zoiwc = (zoi_with_current*)iter; + + if (zoiwc->wrapping_obj) { + /* we have to copy the pointer because zoiwc->wrapping_obj may be + * changed midway the execution of zval_ptr_dtor() */ + zval *zwo = zoiwc->wrapping_obj; + + /* object is still here, we can rely on it to call this again and + * destroy this object */ + zval_ptr_dtor(&zwo); + } else { + /* Object not here anymore (we've been called by the object free handler) + * Note that the iterator wrapper objects (that also depend on this + * structure) call this function earlier, in the destruction phase, which + * precedes the object free phase. Therefore there's no risk on this + * function being called by the iterator wrapper destructor function and + * not finding the memory of this iterator allocated anymore. */ + iter->funcs->invalidate_current(iter TSRMLS_CC); + zoiwc->destroy_it(iter TSRMLS_CC); + efree(iter); + } +} + +U_CFUNC int zoi_with_current_valid(zend_object_iterator *iter TSRMLS_DC) +{ + return ((zoi_with_current*)iter)->current != NULL ? SUCCESS : FAILURE; +} + +U_CFUNC void zoi_with_current_get_current_data(zend_object_iterator *iter, zval ***data TSRMLS_DC) +{ + *data = &((zoi_with_current*)iter)->current; +} + +U_CFUNC void zoi_with_current_invalidate_current(zend_object_iterator *iter TSRMLS_DC) +{ + zoi_with_current *zoi_iter = (zoi_with_current*)iter; + if (zoi_iter->current) { + zval_ptr_dtor(&zoi_iter->current); + zoi_iter->current = NULL; //valid would return FAILURE now + } +} + +static void string_enum_current_move_forward(zend_object_iterator *iter TSRMLS_DC) +{ + zoi_with_current *zoi_iter = (zoi_with_current*)iter; + INTLITERATOR_METHOD_INIT_VARS; + + iter->funcs->invalidate_current(iter TSRMLS_CC); + + object = zoi_iter->wrapping_obj; + INTLITERATOR_METHOD_FETCH_OBJECT_NO_CHECK; + + int32_t result_length; + const char *result = ((StringEnumeration*)iter->data)->next( + &result_length, INTLITERATOR_ERROR_CODE(ii)); + + intl_error_set_code(NULL, INTLITERATOR_ERROR_CODE(ii) TSRMLS_CC); + if (U_FAILURE(INTLITERATOR_ERROR_CODE(ii))) { + intl_errors_set_custom_msg(INTL_DATA_ERROR_P(ii), + "Error fetching next iteration element", 0 TSRMLS_CC); + } else if (result) { + MAKE_STD_ZVAL(zoi_iter->current); + ZVAL_STRINGL(zoi_iter->current, result, result_length, 1); + } //else we've reached the end of the enum, nothing more is required +} + +static void string_enum_rewind(zend_object_iterator *iter TSRMLS_DC) +{ + zoi_with_current *zoi_iter = (zoi_with_current*)iter; + INTLITERATOR_METHOD_INIT_VARS; + + if (zoi_iter->current) { + iter->funcs->invalidate_current(iter TSRMLS_CC); + } + + object = zoi_iter->wrapping_obj; + INTLITERATOR_METHOD_FETCH_OBJECT_NO_CHECK; + + ((StringEnumeration*)iter->data)->reset(INTLITERATOR_ERROR_CODE(ii)); + + intl_error_set_code(NULL, INTLITERATOR_ERROR_CODE(ii) TSRMLS_CC); + if (U_FAILURE(INTLITERATOR_ERROR_CODE(ii))) { + intl_errors_set_custom_msg(INTL_DATA_ERROR_P(ii), + "Error resetting enumeration", 0 TSRMLS_CC); + } else { + iter->funcs->move_forward(iter TSRMLS_CC); + } +} + +static void string_enum_destroy_it(zend_object_iterator *iter TSRMLS_DC) +{ + delete (StringEnumeration*)iter->data; +} + +static zend_object_iterator_funcs string_enum_object_iterator_funcs = { + zoi_with_current_dtor, + zoi_with_current_valid, + zoi_with_current_get_current_data, + NULL, + string_enum_current_move_forward, + string_enum_rewind, + zoi_with_current_invalidate_current +}; + +U_CFUNC void IntlIterator_from_StringEnumeration(StringEnumeration *se, zval *object TSRMLS_DC) +{ + IntlIterator_object *ii; + object_init_ex(object, IntlIterator_ce_ptr); + ii = (IntlIterator_object*)zend_object_store_get_object(object TSRMLS_CC); + ii->iterator = (zend_object_iterator*)emalloc(sizeof(zoi_with_current)); + ii->iterator->data = (void*)se; + ii->iterator->funcs = &string_enum_object_iterator_funcs; + ii->iterator->index = 0; + ((zoi_with_current*)ii->iterator)->destroy_it = string_enum_destroy_it; + ((zoi_with_current*)ii->iterator)->wrapping_obj = object; + ((zoi_with_current*)ii->iterator)->current = NULL; +} + +static void IntlIterator_objects_free(zend_object *object TSRMLS_DC) +{ + IntlIterator_object *ii = (IntlIterator_object*) object; + + if (ii->iterator) { + zval **wrapping_objp = &((zoi_with_current*)ii->iterator)->wrapping_obj; + *wrapping_objp = NULL; + ii->iterator->funcs->dtor(ii->iterator TSRMLS_CC); + } + intl_error_reset(INTLITERATOR_ERROR_P(ii) TSRMLS_CC); + + zend_object_std_dtor(&ii->zo TSRMLS_CC); + + efree(ii); +} + +static zend_object_iterator *IntlIterator_get_iterator( + zend_class_entry *ce, zval *object, int by_ref TSRMLS_DC) +{ + if (by_ref) { + zend_throw_exception(NULL, + "Iteration by reference is not supported", 0 TSRMLS_CC); + return NULL; + } + + IntlIterator_object *ii = (IntlIterator_object*) + zend_object_store_get_object(object TSRMLS_CC); + + if (ii->iterator == NULL) { + zend_throw_exception(NULL, + "The IntlIterator is not properly constructed", 0 TSRMLS_CC); + return NULL; + } + + zval_add_ref(&object); + + return ii->iterator; +} + +static zend_object_value IntlIterator_object_create(zend_class_entry *ce TSRMLS_DC) +{ + zend_object_value retval; + IntlIterator_object *intern; + + intern = (IntlIterator_object*)ecalloc(1, sizeof(IntlIterator_object)); + + zend_object_std_init(&intern->zo, ce TSRMLS_CC); +#if PHP_VERSION_ID < 50399 + zend_hash_copy(intern->zo.properties, &(ce->default_properties), + (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval*)); +#else + object_properties_init((zend_object*) intern, ce); +#endif + intl_error_init(INTLITERATOR_ERROR_P(intern) TSRMLS_CC); + intern->iterator = NULL; + + retval.handle = zend_objects_store_put( + intern, + (zend_objects_store_dtor_t)zend_objects_destroy_object, + (zend_objects_free_object_storage_t)IntlIterator_objects_free, + NULL TSRMLS_CC); + + retval.handlers = &IntlIterator_handlers; + + return retval; +} + +static PHP_METHOD(IntlIterator, current) +{ + zval **data; + INTLITERATOR_METHOD_INIT_VARS; + + if (zend_parse_parameters_none() == FAILURE) { + intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, + "IntlIterator::current: bad arguments", 0 TSRMLS_CC); + return; + } + + INTLITERATOR_METHOD_FETCH_OBJECT; + ii->iterator->funcs->get_current_data(ii->iterator, &data TSRMLS_CC); + if (data && *data) { + RETURN_ZVAL(*data, 1, 0); + } +} + +static PHP_METHOD(IntlIterator, key) +{ + INTLITERATOR_METHOD_INIT_VARS; + + if (zend_parse_parameters_none() == FAILURE) { + intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, + "IntlIterator::key: bad arguments", 0 TSRMLS_CC); + return; + } + + INTLITERATOR_METHOD_FETCH_OBJECT; + + if (ii->iterator->funcs->get_current_key) { + ii->iterator->funcs->get_current_key(ii->iterator, return_value TSRMLS_CC); + } else { + RETURN_LONG(ii->iterator->index); + } +} + +static PHP_METHOD(IntlIterator, next) +{ + INTLITERATOR_METHOD_INIT_VARS; + + if (zend_parse_parameters_none() == FAILURE) { + intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, + "IntlIterator::next: bad arguments", 0 TSRMLS_CC); + return; + } + + INTLITERATOR_METHOD_FETCH_OBJECT; + ii->iterator->funcs->move_forward(ii->iterator TSRMLS_CC); + /* foreach also advances the index after the last iteration, + * so I see no problem in incrementing the index here unconditionally */ + ii->iterator->index++; +} + +static PHP_METHOD(IntlIterator, rewind) +{ + INTLITERATOR_METHOD_INIT_VARS; + + if (zend_parse_parameters_none() == FAILURE) { + intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, + "IntlIterator::rewind: bad arguments", 0 TSRMLS_CC); + return; + } + + INTLITERATOR_METHOD_FETCH_OBJECT; + if (ii->iterator->funcs->rewind) { + ii->iterator->funcs->rewind(ii->iterator TSRMLS_CC); + } else { + intl_errors_set(INTLITERATOR_ERROR_P(ii), U_UNSUPPORTED_ERROR, + "IntlIterator::rewind: rewind not supported", 0 TSRMLS_CC); + } +} + +static PHP_METHOD(IntlIterator, valid) +{ + INTLITERATOR_METHOD_INIT_VARS; + + if (zend_parse_parameters_none() == FAILURE) { + intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, + "IntlIterator::valid: bad arguments", 0 TSRMLS_CC); + return; + } + + INTLITERATOR_METHOD_FETCH_OBJECT; + RETURN_BOOL(ii->iterator->funcs->valid(ii->iterator TSRMLS_CC) == SUCCESS); +} + +ZEND_BEGIN_ARG_INFO_EX(ainfo_se_void, 0, 0, 0) +ZEND_END_ARG_INFO() + +static zend_function_entry IntlIterator_class_functions[] = { + PHP_ME(IntlIterator, current, ainfo_se_void, ZEND_ACC_PUBLIC) + PHP_ME(IntlIterator, key, ainfo_se_void, ZEND_ACC_PUBLIC) + PHP_ME(IntlIterator, next, ainfo_se_void, ZEND_ACC_PUBLIC) + PHP_ME(IntlIterator, rewind, ainfo_se_void, ZEND_ACC_PUBLIC) + PHP_ME(IntlIterator, valid, ainfo_se_void, ZEND_ACC_PUBLIC) + PHP_FE_END +}; + + +/* {{{ intl_register_IntlIterator_class + * Initialize 'IntlIterator' class + */ +U_CFUNC void intl_register_IntlIterator_class(TSRMLS_D) +{ + zend_class_entry ce; + + /* Create and register 'IntlIterator' class. */ + INIT_CLASS_ENTRY(ce, "IntlIterator", IntlIterator_class_functions); + ce.create_object = IntlIterator_object_create; + IntlIterator_ce_ptr = zend_register_internal_class(&ce TSRMLS_CC); + IntlIterator_ce_ptr->get_iterator = IntlIterator_get_iterator; + zend_class_implements(IntlIterator_ce_ptr TSRMLS_CC, 1, + zend_ce_iterator); + + memcpy(&IntlIterator_handlers, zend_get_std_object_handlers(), + sizeof IntlIterator_handlers); + IntlIterator_handlers.clone_obj = NULL; + +} diff --git a/ext/intl/common/common_enum.h b/ext/intl/common/common_enum.h new file mode 100644 index 0000000000..4c6abdb8f5 --- /dev/null +++ b/ext/intl/common/common_enum.h @@ -0,0 +1,77 @@ +/* + +----------------------------------------------------------------------+ + | PHP Version 5 | + +----------------------------------------------------------------------+ + | This source file is subject to version 3.01 of the PHP license, | + | that is bundled with this package in the file LICENSE, and is | + | available through the world-wide-web at the following url: | + | http://www.php.net/license/3_01.txt | + | If you did not receive a copy of the PHP license and are unable to | + | obtain it through the world-wide-web, please send a note to | + | license@php.net so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + | Authors: Vadim Savchuk <vsavchuk@productengine.com> | + | Dmitry Lakhtyuk <dlakhtyuk@productengine.com> | + +----------------------------------------------------------------------+ + */ + +#ifndef INTL_COMMON_ENUM_H +#define INTL_COMMON_ENUM_H + +#include <unicode/umachine.h> +#ifdef __cplusplus +#include <unicode/strenum.h> +extern "C" { +#include <math.h> +#endif +#include <php.h> +#include "../intl_error.h" +#include "../intl_data.h" +#ifdef __cplusplus +} +#endif + +#define INTLITERATOR_ERROR(ii) (ii)->err +#define INTLITERATOR_ERROR_P(ii) &(INTLITERATOR_ERROR(ii)) + +#define INTLITERATOR_ERROR_CODE(ii) INTL_ERROR_CODE(INTLITERATOR_ERROR(ii)) +#define INTLITERATOR_ERROR_CODE_P(ii) &(INTL_ERROR_CODE(INTLITERATOR_ERROR(ii))) + +#define INTLITERATOR_METHOD_INIT_VARS INTL_METHOD_INIT_VARS(IntlIterator, ii) +#define INTLITERATOR_METHOD_FETCH_OBJECT_NO_CHECK INTL_METHOD_FETCH_OBJECT(IntlIterator, ii) +#define INTLITERATOR_METHOD_FETCH_OBJECT\ + object = getThis(); \ + INTLITERATOR_METHOD_FETCH_OBJECT_NO_CHECK; \ + if (ii->iterator == NULL) { \ + intl_errors_set(&ii->err, U_ILLEGAL_ARGUMENT_ERROR, "Found unconstructed IntlIterator", 0 TSRMLS_CC); \ + RETURN_FALSE; \ + } + +typedef struct { + zend_object zo; + intl_error err; + zend_object_iterator *iterator; +} IntlIterator_object; + +typedef struct { + zend_object_iterator zoi; + zval *current; + zval *wrapping_obj; + void (*destroy_it)(zend_object_iterator *iterator TSRMLS_DC); +} zoi_with_current; + +extern zend_class_entry *IntlIterator_ce_ptr; +extern zend_object_handlers IntlIterator_handlers; + +U_CFUNC void zoi_with_current_dtor(zend_object_iterator *iter TSRMLS_DC); +U_CFUNC int zoi_with_current_valid(zend_object_iterator *iter TSRMLS_DC); +U_CFUNC void zoi_with_current_get_current_data(zend_object_iterator *iter, zval ***data TSRMLS_DC); +U_CFUNC void zoi_with_current_invalidate_current(zend_object_iterator *iter TSRMLS_DC); + +#ifdef __cplusplus +U_CFUNC void IntlIterator_from_StringEnumeration(StringEnumeration *se, zval *object TSRMLS_DC); +#endif + +U_CFUNC void intl_register_IntlIterator_class(TSRMLS_D); + +#endif // INTL_COMMON_ENUM_H diff --git a/ext/intl/common/common_error.c b/ext/intl/common/common_error.c index 282172224c..a0ee7c145f 100644 --- a/ext/intl/common/common_error.c +++ b/ext/intl/common/common_error.c @@ -240,9 +240,7 @@ void intl_expose_icu_error_codes( INIT_FUNC_ARGS ) INTL_EXPOSE_CONST( U_IDNA_ACE_PREFIX_ERROR ); INTL_EXPOSE_CONST( U_IDNA_VERIFICATION_ERROR ); INTL_EXPOSE_CONST( U_IDNA_LABEL_TOO_LONG_ERROR ); -#if U_ICU_VERSION_MAJOR_NUM > 3 || U_ICU_VERSION_MAJOR_NUM == 3 && U_ICU_VERSION_MINOR_NUM >= 6 INTL_EXPOSE_CONST( U_IDNA_ZERO_LENGTH_LABEL_ERROR ); -#endif #if U_ICU_VERSION_MAJOR_NUM > 3 || U_ICU_VERSION_MAJOR_NUM == 3 && U_ICU_VERSION_MINOR_NUM >= 8 INTL_EXPOSE_CONST( U_IDNA_DOMAIN_NAME_TOO_LONG_ERROR ); #endif |