|
17 | 17 | #include "config.h"
|
18 | 18 | #endif
|
19 | 19 |
|
20 |
| -#include <unicode/ustring.h> |
21 | 20 | #include <unicode/udat.h>
|
22 |
| -#include <unicode/ucal.h> |
23 | 21 |
|
24 | 22 | #include "php_intl.h"
|
25 |
| -#include "intl_convert.h" |
26 | 23 | #include "dateformat_class.h"
|
27 | 24 | #include "dateformat.h"
|
28 | 25 |
|
@@ -67,157 +64,6 @@ void dateformat_register_constants( INIT_FUNC_ARGS )
|
67 | 64 | }
|
68 | 65 | /* }}} */
|
69 | 66 |
|
70 |
| -/* {{{ */ |
71 |
| -static void datefmt_ctor(INTERNAL_FUNCTION_PARAMETERS) |
72 |
| -{ |
73 |
| - char* locale; |
74 |
| - int locale_len = 0; |
75 |
| - zval* object; |
76 |
| - long date_type = 0; |
77 |
| - long time_type = 0; |
78 |
| - long calendar = UCAL_GREGORIAN; |
79 |
| - char* timezone_str = NULL; |
80 |
| - int timezone_str_len = 0; |
81 |
| - char* pattern_str = NULL; |
82 |
| - int pattern_str_len = 0; |
83 |
| - UChar* svalue = NULL; /* UTF-16 pattern_str */ |
84 |
| - int slength = 0; |
85 |
| - UChar* timezone_utf16 = NULL; /* UTF-16 timezone_str */ |
86 |
| - int timezone_utf16_len = 0; |
87 |
| - UCalendar ucal_obj = NULL; |
88 |
| - IntlDateFormatter_object* dfo; |
89 |
| - |
90 |
| - intl_error_reset( NULL TSRMLS_CC ); |
91 |
| - object = return_value; |
92 |
| - /* Parse parameters. */ |
93 |
| - if( zend_parse_parameters( ZEND_NUM_ARGS() TSRMLS_CC, "sll|sls", |
94 |
| - &locale, &locale_len, &date_type, &time_type, &timezone_str, &timezone_str_len, &calendar,&pattern_str, &pattern_str_len ) == FAILURE ) |
95 |
| - { |
96 |
| - intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, "datefmt_create: unable to parse input parameters", 0 TSRMLS_CC ); |
97 |
| - zval_dtor(return_value); |
98 |
| - RETURN_NULL(); |
99 |
| - } |
100 |
| - |
101 |
| - INTL_CHECK_LOCALE_LEN_OBJ(locale_len, return_value); |
102 |
| - |
103 |
| - if (calendar != UCAL_TRADITIONAL && calendar != UCAL_GREGORIAN) { |
104 |
| - intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, "datefmt_create: " |
105 |
| - "invalid value for calendar type; it must be one of " |
106 |
| - "IntlDateFormatter::TRADITIONAL (locale's default calendar) " |
107 |
| - "or IntlDateFormatter::GREGORIAN", 0 TSRMLS_CC); |
108 |
| - goto error; |
109 |
| - } |
110 |
| - |
111 |
| - DATE_FORMAT_METHOD_FETCH_OBJECT; |
112 |
| - |
113 |
| - if (DATE_FORMAT_OBJECT(dfo) != NULL) { |
114 |
| - intl_errors_set(INTL_DATA_ERROR_P(dfo), U_ILLEGAL_ARGUMENT_ERROR, |
115 |
| - "datefmt_create: cannot call constructor twice", 0 TSRMLS_CC); |
116 |
| - return; |
117 |
| - } |
118 |
| - |
119 |
| - /* Convert pattern (if specified) to UTF-16. */ |
120 |
| - if( pattern_str && pattern_str_len>0 ){ |
121 |
| - intl_convert_utf8_to_utf16(&svalue, &slength, |
122 |
| - pattern_str, pattern_str_len, &INTL_DATA_ERROR_CODE(dfo)); |
123 |
| - if (U_FAILURE(INTL_DATA_ERROR_CODE(dfo))) { |
124 |
| - /* object construction -> only set global error */ |
125 |
| - intl_error_set(NULL, INTL_DATA_ERROR_CODE(dfo), "datefmt_create: " |
126 |
| - "error converting pattern to UTF-16", 0 TSRMLS_CC); |
127 |
| - goto error; |
128 |
| - } |
129 |
| - } |
130 |
| - |
131 |
| - /* resources allocated from now on */ |
132 |
| - |
133 |
| - /* Convert pattern (if specified) to UTF-16. */ |
134 |
| - if( timezone_str && timezone_str_len >0 ){ |
135 |
| - intl_convert_utf8_to_utf16(&timezone_utf16, &timezone_utf16_len, |
136 |
| - timezone_str, timezone_str_len, &INTL_DATA_ERROR_CODE(dfo)); |
137 |
| - if (U_FAILURE(INTL_DATA_ERROR_CODE(dfo))) { |
138 |
| - intl_error_set(NULL, INTL_DATA_ERROR_CODE(dfo), "datefmt_create: " |
139 |
| - "error converting timezone_str to UTF-16", 0 TSRMLS_CC); |
140 |
| - goto error; |
141 |
| - } |
142 |
| - } |
143 |
| - |
144 |
| - if(locale_len == 0) { |
145 |
| - locale = INTL_G(default_locale); |
146 |
| - } |
147 |
| - |
148 |
| - if( pattern_str && pattern_str_len>0 ){ |
149 |
| - DATE_FORMAT_OBJECT(dfo) = udat_open(UDAT_IGNORE, UDAT_IGNORE, locale, timezone_utf16, timezone_utf16_len, svalue, slength, &INTL_DATA_ERROR_CODE(dfo)); |
150 |
| - } else { |
151 |
| - DATE_FORMAT_OBJECT(dfo) = udat_open(time_type, date_type, locale, timezone_utf16, timezone_utf16_len, svalue, slength, &INTL_DATA_ERROR_CODE(dfo)); |
152 |
| - } |
153 |
| - |
154 |
| - if (!U_FAILURE(INTL_DATA_ERROR_CODE(dfo))) { |
155 |
| - if (calendar != UCAL_TRADITIONAL) { |
156 |
| - ucal_obj = ucal_open(timezone_utf16, timezone_utf16_len, locale, |
157 |
| - calendar, &INTL_DATA_ERROR_CODE(dfo)); |
158 |
| - if (!U_FAILURE(INTL_DATA_ERROR_CODE(dfo))) { |
159 |
| - udat_setCalendar(DATE_FORMAT_OBJECT(dfo), ucal_obj); |
160 |
| - ucal_close(ucal_obj); |
161 |
| - } else { |
162 |
| - intl_error_set(NULL, INTL_DATA_ERROR_CODE(dfo), "datefmt_create" |
163 |
| - ": error opening calendar", 0 TSRMLS_CC); |
164 |
| - goto error; |
165 |
| - } |
166 |
| - } |
167 |
| - } else { |
168 |
| - intl_error_set(NULL, INTL_DATA_ERROR_CODE(dfo), "datefmt_create: date " |
169 |
| - "formatter creation failed", 0 TSRMLS_CC); |
170 |
| - goto error; |
171 |
| - } |
172 |
| - |
173 |
| - /* Set the class variables */ |
174 |
| - dfo->date_type = date_type; |
175 |
| - dfo->time_type = time_type; |
176 |
| - dfo->calendar = calendar; |
177 |
| - if( timezone_str && timezone_str_len > 0){ |
178 |
| - dfo->timezone_id = estrndup( timezone_str, timezone_str_len); |
179 |
| - } |
180 |
| - |
181 |
| -error: |
182 |
| - if (svalue) { |
183 |
| - efree(svalue); |
184 |
| - } |
185 |
| - if (timezone_utf16) { |
186 |
| - efree(timezone_utf16); |
187 |
| - } |
188 |
| - if (U_FAILURE(intl_error_get_code(NULL TSRMLS_CC))) { |
189 |
| - /* free_object handles partially constructed instances fine */ |
190 |
| - zval_dtor(return_value); |
191 |
| - RETVAL_NULL(); |
192 |
| - } |
193 |
| -} |
194 |
| -/* }}} */ |
195 |
| - |
196 |
| -/* {{{ proto IntlDateFormatter IntlDateFormatter::create(string $locale, long date_type, long time_type[, string $timezone_str, long $calendar, string $pattern] ) |
197 |
| - * Create formatter. }}} */ |
198 |
| -/* {{{ proto IntlDateFormatter datefmt_create(string $locale, long date_type, long time_type[, string $timezone_str, long $calendar, string $pattern] ) |
199 |
| - |
200 |
| - * Create formatter. |
201 |
| - */ |
202 |
| -PHP_FUNCTION( datefmt_create ) |
203 |
| -{ |
204 |
| - object_init_ex( return_value, IntlDateFormatter_ce_ptr ); |
205 |
| - datefmt_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU); |
206 |
| -} |
207 |
| -/* }}} */ |
208 |
| - |
209 |
| -/* {{{ proto void IntlDateFormatter::__construct(string $locale, long date_type, long time_type[, string $timezone_str, long $calendar, string $pattern]) |
210 |
| - * IntlDateFormatter object constructor. |
211 |
| - */ |
212 |
| -PHP_METHOD( IntlDateFormatter, __construct ) |
213 |
| -{ |
214 |
| - /* return_value param is being changed, therefore we will always return |
215 |
| - * NULL here */ |
216 |
| - return_value = getThis(); |
217 |
| - datefmt_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU); |
218 |
| -} |
219 |
| -/* }}} */ |
220 |
| - |
221 | 67 | /* {{{ proto int IntlDateFormatter::getErrorCode()
|
222 | 68 | * Get formatter's last error code. }}} */
|
223 | 69 | /* {{{ proto int datefmt_get_error_code( IntlDateFormatter $nf )
|
|
0 commit comments