diff options
author | Stanislav Malyshev <stas@php.net> | 2008-07-10 21:58:02 +0000 |
---|---|---|
committer | Stanislav Malyshev <stas@php.net> | 2008-07-10 21:58:02 +0000 |
commit | f7879630568ad396941d73de29f4b07f426d996b (patch) | |
tree | 9668d431db34631021213046aafc17e989d51182 /ext/intl/dateformat | |
parent | b82c9b946123c7279dccce97dc04f864b444e17f (diff) | |
download | php-git-f7879630568ad396941d73de29f4b07f426d996b.tar.gz |
fix date formatter positions (bug #14263)
Diffstat (limited to 'ext/intl/dateformat')
-rwxr-xr-x | ext/intl/dateformat/dateformat_class.c | 8 | ||||
-rwxr-xr-x | ext/intl/dateformat/dateformat_parse.c | 70 |
2 files changed, 50 insertions, 28 deletions
diff --git a/ext/intl/dateformat/dateformat_class.c b/ext/intl/dateformat/dateformat_class.c index e582467231..7a8611b9b7 100755 --- a/ext/intl/dateformat/dateformat_class.c +++ b/ext/intl/dateformat/dateformat_class.c @@ -86,6 +86,10 @@ zend_object_value IntlDateFormatter_object_create(zend_class_entry *ce TSRMLS_DC /* {{{ IntlDateFormatter_class_functions * Every 'IntlDateFormatter' class method has an entry in this table */ +static ZEND_BEGIN_ARG_INFO_EX( datefmt_parse_args, 0, 0, 1 ) + ZEND_ARG_INFO( 0, string ) + ZEND_ARG_INFO( 1, position ) +ZEND_END_ARG_INFO() static function_entry IntlDateFormatter_class_functions[] = { PHP_ME( IntlDateFormatter, __construct, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR ) @@ -102,8 +106,8 @@ static function_entry IntlDateFormatter_class_functions[] = { PHP_NAMED_FE( setLenient, ZEND_FN( datefmt_set_lenient ), NULL ) PHP_NAMED_FE( isLenient, ZEND_FN( datefmt_is_lenient ), NULL ) PHP_NAMED_FE( format, ZEND_FN( datefmt_format ), NULL ) - PHP_NAMED_FE( parse, ZEND_FN( datefmt_parse), NULL ) - PHP_NAMED_FE( localtime, ZEND_FN( datefmt_localtime ), NULL ) + PHP_NAMED_FE( parse, ZEND_FN( datefmt_parse), datefmt_parse_args ) + PHP_NAMED_FE( localtime, ZEND_FN( datefmt_localtime ), datefmt_parse_args ) PHP_NAMED_FE( getErrorCode, ZEND_FN( datefmt_get_error_code ), NULL ) PHP_NAMED_FE( getErrorMessage, ZEND_FN( datefmt_get_error_message ), NULL ) { NULL, NULL, NULL } diff --git a/ext/intl/dateformat/dateformat_parse.c b/ext/intl/dateformat/dateformat_parse.c index 0e9e936502..58394bb985 100755 --- a/ext/intl/dateformat/dateformat_parse.c +++ b/ext/intl/dateformat/dateformat_parse.c @@ -33,7 +33,7 @@ * 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 *mfo, char* text_to_parse , int32_t text_len, int32_t *parse_pos , zval *return_value TSRMLS_DC){ long result = 0; UDate timestamp =0; UChar* text_utf16 = NULL; @@ -43,7 +43,7 @@ static void internal_parse_to_timestamp(IntlDateFormatter_object *mfo, char* tex 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" ); - 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(mfo), text_utf16 , text_utf16_len , parse_pos , &INTL_DATA_ERROR_CODE(mfo)); if( text_utf16 ){ efree(text_utf16); } @@ -78,7 +78,7 @@ 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 *mfo, char* text_to_parse , int32_t text_len, int32_t *parse_pos , zval *return_value TSRMLS_DC){ UCalendar* parsed_calendar = NULL ; UChar* text_utf16 = NULL; int32_t text_utf16_len = 0; @@ -89,7 +89,7 @@ static void internal_parse_to_localtime(IntlDateFormatter_object *mfo, char* tex INTL_METHOD_CHECK_STATUS(mfo, "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)); + udat_parseCalendar( DATE_FORMAT_OBJECT(mfo), parsed_calendar , text_utf16 , text_utf16_len , parse_pos , &INTL_DATA_ERROR_CODE(mfo)); if( text_utf16 ){ efree(text_utf16); } @@ -116,66 +116,84 @@ static void internal_parse_to_localtime(IntlDateFormatter_object *mfo, char* tex /* }}} */ -/* {{{ proto integer IntlDateFormatter::parse( string $text_to_parse , int $parse_pos ) +/* {{{ proto integer IntlDateFormatter::parse( string $text_to_parse [, int $parse_pos] ) * Parse the string $value starting at parse_pos to a Unix timestamp -int }}}*/ -/* {{{ proto integer datefmt_parse( IntlDateFormatter $fmt, string $text_to_parse , int $parse_pos ) +/* {{{ proto integer datefmt_parse( IntlDateFormatter $fmt, string $text_to_parse [, int $parse_pos] ) * Parse the string $value starting at parse_pos to a Unix timestamp -int }}}*/ PHP_FUNCTION(datefmt_parse) { char* text_to_parse = NULL; int32_t text_len =0; - long parse_pos =0; + zval* z_parse_pos = NULL; + int32_t parse_pos = -1; DATE_FORMAT_METHOD_INIT_VARS; // Parse parameters. - if( zend_parse_method_parameters( ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os|l", - &object, IntlDateFormatter_ce_ptr, &text_to_parse , &text_len , &parse_pos ) == FAILURE ){ + if( zend_parse_method_parameters( ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os|z!", + &object, IntlDateFormatter_ce_ptr, &text_to_parse , &text_len , &z_parse_pos ) == FAILURE ){ intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, "datefmt_parse: unable to parse input params", 0 TSRMLS_CC ); RETURN_FALSE; } - // Fetch the object. - DATE_FORMAT_METHOD_FETCH_OBJECT; - - internal_parse_to_timestamp( mfo, text_to_parse , text_len , - parse_pos , - return_value TSRMLS_CC); + // Fetch the object. + DATE_FORMAT_METHOD_FETCH_OBJECT; + if(z_parse_pos) { + convert_to_long(z_parse_pos); + parse_pos = (int32_t)Z_LVAL_P(z_parse_pos); + if(parse_pos > text_len) { + RETURN_FALSE; + } + } + internal_parse_to_timestamp( mfo, text_to_parse, text_len, z_parse_pos?&parse_pos:NULL, return_value TSRMLS_CC); + if(z_parse_pos) { + zval_dtor(z_parse_pos); + ZVAL_LONG(z_parse_pos, parse_pos); + } } /* }}} */ -/* {{{ proto integer IntlDateFormatter::localtime( string $text_to_parse, int $parse_pos ) +/* {{{ proto integer IntlDateFormatter::localtime( string $text_to_parse[, int $parse_pos] ) * Parse the string $value to a localtime array }}}*/ -/* {{{ proto integer datefmt_localtime( IntlDateFormatter $fmt, string $text_to_parse, int $parse_pos ) +/* {{{ proto integer datefmt_localtime( IntlDateFormatter $fmt, string $text_to_parse[, int $parse_pos ]) * Parse the string $value to a localtime array }}}*/ PHP_FUNCTION(datefmt_localtime) { char* text_to_parse = NULL; int32_t text_len =0; - long parse_pos =0; + zval* z_parse_pos = NULL; + int32_t parse_pos = -1; DATE_FORMAT_METHOD_INIT_VARS; // Parse parameters. - if( zend_parse_method_parameters( ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Osl", - &object, IntlDateFormatter_ce_ptr, &text_to_parse , &text_len , &parse_pos ) == FAILURE ){ + if( zend_parse_method_parameters( ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os|z!", + &object, IntlDateFormatter_ce_ptr, &text_to_parse , &text_len , &z_parse_pos ) == FAILURE ){ intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, "datefmt_parse_to_localtime: unable to parse input params", 0 TSRMLS_CC ); RETURN_FALSE; } - // Fetch the object. - DATE_FORMAT_METHOD_FETCH_OBJECT; - - internal_parse_to_localtime( mfo, text_to_parse , text_len , - parse_pos, - return_value TSRMLS_CC); + // Fetch the object. + DATE_FORMAT_METHOD_FETCH_OBJECT; + if(z_parse_pos) { + convert_to_long(z_parse_pos); + parse_pos = (int32_t)Z_LVAL_P(z_parse_pos); + if(parse_pos > text_len) { + RETURN_FALSE; + } + } + internal_parse_to_localtime( mfo, text_to_parse , text_len , z_parse_pos?&parse_pos:NULL, return_value TSRMLS_CC); + if(z_parse_pos) { + zval_dtor(z_parse_pos); + ZVAL_LONG(z_parse_pos, parse_pos); + } } /* }}} */ |