@@ -38,8 +38,6 @@ static void collator_convert_hash_item_from_utf8_to_utf16(
38
38
{
39
39
const char * old_val ;
40
40
size_t old_val_len ;
41
- UChar * new_val = NULL ;
42
- int32_t new_val_len = 0 ;
43
41
zval znew_val ;
44
42
45
43
/* Process string values only. */
@@ -49,17 +47,13 @@ static void collator_convert_hash_item_from_utf8_to_utf16(
49
47
old_val = Z_STRVAL_P ( hashData );
50
48
old_val_len = Z_STRLEN_P ( hashData );
51
49
52
- /* Convert it from UTF-8 to UTF-16LE and save the result to new_val[_len] . */
53
- intl_convert_utf8_to_utf16 ( & new_val , & new_val_len , old_val , old_val_len , status );
50
+ /* Convert it from UTF-8 to UTF-16LE. */
51
+ zend_string * zstr = intl_convert_utf8_to_utf16_zstr ( old_val , old_val_len , status );
54
52
if ( U_FAILURE ( * status ) )
55
53
return ;
56
54
57
55
/* Update current hash item with the converted value. */
58
- ZVAL_STRINGL ( & znew_val , (char * )new_val , UBYTES (new_val_len + 1 ) );
59
- //???
60
- efree (new_val );
61
- /* hack to fix use of initialized value */
62
- Z_STRLEN (znew_val ) = Z_STRLEN (znew_val ) - UBYTES (1 );
56
+ ZVAL_NEW_STR ( & znew_val , zstr );
63
57
64
58
if ( hashKey )
65
59
{
@@ -176,23 +170,19 @@ zval* collator_convert_zstr_utf16_to_utf8( zval* utf16_zval, zval *rv )
176
170
177
171
zend_string * collator_convert_zstr_utf8_to_utf16 (zend_string * utf8_str )
178
172
{
179
- UChar * ustr = NULL ;
180
- int32_t ustr_len = 0 ;
181
173
UErrorCode status = U_ZERO_ERROR ;
182
174
183
175
/* Convert the string to UTF-16. */
184
- intl_convert_utf8_to_utf16 (
185
- & ustr , & ustr_len ,
176
+ zend_string * zstr = intl_convert_utf8_to_utf16_zstr (
186
177
ZSTR_VAL (utf8_str ), ZSTR_LEN (utf8_str ),
187
178
& status );
188
179
// FIXME Or throw error or use intl internal error handler
189
180
if (U_FAILURE (status )) {
190
181
php_error (E_WARNING ,
191
182
"Error casting object to string in collator_convert_zstr_utf8_to_utf16()" );
183
+ zstr = ZSTR_EMPTY_ALLOC ();
192
184
}
193
185
194
- zend_string * zstr = zend_string_init ((char * ) ustr , UBYTES (ustr_len ), 0 );
195
- efree ((char * )ustr );
196
186
return zstr ;
197
187
}
198
188
@@ -203,8 +193,6 @@ zval* collator_convert_object_to_string( zval* obj, zval *rv )
203
193
{
204
194
zval * zstr = NULL ;
205
195
UErrorCode status = U_ZERO_ERROR ;
206
- UChar * ustr = NULL ;
207
- int32_t ustr_len = 0 ;
208
196
209
197
/* Bail out if it's not an object. */
210
198
if ( Z_TYPE_P ( obj ) != IS_OBJECT )
@@ -229,25 +217,20 @@ zval* collator_convert_object_to_string( zval* obj, zval *rv )
229
217
}
230
218
231
219
/* Convert the string to UTF-16. */
232
- intl_convert_utf8_to_utf16 (
233
- & ustr , & ustr_len ,
220
+ zend_string * converted_str = intl_convert_utf8_to_utf16_zstr (
234
221
Z_STRVAL_P ( zstr ), Z_STRLEN_P ( zstr ),
235
222
& status );
236
223
// FIXME Or throw error or use intl internal error handler
237
- if ( U_FAILURE ( status ) )
224
+ if ( U_FAILURE ( status ) ) {
238
225
php_error ( E_WARNING , "Error casting object to string in collator_convert_object_to_string()" );
226
+ converted_str = ZSTR_EMPTY_ALLOC ();
227
+ }
239
228
240
229
/* Cleanup zstr to hold utf16 string. */
241
230
zval_ptr_dtor_str ( zstr );
242
231
243
232
/* Set string. */
244
- ZVAL_STRINGL ( zstr , (char * )ustr , UBYTES (ustr_len ));
245
- //???
246
- efree ((char * )ustr );
247
-
248
- /* Don't free ustr cause it's set in zstr without copy.
249
- * efree( ustr );
250
- */
233
+ ZVAL_STR ( zstr , converted_str );
251
234
252
235
return zstr ;
253
236
}
0 commit comments