diff options
author | Felipe Pena <felipe@php.net> | 2008-08-11 19:48:00 +0000 |
---|---|---|
committer | Felipe Pena <felipe@php.net> | 2008-08-11 19:48:00 +0000 |
commit | eb1837d9de56547f76459397a930f2e812547448 (patch) | |
tree | 0c8be24ca5b3bd7fd3735fc30cb6529351c2ff2b /ext/intl/dateformat/dateformat_parse.c | |
parent | 6d083e2c39aa15f9740d041ca007ae2f86d2f10f (diff) | |
download | php-git-eb1837d9de56547f76459397a930f2e812547448.tar.gz |
MFH:
- Added arginfo
- Fixed WS
- Changed C++ comments to C comments
Diffstat (limited to 'ext/intl/dateformat/dateformat_parse.c')
-rwxr-xr-x | ext/intl/dateformat/dateformat_parse.c | 98 |
1 files changed, 47 insertions, 51 deletions
diff --git a/ext/intl/dateformat/dateformat_parse.c b/ext/intl/dateformat/dateformat_parse.c index 881e244a2c..3e05050760 100755 --- a/ext/intl/dateformat/dateformat_parse.c +++ b/ext/intl/dateformat/dateformat_parse.c @@ -39,9 +39,9 @@ static void internal_parse_to_timestamp(IntlDateFormatter_object *dfo, char* tex 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(dfo)); - INTL_METHOD_CHECK_STATUS(dfo, "Error converting timezone to UTF-16" ); + /* Convert 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(dfo), text_utf16 , text_utf16_len , parse_pos , &INTL_DATA_ERROR_CODE(dfo)); if( text_utf16 ){ @@ -50,7 +50,7 @@ static void internal_parse_to_timestamp(IntlDateFormatter_object *dfo, char* tex INTL_METHOD_CHECK_STATUS( dfo, "Date parsing failed" ); - //Since return is in sec. + /* Since return is in sec. */ result = (long )( timestamp / 1000 ); if( result != (timestamp/1000) ) { intl_error_set( NULL, U_BUFFER_OVERFLOW_ERROR, @@ -65,10 +65,10 @@ static void add_to_localtime_arr( IntlDateFormatter_object *dfo, zval* return_va 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 + /* since tm_year is years from 1900 */ add_assoc_long( return_value, key_name ,( calendar_field_val-1900) ); }else if( strcmp(key_name , CALENDAR_WDAY )==0 ){ - //since tm_wday starts from 0 whereas ICU WDAY start from 1 + /* since tm_wday starts from 0 whereas ICU WDAY start from 1 */ add_assoc_long( return_value, key_name ,( calendar_field_val-1) ); }else{ add_assoc_long( return_value, key_name , calendar_field_val ); @@ -79,26 +79,27 @@ static void add_to_localtime_arr( IntlDateFormatter_object *dfo, zval* return_va * Internal function which calls the udat_parseCalendar */ static void internal_parse_to_localtime(IntlDateFormatter_object *dfo, 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; + 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(dfo)); - INTL_METHOD_CHECK_STATUS(dfo, "Error converting timezone to UTF-16" ); + /* Convert 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(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); - } + 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( dfo, "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 entries from various fields of the obtained parsed_calendar */ 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); @@ -108,9 +109,9 @@ static void internal_parse_to_localtime(IntlDateFormatter_object *dfo, char* tex 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? + /* Is 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." ); + 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)); } /* }}} */ @@ -122,26 +123,24 @@ static void internal_parse_to_localtime(IntlDateFormatter_object *dfo, char* tex * 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; + zval* z_parse_pos = NULL; + int32_t parse_pos = -1; - char* text_to_parse = NULL; - int32_t text_len =0; - zval* z_parse_pos = NULL; - int32_t parse_pos = -1; - - DATE_FORMAT_METHOD_INIT_VARS; + DATE_FORMAT_METHOD_INIT_VARS; - // Parse parameters. - 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; - } + /* Parse parameters. */ + 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; + /* Fetch the object. */ + DATE_FORMAT_METHOD_FETCH_OBJECT; - if(z_parse_pos) { + 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) { @@ -162,25 +161,22 @@ PHP_FUNCTION(datefmt_parse) * Parse the string $value to a localtime array }}}*/ PHP_FUNCTION(datefmt_localtime) { + char* text_to_parse = NULL; + int32_t text_len =0; + zval* z_parse_pos = NULL; + int32_t parse_pos = -1; - char* text_to_parse = NULL; - int32_t text_len =0; - zval* z_parse_pos = NULL; - int32_t parse_pos = -1; - - DATE_FORMAT_METHOD_INIT_VARS; + DATE_FORMAT_METHOD_INIT_VARS; - // Parse parameters. + /* Parse parameters. */ 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; - } + &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; + /* Fetch the object. */ + DATE_FORMAT_METHOD_FETCH_OBJECT; if(z_parse_pos) { convert_to_long(z_parse_pos); |