From 0403ce45c6c2af905a009c7cb81b5786f1b42d92 Mon Sep 17 00:00:00 2001 From: Stanislav Malyshev Date: Tue, 22 Jul 2008 22:11:21 +0000 Subject: [PATCH] MFB: constructors fixes and cleanup --- ext/intl/collator/collator_class.h | 5 +- ext/intl/collator/collator_create.c | 79 ++--- ext/intl/dateformat/dateformat.c | 269 ++++-------------- ext/intl/dateformat/dateformat_attr.c | 72 ++--- ext/intl/dateformat/dateformat_class.c | 12 +- ext/intl/dateformat/dateformat_class.h | 6 +- ext/intl/dateformat/dateformat_format.c | 56 ++-- ext/intl/dateformat/dateformat_parse.c | 52 ++-- ext/intl/formatter/formatter_main.c | 79 ++--- ext/intl/intl_data.h | 10 + ext/intl/msgformat/msgformat.c | 107 ++----- ext/intl/msgformat/msgformat_attr.c | 2 +- ext/intl/msgformat/msgformat_data.c | 2 +- ext/intl/msgformat/msgformat_data.h | 2 +- ext/intl/msgformat/msgformat_format.c | 2 +- ext/intl/msgformat/msgformat_parse.c | 2 +- ext/intl/tests/collator_asort.phpt | 3 - ext/intl/tests/collator_sort.phpt | 3 - .../tests/collator_sort_with_sort_keys.phpt | 3 - ext/intl/tests/formatter_fail.phpt | 10 +- ext/intl/tests/grapheme.phpt | 94 +++--- ext/intl/tests/msgfmt_fail.phpt | 20 +- ext/intl/tests/normalizer_normalize.phpt | 2 + ext/intl/tests/ut_common.inc | 6 +- 24 files changed, 295 insertions(+), 603 deletions(-) diff --git a/ext/intl/collator/collator_class.h b/ext/intl/collator/collator_class.h index 8d4c9d97f4..835abd66c8 100755 --- a/ext/intl/collator/collator_class.h +++ b/ext/intl/collator/collator_class.h @@ -28,12 +28,11 @@ typedef struct { zend_object zo; - // ICU collator - UCollator* ucoll; - // error handling intl_error err; + // ICU collator + UCollator* ucoll; } Collator_object; #define COLLATOR_ERROR(co) (co)->err diff --git a/ext/intl/collator/collator_create.c b/ext/intl/collator/collator_create.c index ca0a7148be..89bbbca799 100755 --- a/ext/intl/collator/collator_create.c +++ b/ext/intl/collator/collator_create.c @@ -24,10 +24,8 @@ #include "collator_create.h" #include "intl_data.h" -/* {{{ proto Collator collator_create( string $locale ) - * Create collator. - */ -PHP_FUNCTION( collator_create ) +/* {{{ */ +static void collator_ctor(INTERNAL_FUNCTION_PARAMETERS) { char* locale; int locale_len = 0; @@ -35,25 +33,18 @@ PHP_FUNCTION( collator_create ) 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(locale_len); - // Create a Collator object and save the ICU collator into it. - if( ( object = getThis() ) == NULL ) - object = return_value; - - if( Z_TYPE_P( object ) != IS_OBJECT ) - object_init_ex( object, Collator_ce_ptr ); - + 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 ); @@ -64,15 +55,17 @@ PHP_FUNCTION( collator_create ) // 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"); +} +/* }}} */ - if( U_FAILURE( COLLATOR_ERROR_CODE( co ) ) || co->ucoll == NULL ) - { - intl_error_set( NULL, COLLATOR_ERROR_CODE( co ), - "collator_create: unable to open ICU collator", 0 TSRMLS_CC ); - - // Collator creation failed. - RETURN_NULL(); - } +/* {{{ proto Collator collator_create( string $locale ) + * Create collator. + */ +PHP_FUNCTION( collator_create ) +{ + object_init_ex( return_value, Collator_ce_ptr ); + collator_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU); } /* }}} */ @@ -81,46 +74,8 @@ PHP_FUNCTION( collator_create ) */ PHP_METHOD( Collator, __construct ) { - char* locale = NULL; - int locale_len = 0; - - COLLATOR_METHOD_INIT_VARS - - object = getThis(); - // Parse parameters. - if( zend_parse_parameters( ZEND_NUM_ARGS() TSRMLS_CC, "s", - &locale, &locale_len ) == FAILURE ) - { - intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, - "__construct: unable to parse input params", 0 TSRMLS_CC ); - - zval_dtor(object); - ZVAL_NULL(object); - RETURN_NULL(); - } - - INTL_CHECK_LOCALE_LEN_OBJ(locale_len, object); - /* Fetch the object. */ - 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 ) ); - - if( U_FAILURE( COLLATOR_ERROR_CODE( co ) ) || co->ucoll == NULL ) - { - intl_error_set( NULL, COLLATOR_ERROR_CODE( co ), - "__construct: unable to open ICU collator", 0 TSRMLS_CC ); - - zval_dtor(object); - ZVAL_NULL(object); - RETURN_NULL(); - } + return_value = getThis(); + collator_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU); } /* }}} */ diff --git a/ext/intl/dateformat/dateformat.c b/ext/intl/dateformat/dateformat.c index b61d268d72..e8610a780f 100755 --- a/ext/intl/dateformat/dateformat.c +++ b/ext/intl/dateformat/dateformat.c @@ -67,242 +67,84 @@ void dateformat_register_constants( INIT_FUNC_ARGS ) } /* }}} */ -/* {{{ proto IntlDateFormatter IntlDateFormatter::create( string $locale , long date_type, long time_type[,string $timezone_str, long $calendar , string $pattern] ) - * Create formatter. }}} */ -/* {{{ proto IntlDateFormatter datefmt_create( string $locale, long date_type, long time_type[,string $timezone_str, long $calendar , string $pattern] ) - - * Create formatter. - */ -PHP_FUNCTION( datefmt_create ) +/* {{{ */ +static void datefmt_ctor(INTERNAL_FUNCTION_PARAMETERS) { - char* locale; + char* locale; int locale_len = 0; zval* object; - - long date_type = 0; - long time_type = 0; - long calendar = 1; - int all_done = 0; - //zval* timezone = NULL; - - char* timezone_str = NULL; - int timezone_str_len = 0; - char* pattern_str = NULL; - int pattern_str_len = 0; - UChar* svalue = NULL; //UTF-16 pattern_str - int slength = 0; - UChar* timezone_utf16 = NULL; //UTF-16 timezone_str - int timezone_utf16_len = 0; + long date_type = 0; + long time_type = 0; + long calendar = 1; + UChar* pattern_str = NULL; + int pattern_str_len = 0; + UChar* timezone_utf16 = NULL; //UTF-16 timezone_str + int timezone_utf16_len = 0; UCalendar ucal_obj = NULL; + IntlDateFormatter_object* dfo; - - IntlDateFormatter_object* mfo; - intl_error_reset( NULL TSRMLS_CC ); - + object = return_value; // Parse parameters. - if( zend_parse_parameters( ZEND_NUM_ARGS() TSRMLS_CC, "sll|sls", - &locale, &locale_len, &date_type, & time_type , &timezone_str, &timezone_str_len , &calendar ,&pattern_str , &pattern_str_len ) == FAILURE ) - { - intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, - "datefmt_create: unable to parse input params", 0 TSRMLS_CC ); - RETURN_NULL(); - } - - - // Create a IntlDateFormatter object and save the ICU formatter into it. - if( ( object = getThis() ) == NULL ) - object = return_value; - - if( Z_TYPE_P( object ) != IS_OBJECT ) - object_init_ex( object, IntlDateFormatter_ce_ptr ); + if( zend_parse_parameters( ZEND_NUM_ARGS() TSRMLS_CC, "sll|ulu", + &locale, &locale_len, &date_type, & time_type , &timezone_utf16, &timezone_utf16_len , &calendar ,&pattern_str , &pattern_str_len ) == FAILURE ) + { + intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, "datefmt_create: unable to parse input parameters", 0 TSRMLS_CC ); + zval_dtor(return_value); + RETURN_NULL(); + } DATE_FORMAT_METHOD_FETCH_OBJECT; - if(locale_len == 0) { locale = INTL_G(default_locale); } - // Convert pattern (if specified) to UTF-16. if( pattern_str && pattern_str_len>0 ){ - intl_convert_utf8_to_utf16(&svalue, &slength, pattern_str, pattern_str_len, &INTL_DATA_ERROR_CODE(mfo)); - INTL_METHOD_CHECK_STATUS(mfo, "Error converting pattern to UTF-16" ); - } - - // Convert pattern (if specified) to UTF-16. - if( timezone_str && timezone_str_len >0 ){ - intl_convert_utf8_to_utf16(&timezone_utf16, &timezone_utf16_len, timezone_str, timezone_str_len, &INTL_DATA_ERROR_CODE(mfo)); - INTL_METHOD_CHECK_STATUS(mfo, "Error converting timezone_str to UTF-16" ); + DATE_FORMAT_OBJECT(dfo) = udat_open(UDAT_IGNORE,UDAT_IGNORE, locale, timezone_utf16, timezone_utf16_len ,pattern_str ,pattern_str_len , &INTL_DATA_ERROR_CODE(dfo)); + } else { + DATE_FORMAT_OBJECT(dfo) = udat_open(time_type,date_type, locale, timezone_utf16, timezone_utf16_len ,pattern_str ,pattern_str_len , &INTL_DATA_ERROR_CODE(dfo)); } - // Create an ICU date formatter. - while( U_FAILURE( INTL_DATA_ERROR_CODE(mfo)) || (all_done==0) ){ - // Convert pattern (if specified) to UTF-16. - if( pattern_str && pattern_str_len>0 ){ - DATE_FORMAT_OBJECT(mfo) = udat_open(UDAT_IGNORE,UDAT_IGNORE, locale, timezone_utf16, timezone_utf16_len ,svalue ,slength , &INTL_DATA_ERROR_CODE((mfo))); - }else{ - DATE_FORMAT_OBJECT(mfo) = udat_open(time_type,date_type, locale, timezone_utf16, timezone_utf16_len ,svalue ,slength , &INTL_DATA_ERROR_CODE((mfo))); + //Set the calendar if passed + if(!U_FAILURE(INTL_DATA_ERROR_CODE(dfo)) && calendar) { + ucal_obj = ucal_open( timezone_utf16 , timezone_utf16_len , locale , calendar , &INTL_DATA_ERROR_CODE(dfo) ); + if(!U_FAILURE(INTL_DATA_ERROR_CODE(dfo))) { + udat_setCalendar( DATE_FORMAT_OBJECT(dfo), ucal_obj ); } + } - //Set the calendar if passed - if( calendar) { - ucal_obj = ucal_open( timezone_utf16 , timezone_utf16_len , locale , calendar , &INTL_DATA_ERROR_CODE(mfo) ); - udat_setCalendar( DATE_FORMAT_OBJECT(mfo), ucal_obj ); - } - all_done = 1; - - }//end of while - - - if( U_FAILURE( INTL_DATA_ERROR_CODE((mfo)) ) ) - { - intl_error_set( NULL, INTL_DATA_ERROR_CODE((mfo)) , - "__construct: date formatter creation failed", 0 TSRMLS_CC ); - zval_dtor(object); - ZVAL_NULL(object); - if( svalue){ - efree(svalue); - } - if( timezone_utf16){ - efree(timezone_utf16); - } - RETURN_NULL(); - } + INTL_CTOR_CHECK_STATUS(dfo, "datefmt_create: date formatter creation failed"); - if( svalue){ - efree(svalue); - } - if( timezone_utf16){ - efree(timezone_utf16); - } //Set the class variables - mfo->date_type = date_type; - mfo->time_type = time_type; - mfo->calendar = calendar; + dfo->date_type = date_type; + dfo->time_type = time_type; + dfo->calendar = calendar; if( timezone_str && timezone_str_len > 0){ - if( mfo->timezone_id ){ - efree(mfo->timezone_id); - } - mfo->timezone_id = estrndup( timezone_str, timezone_str_len); + dfo->timezone_id = estrndup( timezone_str, timezone_str_len); } } /* }}} */ -/* {{{ proto void IntlDateFormatter::__construct( string $locale, string $pattern ) +/* {{{ proto IntlDateFormatter IntlDateFormatter::create(string $locale, long date_type, long time_type[, string $timezone_str, long $calendar, string $pattern] ) + * Create formatter. }}} */ +/* {{{ proto IntlDateFormatter datefmt_create(string $locale, long date_type, long time_type[, string $timezone_str, long $calendar, string $pattern] ) + + * Create formatter. + */ +PHP_FUNCTION( datefmt_create ) +{ + object_init_ex( return_value, IntlDateFormatter_ce_ptr ); + datefmt_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU); +} +/* }}} */ + +/* {{{ proto void IntlDateFormatter::__construct(string $locale, long date_type, long time_type[, string $timezone_str, long $calendar, string $pattern]) * IntlDateFormatter object constructor. */ PHP_METHOD( IntlDateFormatter, __construct ) { - char* locale = NULL; - int locale_len = 0; - long date_type = 0; - long time_type = 0; - long calendar = 1; - - char* timezone_str = NULL; - int timezone_str_len = 0; - char* pattern_str = NULL; - int pattern_str_len = 0; - UChar* svalue = NULL; - int slength = 0; - UChar* timezone_utf16 = NULL; //UTF-16 timezone_str - int timezone_utf16_len = 0; - - UCalendar ucal_obj = NULL; - int all_done = 0; - - zval* object; - IntlDateFormatter_object* mfo; - - intl_error_reset( NULL TSRMLS_CC ); - - object = getThis(); - - // Parse parameters. - if( zend_parse_parameters( ZEND_NUM_ARGS() TSRMLS_CC, "sll|slsb", - &locale, &locale_len, &date_type, & time_type , &timezone_str, &timezone_str_len , &calendar ,&pattern_str , &pattern_str_len ) == FAILURE ) - { - intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, - "__construct: unable to parse input params", 0 TSRMLS_CC ); - zval_dtor(object); - ZVAL_NULL(object); - RETURN_NULL(); - } - -/* - //Check if timezone is in proper type - if( (Z_TYPE_P(timezone) != IS_STRING) && (Z_TYPE_P(timezone) != IS_OBJECT) ){ - intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, - "__construct: unable to parse input params", 0 TSRMLS_CC ); - zval_dtor(object); - ZVAL_NULL(object); - RETURN_NULL(); - } -*/ - - mfo = (IntlDateFormatter_object *) zend_object_store_get_object( object TSRMLS_CC ); - - intl_error_reset( &mfo->datef_data.error TSRMLS_CC ); - - if(locale_len == 0) { - locale = INTL_G(default_locale); - } - - // Convert pattern (if specified) to UTF-16. - if( pattern_str && pattern_str_len>0 ){ - intl_convert_utf8_to_utf16(&svalue, &slength, pattern_str, pattern_str_len, &INTL_DATA_ERROR_CODE(mfo)); - INTL_METHOD_CHECK_STATUS(mfo, "Error converting pattern to UTF-16" ); - } - - // Convert pattern (if specified) to UTF-16. - if( timezone_str && timezone_str_len >0 ){ - intl_convert_utf8_to_utf16(&timezone_utf16, &timezone_utf16_len, timezone_str, timezone_str_len, &INTL_DATA_ERROR_CODE(mfo)); - INTL_METHOD_CHECK_STATUS(mfo, "Error converting timezone_str to UTF-16" ); - } - - - // Create an ICU date formatter. - while( U_FAILURE( INTL_DATA_ERROR_CODE(mfo)) || (all_done==0) ){ - if( pattern_str && pattern_str_len>0 ){ - DATE_FORMAT_OBJECT(mfo) = udat_open(UDAT_IGNORE,UDAT_IGNORE, locale, timezone_utf16, timezone_utf16_len ,svalue ,slength , &INTL_DATA_ERROR_CODE((mfo))); - }else{ - DATE_FORMAT_OBJECT(mfo) = udat_open(time_type,date_type, locale, timezone_utf16, timezone_utf16_len ,svalue ,slength , &INTL_DATA_ERROR_CODE((mfo))); - } - - - //Set the calendar if passed - if( calendar) { - ucal_obj = ucal_open( timezone_utf16 , timezone_utf16_len , locale , calendar , &INTL_DATA_ERROR_CODE(mfo) ); - udat_setCalendar( DATE_FORMAT_OBJECT(mfo), ucal_obj ); - } - all_done = 1; - - }//end of while - - - if( U_FAILURE( INTL_DATA_ERROR_CODE((mfo)) ) ) - { - intl_error_set( NULL, INTL_DATA_ERROR_CODE(mfo), - "__construct: date formatter creation failed", 0 TSRMLS_CC ); - if( svalue){ - efree(svalue); - } - zval_dtor(object); - ZVAL_NULL(object); - RETURN_NULL(); - } - - if( svalue){ - efree(svalue); - } - - //Set the class variables - mfo->date_type = date_type; - mfo->time_type = time_type; - mfo->calendar = calendar; - if( timezone_str && timezone_str_len > 0){ - mfo->timezone_id = estrndup( timezone_str, timezone_str_len); - } + return_value = getThis(); + datefmt_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU); } /* }}} */ @@ -314,7 +156,7 @@ PHP_METHOD( IntlDateFormatter, __construct ) PHP_FUNCTION( datefmt_get_error_code ) { zval* object = NULL; - IntlDateFormatter_object* mfo = NULL; + IntlDateFormatter_object* dfo = NULL; // Parse parameters. if( zend_parse_method_parameters( ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", @@ -322,14 +164,13 @@ PHP_FUNCTION( datefmt_get_error_code ) { intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, "datefmt_get_error_code: unable to parse input params", 0 TSRMLS_CC ); - RETURN_FALSE; } - mfo = (IntlDateFormatter_object *) zend_object_store_get_object( object TSRMLS_CC ); + dfo = (IntlDateFormatter_object *) zend_object_store_get_object( object TSRMLS_CC ); // Return formatter's last error code. - RETURN_LONG( INTL_DATA_ERROR_CODE(mfo) ); + RETURN_LONG( INTL_DATA_ERROR_CODE(dfo) ); } /* }}} */ @@ -342,7 +183,7 @@ PHP_FUNCTION( datefmt_get_error_message ) { char* message = NULL; zval* object = NULL; - IntlDateFormatter_object* mfo = NULL; + IntlDateFormatter_object* dfo = NULL; // Parse parameters. if( zend_parse_method_parameters( ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", @@ -354,10 +195,10 @@ PHP_FUNCTION( datefmt_get_error_message ) RETURN_FALSE; } - mfo = (IntlDateFormatter_object *) zend_object_store_get_object( object TSRMLS_CC ); + dfo = (IntlDateFormatter_object *) zend_object_store_get_object( object TSRMLS_CC ); // Return last error message. - message = intl_error_get_message( &mfo->datef_data.error TSRMLS_CC ); + message = intl_error_get_message( &dfo->datef_data.error TSRMLS_CC ); RETURN_STRING( message, 0); } /* }}} */ diff --git a/ext/intl/dateformat/dateformat_attr.c b/ext/intl/dateformat/dateformat_attr.c index 09997b6ee3..a912b26ae7 100755 --- a/ext/intl/dateformat/dateformat_attr.c +++ b/ext/intl/dateformat/dateformat_attr.c @@ -26,7 +26,7 @@ #include #include -static void internal_set_calendar(IntlDateFormatter_object *mfo, char* timezone_id , int timezone_id_len , int calendar ,zval* return_value TSRMLS_DC){ +static void internal_set_calendar(IntlDateFormatter_object *dfo, char* timezone_id , int timezone_id_len , int calendar ,zval* return_value TSRMLS_DC){ int timezone_utf16_len = 0; UChar* timezone_utf16 = NULL; //timezone_id in UTF-16 @@ -45,17 +45,17 @@ static void internal_set_calendar(IntlDateFormatter_object *mfo, char* timezone_ } // Convert timezone to UTF-16. - intl_convert_utf8_to_utf16(&timezone_utf16, &timezone_utf16_len, timezone_id, timezone_id_len , &INTL_DATA_ERROR_CODE(mfo)); - INTL_METHOD_CHECK_STATUS(mfo, "Error converting timezone to UTF-16" ); + intl_convert_utf8_to_utf16(&timezone_utf16, &timezone_utf16_len, timezone_id, timezone_id_len , &INTL_DATA_ERROR_CODE(dfo)); + INTL_METHOD_CHECK_STATUS(dfo, "Error converting timezone to UTF-16" ); //Get the lcoale for the dateformatter - locale = (char *)udat_getLocaleByType(DATE_FORMAT_OBJECT(mfo), locale_type ,&INTL_DATA_ERROR_CODE(mfo)); + locale = (char *)udat_getLocaleByType(DATE_FORMAT_OBJECT(dfo), locale_type ,&INTL_DATA_ERROR_CODE(dfo)); //Set the calendar if passed - ucal_obj = ucal_open( timezone_utf16 , timezone_utf16_len , locale , calendar , &INTL_DATA_ERROR_CODE(mfo) ); - udat_setCalendar( DATE_FORMAT_OBJECT(mfo), ucal_obj ); - INTL_METHOD_CHECK_STATUS(mfo, "Error setting the calendar."); + ucal_obj = ucal_open( timezone_utf16 , timezone_utf16_len , locale , calendar , &INTL_DATA_ERROR_CODE(dfo) ); + udat_setCalendar( DATE_FORMAT_OBJECT(dfo), ucal_obj ); + INTL_METHOD_CHECK_STATUS(dfo, "Error setting the calendar."); if( timezone_utf16){ efree(timezone_utf16); @@ -83,9 +83,9 @@ PHP_FUNCTION( datefmt_get_datetype ) // Fetch the object. DATE_FORMAT_METHOD_FETCH_OBJECT; - INTL_METHOD_CHECK_STATUS(mfo, "Error getting formatter datetype." ); + INTL_METHOD_CHECK_STATUS(dfo, "Error getting formatter datetype." ); - RETURN_LONG(mfo->date_type ); + RETURN_LONG(dfo->date_type ); } /* }}} */ @@ -109,9 +109,9 @@ PHP_FUNCTION( datefmt_get_timetype ) // Fetch the object. DATE_FORMAT_METHOD_FETCH_OBJECT; - INTL_METHOD_CHECK_STATUS(mfo, "Error getting formatter timetype." ); + INTL_METHOD_CHECK_STATUS(dfo, "Error getting formatter timetype." ); - RETURN_LONG(mfo->time_type ); + RETURN_LONG(dfo->time_type ); } /* }}} */ @@ -136,9 +136,9 @@ PHP_FUNCTION( datefmt_get_calendar ) // Fetch the object. DATE_FORMAT_METHOD_FETCH_OBJECT; - INTL_METHOD_CHECK_STATUS(mfo, "Error getting formatter calendar." ); + INTL_METHOD_CHECK_STATUS(dfo, "Error getting formatter calendar." ); - RETURN_LONG(mfo->calendar ); + RETURN_LONG(dfo->calendar ); } /* }}} */ @@ -162,10 +162,10 @@ PHP_FUNCTION( datefmt_get_timezone_id ) // Fetch the object. DATE_FORMAT_METHOD_FETCH_OBJECT; - INTL_METHOD_CHECK_STATUS(mfo, "Error getting formatter timezone_id." ); + INTL_METHOD_CHECK_STATUS(dfo, "Error getting formatter timezone_id." ); - if( mfo->timezone_id ){ - RETURN_STRING((char*)mfo->timezone_id ,TRUE ); + if( dfo->timezone_id ){ + RETURN_STRING((char*)dfo->timezone_id ,TRUE ); }else{ RETURN_NULL(); } @@ -195,13 +195,13 @@ PHP_FUNCTION( datefmt_set_timezone_id ) DATE_FORMAT_METHOD_FETCH_OBJECT; //set the timezone for the calendar - internal_set_calendar( mfo , timezone_id , timezone_id_len , mfo->calendar ,return_value TSRMLS_CC ); + internal_set_calendar( dfo , timezone_id , timezone_id_len , dfo->calendar ,return_value TSRMLS_CC ); //Set the IntlDateFormatter variable - if( mfo->timezone_id ){ - efree(mfo->timezone_id); + if( dfo->timezone_id ){ + efree(dfo->timezone_id); } - mfo->timezone_id = estrndup(timezone_id , timezone_id_len); + dfo->timezone_id = estrndup(timezone_id , timezone_id_len); RETURN_TRUE; } @@ -231,20 +231,20 @@ PHP_FUNCTION( datefmt_get_pattern ) // Fetch the object. DATE_FORMAT_METHOD_FETCH_OBJECT; - length = udat_toPattern(DATE_FORMAT_OBJECT(mfo), is_pattern_localized, value, length, &INTL_DATA_ERROR_CODE(mfo)); - if(INTL_DATA_ERROR_CODE(mfo) == U_BUFFER_OVERFLOW_ERROR && length >= USIZE( value_buf )) { + length = udat_toPattern(DATE_FORMAT_OBJECT(dfo), is_pattern_localized, value, length, &INTL_DATA_ERROR_CODE(dfo)); + if(INTL_DATA_ERROR_CODE(dfo) == U_BUFFER_OVERFLOW_ERROR && length >= USIZE( value_buf )) { ++length; // to avoid U_STRING_NOT_TERMINATED_WARNING - INTL_DATA_ERROR_CODE(mfo) = U_ZERO_ERROR; + INTL_DATA_ERROR_CODE(dfo) = U_ZERO_ERROR; value = eumalloc(length); - length = udat_toPattern(DATE_FORMAT_OBJECT(mfo), is_pattern_localized , value, length, &INTL_DATA_ERROR_CODE(mfo) ); - if(U_FAILURE(INTL_DATA_ERROR_CODE(mfo))) { + length = udat_toPattern(DATE_FORMAT_OBJECT(dfo), is_pattern_localized , value, length, &INTL_DATA_ERROR_CODE(dfo) ); + if(U_FAILURE(INTL_DATA_ERROR_CODE(dfo))) { efree(value); value = value_buf; } } - INTL_METHOD_CHECK_STATUS(mfo, "Error getting formatter pattern" ); + INTL_METHOD_CHECK_STATUS(dfo, "Error getting formatter pattern" ); - INTL_METHOD_RETVAL_UTF8( mfo, value, length, ( value != value_buf ) ); + INTL_METHOD_RETVAL_UTF8( dfo, value, length, ( value != value_buf ) ); } /* }}} */ @@ -276,13 +276,13 @@ PHP_FUNCTION( datefmt_set_pattern ) DATE_FORMAT_METHOD_FETCH_OBJECT; // Convert given pattern to UTF-16. - intl_convert_utf8_to_utf16(&svalue, &slength, value, value_len, &INTL_DATA_ERROR_CODE(mfo)); - INTL_METHOD_CHECK_STATUS(mfo, "Error converting pattern to UTF-16" ); + intl_convert_utf8_to_utf16(&svalue, &slength, value, value_len, &INTL_DATA_ERROR_CODE(dfo)); + INTL_METHOD_CHECK_STATUS(dfo, "Error converting pattern to UTF-16" ); - udat_applyPattern(DATE_FORMAT_OBJECT(mfo), (UBool)is_pattern_localized , svalue, slength); + udat_applyPattern(DATE_FORMAT_OBJECT(dfo), (UBool)is_pattern_localized , svalue, slength); efree(svalue); - INTL_METHOD_CHECK_STATUS(mfo, "Error setting symbol value"); + INTL_METHOD_CHECK_STATUS(dfo, "Error setting symbol value"); RETURN_TRUE; } @@ -313,7 +313,7 @@ PHP_FUNCTION( datefmt_get_locale ) // Fetch the object. DATE_FORMAT_METHOD_FETCH_OBJECT; - loc = (char *)udat_getLocaleByType(DATE_FORMAT_OBJECT(mfo), loc_type ,&INTL_DATA_ERROR_CODE(mfo)); + loc = (char *)udat_getLocaleByType(DATE_FORMAT_OBJECT(dfo), loc_type ,&INTL_DATA_ERROR_CODE(dfo)); RETURN_STRING(loc, 1); } /* }}} */ @@ -341,7 +341,7 @@ PHP_FUNCTION( datefmt_is_lenient ) // Fetch the object. DATE_FORMAT_METHOD_FETCH_OBJECT; - RETVAL_BOOL(udat_isLenient(DATE_FORMAT_OBJECT(mfo))); + RETVAL_BOOL(udat_isLenient(DATE_FORMAT_OBJECT(dfo))); } /* }}} */ @@ -370,7 +370,7 @@ PHP_FUNCTION( datefmt_set_lenient ) // Fetch the object. DATE_FORMAT_METHOD_FETCH_OBJECT; - udat_setLenient(DATE_FORMAT_OBJECT(mfo) , (UBool)isLenient ); + udat_setLenient(DATE_FORMAT_OBJECT(dfo) , (UBool)isLenient ); } /* }}} */ @@ -404,10 +404,10 @@ PHP_FUNCTION( datefmt_set_calendar ) DATE_FORMAT_METHOD_FETCH_OBJECT; - internal_set_calendar( mfo , mfo->timezone_id , strlen(mfo->timezone_id) , calendar ,return_value TSRMLS_CC ); + internal_set_calendar( dfo , dfo->timezone_id , strlen(dfo->timezone_id) , calendar ,return_value TSRMLS_CC ); //Set the calendar value in the IntlDateFormatter object - mfo->calendar = calendar ; + dfo->calendar = calendar ; RETURN_TRUE; } diff --git a/ext/intl/dateformat/dateformat_class.c b/ext/intl/dateformat/dateformat_class.c index e582467231..798fac3393 100755 --- a/ext/intl/dateformat/dateformat_class.c +++ b/ext/intl/dateformat/dateformat_class.c @@ -39,17 +39,17 @@ static void IntlDateFormatter_object_dtor(void *object, zend_object_handle handl /* {{{ IntlDateFormatter_objects_free */ void IntlDateFormatter_object_free( zend_object *object TSRMLS_DC ) { - IntlDateFormatter_object* mfo = (IntlDateFormatter_object*)object; + IntlDateFormatter_object* dfo = (IntlDateFormatter_object*)object; - zend_object_std_dtor( &mfo->zo TSRMLS_CC ); + zend_object_std_dtor( &dfo->zo TSRMLS_CC ); - dateformat_data_free( &mfo->datef_data TSRMLS_CC ); + dateformat_data_free( &dfo->datef_data TSRMLS_CC ); - if( mfo->timezone_id ){ - efree(mfo->timezone_id); + if( dfo->timezone_id ){ + efree(dfo->timezone_id); } - efree( mfo ); + efree( dfo ); } /* }}} */ diff --git a/ext/intl/dateformat/dateformat_class.h b/ext/intl/dateformat/dateformat_class.h index 039ff1a59a..9ad83ee3d6 100755 --- a/ext/intl/dateformat/dateformat_class.h +++ b/ext/intl/dateformat/dateformat_class.h @@ -37,8 +37,8 @@ extern zend_class_entry *IntlDateFormatter_ce_ptr; /* Auxiliary macros */ -#define DATE_FORMAT_METHOD_INIT_VARS INTL_METHOD_INIT_VARS(IntlDateFormatter, mfo) -#define DATE_FORMAT_METHOD_FETCH_OBJECT INTL_METHOD_FETCH_OBJECT(IntlDateFormatter, mfo) -#define DATE_FORMAT_OBJECT(mfo) (mfo)->datef_data.udatf +#define DATE_FORMAT_METHOD_INIT_VARS INTL_METHOD_INIT_VARS(IntlDateFormatter, dfo) +#define DATE_FORMAT_METHOD_FETCH_OBJECT INTL_METHOD_FETCH_OBJECT(IntlDateFormatter, dfo) +#define DATE_FORMAT_OBJECT(dfo) (dfo)->datef_data.udatf #endif // #ifndef DATE_FORMAT_CLASS_H diff --git a/ext/intl/dateformat/dateformat_format.c b/ext/intl/dateformat/dateformat_format.c index c23ab3203d..bf575c9883 100755 --- a/ext/intl/dateformat/dateformat_format.c +++ b/ext/intl/dateformat/dateformat_format.c @@ -31,24 +31,24 @@ /* {{{ * Internal function which calls the udat_format */ -static void internal_format(IntlDateFormatter_object *mfo, UDate timestamp , zval *return_value TSRMLS_DC){ +static void internal_format(IntlDateFormatter_object *dfo, UDate timestamp , zval *return_value TSRMLS_DC){ UChar* formatted = NULL; int32_t resultlengthneeded =0 ; - resultlengthneeded=udat_format( DATE_FORMAT_OBJECT(mfo), timestamp, NULL, resultlengthneeded, NULL, &INTL_DATA_ERROR_CODE(mfo)); - if(INTL_DATA_ERROR_CODE(mfo)==U_BUFFER_OVERFLOW_ERROR) + resultlengthneeded=udat_format( DATE_FORMAT_OBJECT(dfo), timestamp, NULL, resultlengthneeded, NULL, &INTL_DATA_ERROR_CODE(dfo)); + if(INTL_DATA_ERROR_CODE(dfo)==U_BUFFER_OVERFLOW_ERROR) { - INTL_DATA_ERROR_CODE(mfo)=U_ZERO_ERROR; + INTL_DATA_ERROR_CODE(dfo)=U_ZERO_ERROR; formatted=(UChar*)emalloc(sizeof(UChar) * resultlengthneeded); - udat_format( DATE_FORMAT_OBJECT(mfo), timestamp, formatted, resultlengthneeded, NULL, &INTL_DATA_ERROR_CODE(mfo)); + udat_format( DATE_FORMAT_OBJECT(dfo), timestamp, formatted, resultlengthneeded, NULL, &INTL_DATA_ERROR_CODE(dfo)); } - if (formatted && U_FAILURE( INTL_DATA_ERROR_CODE(mfo) ) ) { + if (formatted && U_FAILURE( INTL_DATA_ERROR_CODE(dfo) ) ) { efree(formatted); } - INTL_METHOD_CHECK_STATUS( mfo, "Date formatting failed" ); - INTL_METHOD_RETVAL_UTF8( mfo, formatted, resultlengthneeded, 1 ); + INTL_METHOD_CHECK_STATUS( dfo, "Date formatting failed" ); + INTL_METHOD_RETVAL_UTF8( dfo, formatted, resultlengthneeded, 1 ); } /* }}} */ @@ -57,7 +57,7 @@ static void internal_format(IntlDateFormatter_object *mfo, UDate timestamp , zva /* {{{ * Internal function which fetches an element from the passed array for the key_name passed */ -static double internal_get_arr_ele(IntlDateFormatter_object *mfo , HashTable* hash_arr ,char* key_name TSRMLS_DC){ +static double internal_get_arr_ele(IntlDateFormatter_object *dfo , HashTable* hash_arr ,char* key_name TSRMLS_DC){ zval** ele_value = NULL; UDate result = -1; @@ -77,7 +77,7 @@ static double internal_get_arr_ele(IntlDateFormatter_object *mfo , HashTable* h /* {{{ * Internal function which creates a UCalendar from the passed array */ -static void internal_create_ucal(IntlDateFormatter_object *mfo, HashTable* hash_arr , UCalendar* pcal TSRMLS_DC){ +static void internal_create_ucal(IntlDateFormatter_object *dfo, HashTable* hash_arr , UCalendar* pcal TSRMLS_DC){ long year =0; long month =0; long hour =0; @@ -89,21 +89,21 @@ static void internal_create_ucal(IntlDateFormatter_object *mfo, HashTable* hash_ UBool isInDST = FALSE; //Fetch values from the incoming array - year = internal_get_arr_ele( mfo , hash_arr , CALENDAR_YEAR TSRMLS_CC) + 1900; //tm_year is years since 1900 + year = internal_get_arr_ele( dfo , hash_arr , CALENDAR_YEAR TSRMLS_CC) + 1900; //tm_year is years since 1900 //Month in ICU and PHP starts from January =0 - month = internal_get_arr_ele( mfo , hash_arr , CALENDAR_MON TSRMLS_CC); - hour = internal_get_arr_ele( mfo , hash_arr , CALENDAR_HOUR TSRMLS_CC); - minute = internal_get_arr_ele( mfo , hash_arr , CALENDAR_MIN TSRMLS_CC); - second = internal_get_arr_ele( mfo , hash_arr , CALENDAR_SEC TSRMLS_CC); - wday = internal_get_arr_ele( mfo , hash_arr , CALENDAR_WDAY TSRMLS_CC); - yday = internal_get_arr_ele( mfo , hash_arr , CALENDAR_YDAY TSRMLS_CC); - isInDST = internal_get_arr_ele( mfo , hash_arr , CALENDAR_ISDST TSRMLS_CC); + month = internal_get_arr_ele( dfo , hash_arr , CALENDAR_MON TSRMLS_CC); + hour = internal_get_arr_ele( dfo , hash_arr , CALENDAR_HOUR TSRMLS_CC); + minute = internal_get_arr_ele( dfo , hash_arr , CALENDAR_MIN TSRMLS_CC); + second = internal_get_arr_ele( dfo , hash_arr , CALENDAR_SEC TSRMLS_CC); + wday = internal_get_arr_ele( dfo , hash_arr , CALENDAR_WDAY TSRMLS_CC); + yday = internal_get_arr_ele( dfo , hash_arr , CALENDAR_YDAY TSRMLS_CC); + isInDST = internal_get_arr_ele( dfo , hash_arr , CALENDAR_ISDST TSRMLS_CC); //For the ucal_setDateTime() function , this is the 'date' value - mday = internal_get_arr_ele( mfo , hash_arr , CALENDAR_MDAY TSRMLS_CC); + mday = internal_get_arr_ele( dfo , hash_arr , CALENDAR_MDAY TSRMLS_CC); //set the incoming values for the calendar - ucal_setDateTime( pcal, year, month , mday , hour , minute , second , &INTL_DATA_ERROR_CODE(mfo)); - if( INTL_DATA_ERROR_CODE(mfo) != U_ZERO_ERROR){ + ucal_setDateTime( pcal, year, month , mday , hour , minute , second , &INTL_DATA_ERROR_CODE(dfo)); + if( INTL_DATA_ERROR_CODE(dfo) != U_ZERO_ERROR){ return; } //ICU UCAL_DAY_OF_WEEK starts from SUNDAY=1 thru SATURDAY=7 @@ -157,14 +157,14 @@ PHP_FUNCTION(datefmt_format) if( !hash_arr || zend_hash_num_elements( hash_arr ) == 0 ) RETURN_FALSE; //Create a UCalendar object from the array and then format it - temp_cal = ucal_open(NULL, -1, NULL, UCAL_GREGORIAN, &INTL_DATA_ERROR_CODE(mfo)); + temp_cal = ucal_open(NULL, -1, NULL, UCAL_GREGORIAN, &INTL_DATA_ERROR_CODE(dfo)); ucal_clear(temp_cal); - INTL_METHOD_CHECK_STATUS( mfo, "datefmt_format: Date formatting failed while creating calendar from the array" ) - internal_create_ucal( mfo , hash_arr , temp_cal TSRMLS_CC); - INTL_METHOD_CHECK_STATUS( mfo, "datefmt_format: Date formatting failed while creating calendar from the array" ) + INTL_METHOD_CHECK_STATUS( dfo, "datefmt_format: Date formatting failed while creating calendar from the array" ) + internal_create_ucal( dfo , hash_arr , temp_cal TSRMLS_CC); + INTL_METHOD_CHECK_STATUS( dfo, "datefmt_format: Date formatting failed while creating calendar from the array" ) //Fetch the timestamp from the created UCalendar - timestamp = ucal_getMillis(temp_cal , &INTL_DATA_ERROR_CODE(mfo) ); - INTL_METHOD_CHECK_STATUS( mfo, "datefmt_format: Date formatting failed" ) + timestamp = ucal_getMillis(temp_cal , &INTL_DATA_ERROR_CODE(dfo) ); + INTL_METHOD_CHECK_STATUS( dfo, "datefmt_format: Date formatting failed" ) break; /* case IS_OBJECT: @@ -176,7 +176,7 @@ PHP_FUNCTION(datefmt_format) RETURN_FALSE; } - internal_format( mfo, timestamp ,return_value TSRMLS_CC); + internal_format( dfo, timestamp ,return_value TSRMLS_CC); } diff --git a/ext/intl/dateformat/dateformat_parse.c b/ext/intl/dateformat/dateformat_parse.c index a27171bfa7..873cf9ed25 100755 --- a/ext/intl/dateformat/dateformat_parse.c +++ b/ext/intl/dateformat/dateformat_parse.c @@ -33,22 +33,22 @@ * if set to 1 - store any error encountered in the parameter parse_error * if set to 0 - no need to store any error encountered in the parameter parse_error */ -static void internal_parse_to_timestamp(IntlDateFormatter_object *mfo, char* text_to_parse , int32_t text_len, int parse_pos , zval *return_value TSRMLS_DC){ +static void internal_parse_to_timestamp(IntlDateFormatter_object *dfo, char* text_to_parse , int32_t text_len, int parse_pos , zval *return_value TSRMLS_DC){ long result = 0; UDate timestamp =0; UChar* text_utf16 = NULL; int32_t text_utf16_len = 0; // Convert timezone to UTF-16. - intl_convert_utf8_to_utf16(&text_utf16 , &text_utf16_len , text_to_parse , text_len, &INTL_DATA_ERROR_CODE(mfo)); - INTL_METHOD_CHECK_STATUS(mfo, "Error converting timezone to UTF-16" ); + intl_convert_utf8_to_utf16(&text_utf16 , &text_utf16_len , text_to_parse , text_len, &INTL_DATA_ERROR_CODE(dfo)); + INTL_METHOD_CHECK_STATUS(dfo, "Error converting timezone to UTF-16" ); - timestamp = udat_parse( DATE_FORMAT_OBJECT(mfo), text_utf16 , text_utf16_len , &parse_pos , &INTL_DATA_ERROR_CODE(mfo)); + timestamp = udat_parse( DATE_FORMAT_OBJECT(dfo), text_utf16 , text_utf16_len , &parse_pos , &INTL_DATA_ERROR_CODE(dfo)); if( text_utf16 ){ efree(text_utf16); } - INTL_METHOD_CHECK_STATUS( mfo, "Date parsing failed" ); + INTL_METHOD_CHECK_STATUS( dfo, "Date parsing failed" ); //Since return is in sec. result = (long )( timestamp / 1000 ); @@ -60,9 +60,9 @@ static void internal_parse_to_timestamp(IntlDateFormatter_object *mfo, char* tex } /* }}} */ -static void add_to_localtime_arr( IntlDateFormatter_object *mfo, zval* return_value ,UCalendar parsed_calendar , long calendar_field , char* key_name TSRMLS_DC){ - long calendar_field_val = ucal_get( parsed_calendar , calendar_field , &INTL_DATA_ERROR_CODE(mfo)); - INTL_METHOD_CHECK_STATUS( mfo, "Date parsing - localtime failed : could not get a field from calendar" ); +static void add_to_localtime_arr( IntlDateFormatter_object *dfo, zval* return_value ,UCalendar parsed_calendar , long calendar_field , char* key_name TSRMLS_DC){ + long calendar_field_val = ucal_get( parsed_calendar , calendar_field , &INTL_DATA_ERROR_CODE(dfo)); + INTL_METHOD_CHECK_STATUS( dfo, "Date parsing - localtime failed : could not get a field from calendar" ); if( strcmp(key_name , CALENDAR_YEAR )==0 ){ //since tm_year is years from 1900 @@ -78,39 +78,39 @@ static void add_to_localtime_arr( IntlDateFormatter_object *mfo, zval* return_va /* {{{ * Internal function which calls the udat_parseCalendar */ -static void internal_parse_to_localtime(IntlDateFormatter_object *mfo, char* text_to_parse , int32_t text_len, int parse_pos , zval *return_value TSRMLS_DC){ +static void internal_parse_to_localtime(IntlDateFormatter_object *dfo, char* text_to_parse , int32_t text_len, int parse_pos , zval *return_value TSRMLS_DC){ UCalendar* parsed_calendar = NULL ; UChar* text_utf16 = NULL; int32_t text_utf16_len = 0; long isInDST = 0; // Convert timezone to UTF-16. - intl_convert_utf8_to_utf16(&text_utf16 , &text_utf16_len , text_to_parse , text_len, &INTL_DATA_ERROR_CODE(mfo)); - INTL_METHOD_CHECK_STATUS(mfo, "Error converting timezone to UTF-16" ); + intl_convert_utf8_to_utf16(&text_utf16 , &text_utf16_len , text_to_parse , text_len, &INTL_DATA_ERROR_CODE(dfo)); + INTL_METHOD_CHECK_STATUS(dfo, "Error converting timezone to UTF-16" ); - parsed_calendar = ucal_open(NULL, -1, NULL, UCAL_GREGORIAN, &INTL_DATA_ERROR_CODE(mfo)); - udat_parseCalendar( DATE_FORMAT_OBJECT(mfo), parsed_calendar , text_utf16 , text_utf16_len , &parse_pos , &INTL_DATA_ERROR_CODE(mfo)); + parsed_calendar = ucal_open(NULL, -1, NULL, UCAL_GREGORIAN, &INTL_DATA_ERROR_CODE(dfo)); + udat_parseCalendar( DATE_FORMAT_OBJECT(dfo), parsed_calendar , text_utf16 , text_utf16_len , &parse_pos , &INTL_DATA_ERROR_CODE(dfo)); if( text_utf16 ){ efree(text_utf16); } - INTL_METHOD_CHECK_STATUS( mfo, "Date parsing failed" ); + INTL_METHOD_CHECK_STATUS( dfo, "Date parsing failed" ); array_init( return_value ); //Add entries from various fields of the obtained parsed_calendar - add_to_localtime_arr( mfo , return_value , parsed_calendar , UCAL_SECOND , CALENDAR_SEC TSRMLS_CC); - add_to_localtime_arr( mfo , return_value , parsed_calendar , UCAL_MINUTE , CALENDAR_MIN TSRMLS_CC); - add_to_localtime_arr( mfo , return_value , parsed_calendar , UCAL_HOUR_OF_DAY , CALENDAR_HOUR TSRMLS_CC); - add_to_localtime_arr( mfo , return_value , parsed_calendar , UCAL_YEAR , CALENDAR_YEAR TSRMLS_CC); - add_to_localtime_arr( mfo , return_value , parsed_calendar , UCAL_DAY_OF_MONTH , CALENDAR_MDAY TSRMLS_CC); - add_to_localtime_arr( mfo , return_value , parsed_calendar , UCAL_DAY_OF_WEEK , CALENDAR_WDAY TSRMLS_CC); - add_to_localtime_arr( mfo , return_value , parsed_calendar , UCAL_DAY_OF_YEAR , CALENDAR_YDAY TSRMLS_CC); - add_to_localtime_arr( mfo , return_value , parsed_calendar , UCAL_MONTH , CALENDAR_MON TSRMLS_CC); + add_to_localtime_arr( dfo , return_value , parsed_calendar , UCAL_SECOND , CALENDAR_SEC TSRMLS_CC); + add_to_localtime_arr( dfo , return_value , parsed_calendar , UCAL_MINUTE , CALENDAR_MIN TSRMLS_CC); + add_to_localtime_arr( dfo , return_value , parsed_calendar , UCAL_HOUR_OF_DAY , CALENDAR_HOUR TSRMLS_CC); + add_to_localtime_arr( dfo , return_value , parsed_calendar , UCAL_YEAR , CALENDAR_YEAR TSRMLS_CC); + add_to_localtime_arr( dfo , return_value , parsed_calendar , UCAL_DAY_OF_MONTH , CALENDAR_MDAY TSRMLS_CC); + add_to_localtime_arr( dfo , return_value , parsed_calendar , UCAL_DAY_OF_WEEK , CALENDAR_WDAY TSRMLS_CC); + add_to_localtime_arr( dfo , return_value , parsed_calendar , UCAL_DAY_OF_YEAR , CALENDAR_YDAY TSRMLS_CC); + add_to_localtime_arr( dfo , return_value , parsed_calendar , UCAL_MONTH , CALENDAR_MON TSRMLS_CC); //Is in DST? - isInDST = ucal_inDaylightTime(parsed_calendar , &INTL_DATA_ERROR_CODE(mfo)); - INTL_METHOD_CHECK_STATUS( mfo, "Date parsing - localtime failed : while checking if currently in DST." ); + isInDST = ucal_inDaylightTime(parsed_calendar , &INTL_DATA_ERROR_CODE(dfo)); + INTL_METHOD_CHECK_STATUS( dfo, "Date parsing - localtime failed : while checking if currently in DST." ); add_assoc_long( return_value, CALENDAR_ISDST ,(isInDST==1?1:0)); } /* }}} */ @@ -140,7 +140,7 @@ PHP_FUNCTION(datefmt_parse) // Fetch the object. DATE_FORMAT_METHOD_FETCH_OBJECT; - internal_parse_to_timestamp( mfo, text_to_parse , text_len , + internal_parse_to_timestamp( dfo, text_to_parse , text_len , parse_pos , return_value TSRMLS_CC); @@ -172,7 +172,7 @@ PHP_FUNCTION(datefmt_localtime) // Fetch the object. DATE_FORMAT_METHOD_FETCH_OBJECT; - internal_parse_to_localtime( mfo, text_to_parse , text_len , + internal_parse_to_localtime( dfo, text_to_parse , text_len , parse_pos, return_value TSRMLS_CC); diff --git a/ext/intl/formatter/formatter_main.c b/ext/intl/formatter/formatter_main.c index 54f3f179b0..6d199730af 100755 --- a/ext/intl/formatter/formatter_main.c +++ b/ext/intl/formatter/formatter_main.c @@ -23,12 +23,8 @@ #include "php_intl.h" #include "formatter_class.h" -/* {{{ proto NumberFormatter NumberFormatter::create( string $locale, int style[, string $pattern ] ) - * Create formatter. }}} */ -/* {{{ proto NumberFormatter numfmt_create( string $locale, int style[, string $pattern ] ) - * Create formatter. - */ -PHP_FUNCTION( numfmt_create ) +/* {{{ */ +static void numfmt_ctor(INTERNAL_FUNCTION_PARAMETERS) { char* locale; UChar* pattern = NULL; @@ -42,18 +38,12 @@ PHP_FUNCTION( numfmt_create ) { intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, "numfmt_create: unable to parse input parameters", 0 TSRMLS_CC ); - + zval_dtor(return_value); RETURN_NULL(); } - INTL_CHECK_LOCALE_LEN(locale_len); - // Create a NumberFormatter object and save the ICU formatter into it. - if( ( object = getThis() ) == NULL ) - object = return_value; - - if( Z_TYPE_P( object ) != IS_OBJECT ) - object_init_ex( object, NumberFormatter_ce_ptr ); - + object = return_value; + INTL_CHECK_LOCALE_LEN_OBJ(locale_len, return_value); FORMATTER_METHOD_FETCH_OBJECT; if(locale_len == 0) { @@ -62,13 +52,19 @@ PHP_FUNCTION( numfmt_create ) FORMATTER_OBJECT(nfo) = unum_open(style, pattern, pattern_len, locale, NULL, &INTL_DATA_ERROR_CODE(nfo)); - if( U_FAILURE( INTL_DATA_ERROR_CODE((nfo)) ) ) - { - intl_error_set( NULL, INTL_DATA_ERROR_CODE( nfo ), - "numfmt_create: number formatter creation failed", 0 TSRMLS_CC ); - zval_dtor(return_value); - RETURN_NULL(); - } + INTL_CTOR_CHECK_STATUS(nfo, "numfmt_create: number formatter creation failed"); +} +/* }}} */ + +/* {{{ proto NumberFormatter NumberFormatter::create( string $locale, int style[, string $pattern ] ) + * Create number formatter. }}} */ +/* {{{ proto NumberFormatter numfmt_create( string $locale, int style[, string $pattern ] ) + * Create number formatter. + */ +PHP_FUNCTION( numfmt_create ) +{ + object_init_ex( return_value, NumberFormatter_ce_ptr ); + numfmt_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU); } /* }}} */ @@ -77,43 +73,8 @@ PHP_FUNCTION( numfmt_create ) */ PHP_METHOD( NumberFormatter, __construct ) { - char* locale; - UChar* pattern = NULL; - int locale_len = 0, pattern_len = 0; - long style; - FORMATTER_METHOD_INIT_VARS; - - object = getThis(); - - // Parse parameters. - if( zend_parse_parameters( ZEND_NUM_ARGS() TSRMLS_CC, "sl|u", - &locale, &locale_len, &style, &pattern, &pattern_len ) == FAILURE ) - { - intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, - "__construct: unable to parse input params", 0 TSRMLS_CC ); - zval_dtor(object); - ZVAL_NULL(object); - RETURN_NULL(); - } - - INTL_CHECK_LOCALE_LEN_OBJ(locale_len, object); - FORMATTER_METHOD_FETCH_OBJECT; - - if(locale_len == 0) { - locale = UG(default_locale); - } - - // Create an ICU number formatter. - FORMATTER_OBJECT(nfo) = unum_open(style, pattern, pattern_len, locale, NULL, &INTL_DATA_ERROR_CODE(nfo)); - - if( U_FAILURE( INTL_DATA_ERROR_CODE((nfo)) ) ) - { - intl_error_set( NULL, INTL_DATA_ERROR_CODE( nfo ), - "__construct: number formatter creation failed", 0 TSRMLS_CC ); - zval_dtor(object); - ZVAL_NULL(object); - RETURN_NULL(); - } + return_value = getThis(); + numfmt_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU); } /* }}} */ diff --git a/ext/intl/intl_data.h b/ext/intl/intl_data.h index 2c15a4a9c6..b3d729a5dd 100755 --- a/ext/intl/intl_data.h +++ b/ext/intl/intl_data.h @@ -55,6 +55,16 @@ typedef struct _intl_data { #define INTL_MAX_LOCALE_LEN 64 +// Check status, if error - destroy value and exit +#define INTL_CTOR_CHECK_STATUS(obj, msg) \ + intl_error_set_code( NULL, INTL_DATA_ERROR_CODE((obj)) TSRMLS_CC ); \ + if( U_FAILURE( INTL_DATA_ERROR_CODE((obj)) ) ) \ + { \ + intl_errors_set_custom_msg( INTL_DATA_ERROR_P((obj)), msg, 0 TSRMLS_CC ); \ + zval_dtor(return_value); \ + RETURN_NULL(); \ + } + #define INTL_CHECK_LOCALE_LEN(locale_len) \ if((locale_len) > INTL_MAX_LOCALE_LEN) { \ intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, \ diff --git a/ext/intl/msgformat/msgformat.c b/ext/intl/msgformat/msgformat.c index badd1e2f95..4967a24d8c 100755 --- a/ext/intl/msgformat/msgformat.c +++ b/ext/intl/msgformat/msgformat.c @@ -25,12 +25,8 @@ #include "msgformat_class.h" #include "intl_data.h" -/* {{{ proto MessageFormatter MesssageFormatter::create( string $locale, string $pattern ) - * Create formatter. }}} */ -/* {{{ proto MessageFormatter msgfmt_create( string $locale, string $pattern ) - * Create formatter. - */ -PHP_FUNCTION( msgfmt_create ) +/* {{{ */ +static msgfmt_ctor(INTERNAL_FUNCTION_PARAMETERS) { char* locale; int locale_len = 0; @@ -41,25 +37,18 @@ PHP_FUNCTION( msgfmt_create ) MessageFormatter_object* mfo; intl_error_reset( NULL TSRMLS_CC ); - + object = return_value; // Parse parameters. if( zend_parse_parameters( ZEND_NUM_ARGS() TSRMLS_CC, "su", &locale, &locale_len, &spattern, &spattern_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(locale_len); - // Create a MessageFormatter object and save the ICU formatter into it. - if( ( object = getThis() ) == NULL ) - object = return_value; - - if( Z_TYPE_P( object ) != IS_OBJECT ) - object_init_ex( object, MessageFormatter_ce_ptr ); - + INTL_CHECK_LOCALE_LEN_OBJ(locale_len, return_value); MSG_FORMAT_METHOD_FETCH_OBJECT; // Convert pattern (if specified) to UTF-16. @@ -70,11 +59,8 @@ PHP_FUNCTION( msgfmt_create ) (mfo)->mf_data.orig_format = eustrndup(spattern, spattern_len); (mfo)->mf_data.orig_format_len = spattern_len; - if(msfgotmat_fix_quotes(&spattern, &spattern_len, &INTL_DATA_ERROR_CODE(mfo), &free_pattern) != SUCCESS) { - intl_error_set( NULL, U_INVALID_FORMAT_ERROR, - "msgfmt_create: error converting pattern to quote-friendly format", 0 TSRMLS_CC ); - zval_dtor(return_value); - RETURN_NULL(); + if(msgformat_fix_quotes(&spattern, &spattern_len, &INTL_DATA_ERROR_CODE(mfo), &free_pattern) != SUCCESS) { + INTL_CTOR_CHECK_STATUS(mfo, "msgfmt_create: error converting pattern to quote-friendly format"); } // Create an ICU message formatter. @@ -83,13 +69,19 @@ PHP_FUNCTION( msgfmt_create ) efree(spattern); } - if( U_FAILURE( INTL_DATA_ERROR_CODE((mfo)) ) ) - { - intl_error_set( NULL, INTL_DATA_ERROR_CODE( mfo ), - "msgfmt_create: message formatter creation failed", 0 TSRMLS_CC ); - zval_dtor(return_value); - RETURN_NULL(); - } + INTL_CTOR_CHECK_STATUS(mfo, "msgfmt_create: message formatter creation failed"); +} +/* }}} */ + +/* {{{ proto MessageFormatter MesssageFormatter::create( string $locale, string $pattern ) + * Create formatter. }}} */ +/* {{{ proto MessageFormatter msgfmt_create( string $locale, string $pattern ) + * Create formatter. + */ +PHP_FUNCTION( msgfmt_create ) +{ + object_init_ex( return_value, MessageFormatter_ce_ptr ); + msgfmt_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU); } /* }}} */ @@ -98,63 +90,8 @@ PHP_FUNCTION( msgfmt_create ) */ PHP_METHOD( MessageFormatter, __construct ) { - char* locale; - int locale_len; - UChar* spattern = NULL; - int spattern_len = 0; - zval* object; - int free_pattern = 0; - MessageFormatter_object* mfo; - - intl_error_reset( NULL TSRMLS_CC ); - - object = getThis(); - - // Parse parameters. - if( zend_parse_parameters( ZEND_NUM_ARGS() TSRMLS_CC, "su", - &locale, &locale_len, &spattern, &spattern_len ) == FAILURE ) - { - intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, - "__construct: unable to parse input params", 0 TSRMLS_CC ); - zval_dtor(object); - ZVAL_NULL(object); - RETURN_NULL(); - } - - INTL_CHECK_LOCALE_LEN_OBJ(locale_len, object); - mfo = (MessageFormatter_object *) zend_object_store_get_object( object TSRMLS_CC ); - - intl_error_reset( &mfo->mf_data.error TSRMLS_CC ); - - if(locale_len == 0) { - locale = UG(default_locale); - } - - (mfo)->mf_data.orig_format = eustrndup(spattern, spattern_len); - (mfo)->mf_data.orig_format_len = spattern_len; - - if(msfgotmat_fix_quotes(&spattern, &spattern_len, &INTL_DATA_ERROR_CODE(mfo), &free_pattern) != SUCCESS) { - intl_error_set( NULL, U_INVALID_FORMAT_ERROR, - "__construct: error converting pattern to quote-friendly format", 0 TSRMLS_CC ); - zval_dtor(object); - ZVAL_NULL(object); - RETURN_NULL(); - } - - // Create an ICU message formatter. - MSG_FORMAT_OBJECT(mfo) = umsg_open(spattern, spattern_len, locale, NULL, &INTL_DATA_ERROR_CODE(mfo)); - if(free_pattern) { - efree(spattern); - } - - if( U_FAILURE( INTL_DATA_ERROR_CODE((mfo)) ) ) - { - intl_error_set( NULL, INTL_DATA_ERROR_CODE(mfo), - "__construct: message formatter creation failed", 0 TSRMLS_CC ); - zval_dtor(object); - ZVAL_NULL(object); - RETURN_NULL(); - } + return_value = getThis(); + msgfmt_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU); } /* }}} */ diff --git a/ext/intl/msgformat/msgformat_attr.c b/ext/intl/msgformat/msgformat_attr.c index e560b62a42..b5b28e32db 100755 --- a/ext/intl/msgformat/msgformat_attr.c +++ b/ext/intl/msgformat/msgformat_attr.c @@ -82,7 +82,7 @@ PHP_FUNCTION( msgfmt_set_pattern ) mfo->mf_data.orig_format = eustrndup(svalue, slength); mfo->mf_data.orig_format_len = slength; - if(msfgotmat_fix_quotes(&svalue, &slength, &INTL_DATA_ERROR_CODE(mfo), &free_pattern) != SUCCESS) { + if(msgformat_fix_quotes(&svalue, &slength, &INTL_DATA_ERROR_CODE(mfo), &free_pattern) != SUCCESS) { intl_error_set( NULL, U_INVALID_FORMAT_ERROR, "msgfmt_set_pattern: error converting pattern to quote-friendly format", 0 TSRMLS_CC ); RETURN_FALSE; diff --git a/ext/intl/msgformat/msgformat_data.c b/ext/intl/msgformat/msgformat_data.c index cdb5412993..100e66a0df 100755 --- a/ext/intl/msgformat/msgformat_data.c +++ b/ext/intl/msgformat/msgformat_data.c @@ -69,7 +69,7 @@ msgformat_data* msgformat_data_create( TSRMLS_D ) } /* }}} */ -int msfgotmat_fix_quotes(UChar **spattern, uint32_t *spattern_len, UErrorCode *ec, int *free_pattern) +int msgformat_fix_quotes(UChar **spattern, uint32_t *spattern_len, UErrorCode *ec, int *free_pattern) { *free_pattern = 0; if(*spattern && *spattern_len && u_strchr(*spattern, (UChar)'\'')) { diff --git a/ext/intl/msgformat/msgformat_data.h b/ext/intl/msgformat/msgformat_data.h index dd1d392a2e..578878f319 100755 --- a/ext/intl/msgformat/msgformat_data.h +++ b/ext/intl/msgformat/msgformat_data.h @@ -36,6 +36,6 @@ typedef struct { msgformat_data* msgformat_data_create( TSRMLS_D ); void msgformat_data_init( msgformat_data* mf_data TSRMLS_DC ); void msgformat_data_free( msgformat_data* mf_data TSRMLS_DC ); -int msfgotmat_fix_quotes(UChar **spattern, uint32_t *spattern_len, UErrorCode *ec, int *free_pattern); +int msgformat_fix_quotes(UChar **spattern, uint32_t *spattern_len, UErrorCode *ec, int *free_pattern); #endif // MSG_FORMAT_DATA_H diff --git a/ext/intl/msgformat/msgformat_format.c b/ext/intl/msgformat/msgformat_format.c index c7533d5a69..7b172fcf4a 100755 --- a/ext/intl/msgformat/msgformat_format.c +++ b/ext/intl/msgformat/msgformat_format.c @@ -135,7 +135,7 @@ PHP_FUNCTION( msgfmt_format_message ) slocale = UG(default_locale); } - if(msfgotmat_fix_quotes(&spattern, &spattern_len, &INTL_DATA_ERROR_CODE(mfo), &free_pattern) != SUCCESS) { + if(msgformat_fix_quotes(&spattern, &spattern_len, &INTL_DATA_ERROR_CODE(mfo), &free_pattern) != SUCCESS) { intl_error_set( NULL, U_INVALID_FORMAT_ERROR, "msgfmt_format_message: error converting pattern to quote-friendly format", 0 TSRMLS_CC ); RETURN_FALSE; diff --git a/ext/intl/msgformat/msgformat_parse.c b/ext/intl/msgformat/msgformat_parse.c index 3601cfd1e4..10eaba1bab 100755 --- a/ext/intl/msgformat/msgformat_parse.c +++ b/ext/intl/msgformat/msgformat_parse.c @@ -106,7 +106,7 @@ PHP_FUNCTION( msgfmt_parse_message ) slocale = UG(default_locale); } - if(msfgotmat_fix_quotes(&spattern, &spattern_len, &INTL_DATA_ERROR_CODE(mfo), &free_pattern) != SUCCESS) { + if(msgformat_fix_quotes(&spattern, &spattern_len, &INTL_DATA_ERROR_CODE(mfo), &free_pattern) != SUCCESS) { intl_error_set( NULL, U_INVALID_FORMAT_ERROR, "msgfmt_parse_message: error converting pattern to quote-friendly format", 0 TSRMLS_CC ); RETURN_FALSE; diff --git a/ext/intl/tests/collator_asort.phpt b/ext/intl/tests/collator_asort.phpt index f302e514cd..d8b3f07b33 100755 --- a/ext/intl/tests/collator_asort.phpt +++ b/ext/intl/tests/collator_asort.phpt @@ -34,10 +34,7 @@ function sort_arrays( $locale, $test_arrays, $sort_flag = Collator::SORT_REGULAR "\n Result: " . dump_str( $res_val ); // Preppend test signature to output string - if( unicode_semantics() ) $md5 = md5( unicode_encode( $res_dump, 'utf-8' ) ); - else - $md5 = md5( $res_dump ); global $test_num; diff --git a/ext/intl/tests/collator_sort.phpt b/ext/intl/tests/collator_sort.phpt index f336d2742d..580ac347d2 100755 --- a/ext/intl/tests/collator_sort.phpt +++ b/ext/intl/tests/collator_sort.phpt @@ -35,10 +35,7 @@ function sort_arrays( $locale, $arrays, $sort_flag = Collator::SORT_REGULAR ) "\n Result: " . dump_str( $res_val ); // Preppend test signature to output string - if( unicode_semantics() ) $md5 = md5( unicode_encode( $res_dump, 'utf-8' ) ); - else - $md5 = md5( $res_dump ); global $test_num; diff --git a/ext/intl/tests/collator_sort_with_sort_keys.phpt b/ext/intl/tests/collator_sort_with_sort_keys.phpt index 71afca314b..04aa0a8902 100755 --- a/ext/intl/tests/collator_sort_with_sort_keys.phpt +++ b/ext/intl/tests/collator_sort_with_sort_keys.phpt @@ -36,10 +36,7 @@ function sort_arrays( $locale, $arrays ) // Preppend test signature to output string - if( unicode_semantics() ) $md5 = md5( unicode_encode( $res_dump, 'utf-8' ) ); - else - $md5 = md5( $res_dump ); global $test_num; diff --git a/ext/intl/tests/formatter_fail.phpt b/ext/intl/tests/formatter_fail.phpt index b435a57d75..1fe5769879 100755 --- a/ext/intl/tests/formatter_fail.phpt +++ b/ext/intl/tests/formatter_fail.phpt @@ -52,28 +52,28 @@ foreach($args as $arg) { ?> --EXPECTF-- Warning: NumberFormatter::__construct() expects at least 2 parameters, 0 given in %s on line %d -'__construct: unable to parse input params: U_ILLEGAL_ARGUMENT_ERROR' +'numfmt_create: unable to parse input parameters: U_ILLEGAL_ARGUMENT_ERROR' Warning: numfmt_create() expects at least 2 parameters, 0 given in %s on line %d 'numfmt_create: unable to parse input parameters: U_ILLEGAL_ARGUMENT_ERROR' Warning: NumberFormatter::create() expects at least 2 parameters, 0 given in %s on line %d 'numfmt_create: unable to parse input parameters: U_ILLEGAL_ARGUMENT_ERROR' -'__construct: number formatter creation failed: U_UNSUPPORTED_ERROR' +'numfmt_create: number formatter creation failed: U_UNSUPPORTED_ERROR' 'numfmt_create: number formatter creation failed: U_UNSUPPORTED_ERROR' 'numfmt_create: number formatter creation failed: U_UNSUPPORTED_ERROR' Warning: NumberFormatter::__construct() expects parameter 1 to be binary string, array given in %s on line %d -'__construct: unable to parse input params: U_ILLEGAL_ARGUMENT_ERROR' +'numfmt_create: unable to parse input parameters: U_ILLEGAL_ARGUMENT_ERROR' Warning: NumberFormatter::create() expects parameter 1 to be binary string, array given in %s on line %d 'numfmt_create: unable to parse input parameters: U_ILLEGAL_ARGUMENT_ERROR' Warning: numfmt_create() expects parameter 1 to be binary string, array given in %s on line %d 'numfmt_create: unable to parse input parameters: U_ILLEGAL_ARGUMENT_ERROR' -'__construct: number formatter creation failed: U_UNSUPPORTED_ERROR' 'numfmt_create: number formatter creation failed: U_UNSUPPORTED_ERROR' 'numfmt_create: number formatter creation failed: U_UNSUPPORTED_ERROR' -'__construct: number formatter creation failed: U_MEMORY_ALLOCATION_ERROR' +'numfmt_create: number formatter creation failed: U_UNSUPPORTED_ERROR' +'numfmt_create: number formatter creation failed: U_MEMORY_ALLOCATION_ERROR' 'numfmt_create: number formatter creation failed: U_MEMORY_ALLOCATION_ERROR' 'numfmt_create: number formatter creation failed: U_MEMORY_ALLOCATION_ERROR' diff --git a/ext/intl/tests/grapheme.phpt b/ext/intl/tests/grapheme.phpt index b5c0bdb833..0427fb0035 100755 --- a/ext/intl/tests/grapheme.phpt +++ b/ext/intl/tests/grapheme.phpt @@ -1,5 +1,7 @@ --TEST-- grapheme() +--INI-- +unicode.runtime_encoding="utf-8" --SKIPIF-- --FILE-- @@ -9,35 +11,37 @@ grapheme() * Test grapheme functions (procedural only) */ +function b_urlencode($s) { return urlencode((binary)$s); } + function ut_main() { $res_str = ''; - $char_a_diaeresis = "\xC3\xA4"; // 'LATIN SMALL LETTER A WITH DIAERESIS' (U+00E4) - $char_a_ring = "\xC3\xA5"; // 'LATIN SMALL LETTER A WITH RING ABOVE' (U+00E5) - $char_o_diaeresis = "\xC3\xB6"; // 'LATIN SMALL LETTER O WITH DIAERESIS' (U+00F6) - $char_O_diaeresis = "\xC3\x96"; // 'LATIN CAPITAL LETTER O WITH DIAERESIS' (U+00D6) + $char_a_diaeresis = b"\xC3\xA4"; // 'LATIN SMALL LETTER A WITH DIAERESIS' (U+00E4) + $char_a_ring = b"\xC3\xA5"; // 'LATIN SMALL LETTER A WITH RING ABOVE' (U+00E5) + $char_o_diaeresis = b"\xC3\xB6"; // 'LATIN SMALL LETTER O WITH DIAERESIS' (U+00F6) + $char_O_diaeresis = b"\xC3\x96"; // 'LATIN CAPITAL LETTER O WITH DIAERESIS' (U+00D6) - $char_angstrom_sign = "\xE2\x84\xAB"; // 'ANGSTROM SIGN' (U+212B) - $char_A_ring = "\xC3\x85"; // 'LATIN CAPITAL LETTER A WITH RING ABOVE' (U+00C5) + $char_angstrom_sign = b"\xE2\x84\xAB"; // 'ANGSTROM SIGN' (U+212B) + $char_A_ring = b"\xC3\x85"; // 'LATIN CAPITAL LETTER A WITH RING ABOVE' (U+00C5) - $char_ohm_sign = "\xE2\x84\xA6"; // 'OHM SIGN' (U+2126) - $char_omega = "\xCE\xA9"; // 'GREEK CAPITAL LETTER OMEGA' (U+03A9) + $char_ohm_sign = b"\xE2\x84\xA6"; // 'OHM SIGN' (U+2126) + $char_omega = b"\xCE\xA9"; // 'GREEK CAPITAL LETTER OMEGA' (U+03A9) - $char_combining_ring_above = "\xCC\x8A"; // 'COMBINING RING ABOVE' (U+030A) + $char_combining_ring_above = b"\xCC\x8A"; // 'COMBINING RING ABOVE' (U+030A) - $char_fi_ligature = "\xEF\xAC\x81"; // 'LATIN SMALL LIGATURE FI' (U+FB01) + $char_fi_ligature = b"\xEF\xAC\x81"; // 'LATIN SMALL LIGATURE FI' (U+FB01) - $char_long_s_dot = "\xE1\xBA\x9B"; // 'LATIN SMALL LETTER LONG S WITH DOT ABOVE' (U+1E9B) + $char_long_s_dot = b"\xE1\xBA\x9B"; // 'LATIN SMALL LETTER LONG S WITH DOT ABOVE' (U+1E9B) // the word 'hindi' using Devanagari characters: - $hindi = "\xe0\xa4\xb9\xe0\xa4\xbf\xe0\xa4\xa8\xe0\xa5\x8d\xe0\xa4\xa6\xe0\xa5\x80"; + $hindi = b"\xe0\xa4\xb9\xe0\xa4\xbf\xe0\xa4\xa8\xe0\xa5\x8d\xe0\xa4\xa6\xe0\xa5\x80"; - $char_a_ring_nfd = "a\xCC\x8A"; - $char_A_ring_nfd = "A\xCC\x8A"; - $char_o_diaeresis_nfd = "o\xCC\x88"; - $char_O_diaeresis_nfd = "O\xCC\x88"; - $char_diaeresis = "\xCC\x88"; + $char_a_ring_nfd = b"a\xCC\x8A"; + $char_A_ring_nfd = b"A\xCC\x8A"; + $char_o_diaeresis_nfd = b"o\xCC\x88"; + $char_O_diaeresis_nfd = b"O\xCC\x88"; + $char_diaeresis = b"\xCC\x88"; //===================================================================================== $res_str .= "\n" . 'function grapheme_strlen($string) {}' . "\n\n"; @@ -95,8 +99,8 @@ function ut_main() ); foreach( $tests as $test ) { - $arg1 = urlencode($test[1]); - $arg0 = urlencode($test[0]); + $arg1 = b_urlencode($test[1]); + $arg0 = b_urlencode($test[0]); $res_str .= "find \"$arg1\" in \"$arg0\" - grapheme_strpos"; if ( 3 == count( $test ) ) { $result = grapheme_strpos($test[0], $test[1]); @@ -159,8 +163,8 @@ function ut_main() ); foreach( $tests as $test ) { - $arg1 = urlencode($test[1]); - $arg0 = urlencode($test[0]); + $arg1 = b_urlencode($test[1]); + $arg0 = b_urlencode($test[0]); $res_str .= "find \"$arg1\" in \"$arg0\" - grapheme_stripos"; if ( 3 == count( $test ) ) { $result = grapheme_stripos($test[0], $test[1]); @@ -225,8 +229,8 @@ function ut_main() ); foreach( $tests as $test ) { - $arg1 = urlencode($test[1]); - $arg0 = urlencode($test[0]); + $arg1 = b_urlencode($test[1]); + $arg0 = b_urlencode($test[0]); $res_str .= "find \"$arg1\" in \"$arg0\" - grapheme_strrpos"; if ( 3 == count( $test ) ) { $result = grapheme_strrpos($test[0], $test[1]); @@ -290,8 +294,8 @@ function ut_main() ); foreach( $tests as $test ) { - $arg1 = urlencode($test[1]); - $arg0 = urlencode($test[0]); + $arg1 = b_urlencode($test[1]); + $arg0 = b_urlencode($test[0]); $res_str .= "find \"$arg1\" in \"$arg0\" - grapheme_strripos"; if ( 3 == count( $test ) ) { $result = grapheme_strripos($test[0], $test[1]); @@ -386,7 +390,7 @@ function ut_main() ); foreach( $tests as $test ) { - $arg0 = urlencode($test[0]); + $arg0 = b_urlencode($test[0]); $res_str .= "substring of \"$arg0\" from \"$test[1]\" - grapheme_substr"; if ( 3 == count( $test ) ) { $result = grapheme_substr($test[0], $test[1]); @@ -400,9 +404,9 @@ function ut_main() $res_str .= 'false'; } else { - $res_str .= urlencode($result); + $res_str .= b_urlencode($result); } - $res_str .= " == " . urlencode($test[count($test)-1]) . check_result($result, $test[count($test)-1]) . "\n"; + $res_str .= " == " . b_urlencode($test[count($test)-1]) . check_result($result, $test[count($test)-1]) . "\n"; } @@ -450,8 +454,8 @@ function ut_main() ); foreach( $tests as $test ) { - $arg1 = urlencode($test[1]); - $arg0 = urlencode($test[0]); + $arg1 = b_urlencode($test[1]); + $arg0 = b_urlencode($test[0]); $res_str .= "find \"$arg1\" in \"$arg0\" - grapheme_strstr"; if ( 3 == count( $test ) ) { $result = grapheme_strstr($test[0], $test[1]); @@ -465,9 +469,9 @@ function ut_main() $res_str .= 'false'; } else { - $res_str .= urlencode($result); + $res_str .= b_urlencode($result); } - $res_str .= " == " . urlencode($test[count($test)-1]) . check_result($result, $test[count($test)-1]) . "\n"; + $res_str .= " == " . b_urlencode($test[count($test)-1]) . check_result($result, $test[count($test)-1]) . "\n"; } @@ -515,8 +519,8 @@ function ut_main() ); foreach( $tests as $test ) { - $arg1 = urlencode($test[1]); - $arg0 = urlencode($test[0]); + $arg1 = b_urlencode($test[1]); + $arg0 = b_urlencode($test[0]); $res_str .= "find \"$arg1\" in \"$arg0\" - grapheme_stristr"; if ( 3 == count( $test ) ) { $result = grapheme_stristr($test[0], $test[1]); @@ -530,9 +534,9 @@ function ut_main() $res_str .= 'false'; } else { - $res_str .= urlencode($result); + $res_str .= b_urlencode($result); } - $res_str .= " == " . urlencode($test[count($test)-1]) . check_result($result, $test[count($test)-1]) . "\n"; + $res_str .= " == " . b_urlencode($test[count($test)-1]) . check_result($result, $test[count($test)-1]) . "\n"; } @@ -592,7 +596,7 @@ function ut_main() $next = -1; foreach( $tests as $test ) { - $arg0 = urlencode($test[0]); + $arg0 = b_urlencode($test[0]); $res_str .= "extract from \"$arg0\" \"$test[1]\" graphemes - grapheme_extract"; if ( 3 == count( $test ) ) { $result = grapheme_extract($test[0], $test[1]); @@ -610,9 +614,9 @@ function ut_main() $res_str .= 'false'; } else { - $res_str .= urlencode($result); + $res_str .= b_urlencode($result); } - $res_str .= " == " . urlencode($test[count($test)-1]) . check_result($result, $test[count($test)-1]); + $res_str .= " == " . b_urlencode($test[count($test)-1]) . check_result($result, $test[count($test)-1]); if ( 5 == count ( $test ) ) { $res_str .= " \$next=$next == $test[3] "; if ( $next != $test[3] ) { @@ -661,7 +665,7 @@ function ut_main() ); foreach( $tests as $test ) { - $arg0 = urlencode($test[0]); + $arg0 = b_urlencode($test[0]); $res_str .= "extract from \"$arg0\" \"$test[1]\" graphemes - grapheme_extract GRAPHEME_EXTR_MAXBYTES"; if ( 3 == count( $test ) ) { $result = grapheme_extract($test[0], $test[1], GRAPHEME_EXTR_MAXBYTES); @@ -675,9 +679,9 @@ function ut_main() $res_str .= 'false'; } else { - $res_str .= urlencode($result); + $res_str .= b_urlencode($result); } - $res_str .= " == " . urlencode($test[count($test)-1]) . check_result($result, $test[count($test)-1]) . "\n"; + $res_str .= " == " . b_urlencode($test[count($test)-1]) . check_result($result, $test[count($test)-1]) . "\n"; } @@ -725,7 +729,7 @@ function ut_main() ); foreach( $tests as $test ) { - $arg0 = urlencode($test[0]); + $arg0 = b_urlencode($test[0]); $res_str .= "extract from \"$arg0\" \"$test[1]\" graphemes - grapheme_extract GRAPHEME_EXTR_MAXCHARS"; if ( 3 == count( $test ) ) { $result = grapheme_extract($test[0], $test[1], GRAPHEME_EXTR_MAXCHARS); @@ -739,9 +743,9 @@ function ut_main() $res_str .= 'false'; } else { - $res_str .= urlencode($result); + $res_str .= b_urlencode($result); } - $res_str .= " == " . urlencode($test[count($test)-1]) . check_result($result, $test[count($test)-1]) . "\n"; + $res_str .= " == " . b_urlencode($test[count($test)-1]) . check_result($result, $test[count($test)-1]) . "\n"; } diff --git a/ext/intl/tests/msgfmt_fail.phpt b/ext/intl/tests/msgfmt_fail.phpt index ec287001f7..ee0f520299 100755 --- a/ext/intl/tests/msgfmt_fail.phpt +++ b/ext/intl/tests/msgfmt_fail.phpt @@ -1,5 +1,7 @@ --TEST-- msgfmt creation failures +--INI-- +display_errors=1 --SKIPIF-- --FILE-- @@ -58,7 +60,7 @@ foreach($args as $arg) { ?> --EXPECTF-- Warning: MessageFormatter::__construct() expects exactly 2 parameters, 0 given in %s on line %d -'__construct: unable to parse input params: U_ILLEGAL_ARGUMENT_ERROR' +'msgfmt_create: unable to parse input parameters: U_ILLEGAL_ARGUMENT_ERROR' Warning: msgfmt_create() expects exactly 2 parameters, 0 given in %s on line %d 'msgfmt_create: unable to parse input parameters: U_ILLEGAL_ARGUMENT_ERROR' @@ -67,34 +69,28 @@ Warning: MessageFormatter::create() expects exactly 2 parameters, 0 given in %s 'msgfmt_create: unable to parse input parameters: U_ILLEGAL_ARGUMENT_ERROR' Warning: MessageFormatter::__construct() expects exactly 2 parameters, 1 given in %s on line %d -'__construct: unable to parse input params: U_ILLEGAL_ARGUMENT_ERROR' +'msgfmt_create: unable to parse input parameters: U_ILLEGAL_ARGUMENT_ERROR' Warning: msgfmt_create() expects exactly 2 parameters, 1 given in %s on line %d 'msgfmt_create: unable to parse input parameters: U_ILLEGAL_ARGUMENT_ERROR' Warning: MessageFormatter::create() expects exactly 2 parameters, 1 given in %s on line %d 'msgfmt_create: unable to parse input parameters: U_ILLEGAL_ARGUMENT_ERROR' -'__construct: message formatter creation failed: U_ILLEGAL_ARGUMENT_ERROR' +'msgfmt_create: message formatter creation failed: U_ILLEGAL_ARGUMENT_ERROR' 'msgfmt_create: message formatter creation failed: U_ILLEGAL_ARGUMENT_ERROR' 'msgfmt_create: message formatter creation failed: U_ILLEGAL_ARGUMENT_ERROR' Warning: MessageFormatter::__construct() expects parameter 1 to be binary string, array given in %s on line %d -'__construct: unable to parse input params: U_ILLEGAL_ARGUMENT_ERROR' +'msgfmt_create: unable to parse input parameters: U_ILLEGAL_ARGUMENT_ERROR' Warning: MessageFormatter::create() expects parameter 1 to be binary string, array given in %s on line %d 'msgfmt_create: unable to parse input parameters: U_ILLEGAL_ARGUMENT_ERROR' Warning: msgfmt_create() expects parameter 1 to be binary string, array given in %s on line %d 'msgfmt_create: unable to parse input parameters: U_ILLEGAL_ARGUMENT_ERROR' -'__construct: message formatter creation failed: U_ILLEGAL_ARGUMENT_ERROR' 'msgfmt_create: message formatter creation failed: U_ILLEGAL_ARGUMENT_ERROR' 'msgfmt_create: message formatter creation failed: U_ILLEGAL_ARGUMENT_ERROR' -'__construct: message formatter creation failed: U_UNMATCHED_BRACES' +'msgfmt_create: message formatter creation failed: U_ILLEGAL_ARGUMENT_ERROR' +'msgfmt_create: message formatter creation failed: U_UNMATCHED_BRACES' 'msgfmt_create: message formatter creation failed: U_UNMATCHED_BRACES' 'msgfmt_create: message formatter creation failed: U_UNMATCHED_BRACES' - -Warning: Could not convert binary string to Unicode string (converter UTF-8 failed on bytes (0xD0) at offset 0) in %s on line %d - -Warning: Could not convert binary string to Unicode string (converter UTF-8 failed on bytes (0xD0) at offset 0) in %s on line %d - -Warning: Could not convert binary string to Unicode string (converter UTF-8 failed on bytes (0xD0) at offset 0) in %s on line %d diff --git a/ext/intl/tests/normalizer_normalize.phpt b/ext/intl/tests/normalizer_normalize.phpt index 5fa25c7d7a..9889e26ec2 100755 --- a/ext/intl/tests/normalizer_normalize.phpt +++ b/ext/intl/tests/normalizer_normalize.phpt @@ -1,5 +1,7 @@ --TEST-- normalize() +--INI-- +unicode.runtime_encoding="utf-8" --SKIPIF-- --FILE-- diff --git a/ext/intl/tests/ut_common.inc b/ext/intl/tests/ut_common.inc index bd4f13b3ee..2eaff1e165 100755 --- a/ext/intl/tests/ut_common.inc +++ b/ext/intl/tests/ut_common.inc @@ -84,8 +84,6 @@ function dump_str( $val, $use_quotes = true ) $q = ''; if( $use_quotes ) $q = "'"; - if( is_unicode( $val ) && !unicode_semantics() ) - return $q . unicode_encode( $val, 'utf-8' ) . $q; if( is_string( $val ) ) return $q . "$val" . $q; @@ -107,9 +105,7 @@ function dump_array( $a ) else $b .= " '$key' => "; - if( is_unicode( $val ) && !unicode_semantics() ) - $b .= "'" . unicode_encode( $val, 'utf-8' ) . "'"; - elseif( is_null( $val ) ) + if( is_null( $val ) ) $b .= "NULL"; elseif( is_string( $val ) ) $b .= "'" . "$val" . "'"; -- 2.40.0