@@ -256,9 +256,9 @@ PHP_NAMED_FUNCTION(zif_locale_set_default)
256
256
* common code shared by get_primary_language,get_script or get_region or get_variant
257
257
* result = 0 if error, 1 if successful , -1 if no value
258
258
*/
259
- static char * get_icu_value_internal ( const char * loc_name , char * tag_name , int * result , int fromParseLocale )
259
+ static zend_string * get_icu_value_internal ( const char * loc_name , char * tag_name , int * result , int fromParseLocale )
260
260
{
261
- char * tag_value = NULL ;
261
+ zend_string * tag_value = NULL ;
262
262
int32_t tag_value_len = 512 ;
263
263
264
264
int singletonPos = 0 ;
@@ -274,7 +274,7 @@ static char* get_icu_value_internal( const char* loc_name , char* tag_name, int*
274
274
grOffset = findOffset ( LOC_GRANDFATHERED , loc_name );
275
275
if ( grOffset >= 0 ){
276
276
if ( strcmp (tag_name , LOC_LANG_TAG )== 0 ){
277
- return estrdup (loc_name );
277
+ return zend_string_init (loc_name , strlen ( loc_name ), 0 );
278
278
} else {
279
279
/* Since Grandfathered , no value , do nothing , retutn NULL */
280
280
return NULL ;
@@ -285,7 +285,7 @@ static char* get_icu_value_internal( const char* loc_name , char* tag_name, int*
285
285
/* Handle singletons */
286
286
if ( strcmp (tag_name , LOC_LANG_TAG )== 0 ){
287
287
if ( strlen (loc_name )> 1 && (isIDPrefix (loc_name ) == 1 ) ){
288
- return estrdup (loc_name );
288
+ return zend_string_init (loc_name , strlen ( loc_name ), 0 );
289
289
}
290
290
}
291
291
@@ -308,24 +308,28 @@ static char* get_icu_value_internal( const char* loc_name , char* tag_name, int*
308
308
}
309
309
310
310
/* Proceed to ICU */
311
- do {
312
- tag_value = erealloc ( tag_value , buflen );
311
+ do {
312
+ if (tag_value ) {
313
+ tag_value = zend_string_realloc ( tag_value , buflen , 0 );
314
+ } else {
315
+ tag_value = zend_string_alloc ( buflen , 0 );
316
+ }
313
317
tag_value_len = buflen ;
314
318
315
319
if ( strcmp (tag_name , LOC_SCRIPT_TAG )== 0 ){
316
- buflen = uloc_getScript ( mod_loc_name ,tag_value , tag_value_len , & status );
320
+ buflen = uloc_getScript ( mod_loc_name , tag_value -> val , tag_value_len , & status );
317
321
}
318
322
if ( strcmp (tag_name , LOC_LANG_TAG )== 0 ){
319
- buflen = uloc_getLanguage ( mod_loc_name ,tag_value , tag_value_len , & status );
323
+ buflen = uloc_getLanguage ( mod_loc_name , tag_value -> val , tag_value_len , & status );
320
324
}
321
325
if ( strcmp (tag_name , LOC_REGION_TAG )== 0 ){
322
- buflen = uloc_getCountry ( mod_loc_name ,tag_value , tag_value_len , & status );
326
+ buflen = uloc_getCountry ( mod_loc_name , tag_value -> val , tag_value_len , & status );
323
327
}
324
328
if ( strcmp (tag_name , LOC_VARIANT_TAG )== 0 ){
325
- buflen = uloc_getVariant ( mod_loc_name ,tag_value , tag_value_len , & status );
329
+ buflen = uloc_getVariant ( mod_loc_name , tag_value -> val , tag_value_len , & status );
326
330
}
327
331
if ( strcmp (tag_name , LOC_CANONICALIZE_TAG )== 0 ){
328
- buflen = uloc_canonicalize ( mod_loc_name ,tag_value , tag_value_len , & status );
332
+ buflen = uloc_canonicalize ( mod_loc_name , tag_value -> val , tag_value_len , & status );
329
333
}
330
334
331
335
if ( U_FAILURE ( status ) ) {
@@ -337,7 +341,7 @@ static char* get_icu_value_internal( const char* loc_name , char* tag_name, int*
337
341
/* Error in retriving data */
338
342
* result = 0 ;
339
343
if ( tag_value ){
340
- efree ( tag_value );
344
+ zend_string_release ( tag_value );
341
345
}
342
346
if ( mod_loc_name ){
343
347
efree ( mod_loc_name );
@@ -350,7 +354,7 @@ static char* get_icu_value_internal( const char* loc_name , char* tag_name, int*
350
354
/* No value found */
351
355
* result = -1 ;
352
356
if ( tag_value ){
353
- efree ( tag_value );
357
+ zend_string_release ( tag_value );
354
358
}
355
359
if ( mod_loc_name ){
356
360
efree ( mod_loc_name );
@@ -363,6 +367,8 @@ static char* get_icu_value_internal( const char* loc_name , char* tag_name, int*
363
367
if ( mod_loc_name ){
364
368
efree ( mod_loc_name );
365
369
}
370
+
371
+ tag_value -> len = strlen (tag_value -> val );
366
372
return tag_value ;
367
373
}
368
374
/* }}} */
@@ -377,7 +383,7 @@ static void get_icu_value_src_php( char* tag_name, INTERNAL_FUNCTION_PARAMETERS)
377
383
const char * loc_name = NULL ;
378
384
size_t loc_name_len = 0 ;
379
385
380
- char * tag_value = NULL ;
386
+ zend_string * tag_value = NULL ;
381
387
char * empty_result = "" ;
382
388
383
389
int result = 0 ;
@@ -406,16 +412,14 @@ static void get_icu_value_src_php( char* tag_name, INTERNAL_FUNCTION_PARAMETERS)
406
412
/* No value found */
407
413
if ( result == -1 ) {
408
414
if ( tag_value ){
409
- efree ( tag_value );
415
+ zend_string_release ( tag_value );
410
416
}
411
417
RETURN_STRING ( empty_result );
412
418
}
413
419
414
420
/* value found */
415
421
if ( tag_value ){
416
- RETVAL_STRING ( tag_value );
417
- //???
418
- efree (tag_value );
422
+ RETVAL_STR ( tag_value );
419
423
return ;
420
424
}
421
425
@@ -985,9 +989,9 @@ PHP_FUNCTION(locale_compose)
985
989
* e.g. for locale='en_US-x-prv1-prv2-prv3'
986
990
* returns a pointer to the string 'prv1-prv2-prv3'
987
991
*/
988
- static char * get_private_subtags (const char * loc_name )
992
+ static zend_string * get_private_subtags (const char * loc_name )
989
993
{
990
- char * result = NULL ;
994
+ zend_string * result = NULL ;
991
995
int singletonPos = 0 ;
992
996
int len = 0 ;
993
997
const char * mod_loc_name = NULL ;
@@ -1005,7 +1009,7 @@ static char* get_private_subtags(const char* loc_name)
1005
1009
}
1006
1010
else {
1007
1011
/* result = mod_loc_name + singletonPos +2; */
1008
- result = estrndup (mod_loc_name + singletonPos + 2 , (len - ( singletonPos + 2 ) ) );
1012
+ result = zend_string_init (mod_loc_name + singletonPos + 2 , (len - ( singletonPos + 2 ) ), 0 );
1009
1013
}
1010
1014
break ;
1011
1015
}
@@ -1032,7 +1036,7 @@ static char* get_private_subtags(const char* loc_name)
1032
1036
*/
1033
1037
static int add_array_entry (const char * loc_name , zval * hash_arr , char * key_name )
1034
1038
{
1035
- char * key_value = NULL ;
1039
+ zend_string * key_value = NULL ;
1036
1040
char * cur_key_name = NULL ;
1037
1041
char * token = NULL ;
1038
1042
char * last_ptr = NULL ;
@@ -1052,7 +1056,7 @@ static int add_array_entry(const char* loc_name, zval* hash_arr, char* key_name)
1052
1056
( strcmp (key_name , LOC_VARIANT_TAG )== 0 ) ){
1053
1057
if ( result > 0 && key_value ){
1054
1058
/* Tokenize on the "_" or "-" */
1055
- token = php_strtok_r ( key_value , DELIMITER ,& last_ptr );
1059
+ token = php_strtok_r ( key_value -> val , DELIMITER ,& last_ptr );
1056
1060
if ( cur_key_name ){
1057
1061
efree ( cur_key_name );
1058
1062
}
@@ -1069,20 +1073,22 @@ static int add_array_entry(const char* loc_name, zval* hash_arr, char* key_name)
1069
1073
}
1070
1074
*/
1071
1075
}
1076
+ if (key_value ) {
1077
+ zend_string_release (key_value );
1078
+ }
1072
1079
} else {
1073
1080
if ( result == 1 ){
1074
- add_assoc_string ( hash_arr , key_name , key_value );
1081
+ add_assoc_str ( hash_arr , key_name , key_value );
1075
1082
cur_result = 1 ;
1083
+ } else if (key_value ) {
1084
+ zend_string_release (key_value );
1076
1085
}
1077
1086
}
1078
1087
1079
1088
if ( cur_key_name ){
1080
1089
efree ( cur_key_name );
1081
1090
}
1082
1091
/*if( key_name != LOC_PRIVATE_TAG && key_value){*/
1083
- if ( key_value ){
1084
- efree (key_value );
1085
- }
1086
1092
return cur_result ;
1087
1093
}
1088
1094
/* }}} */
@@ -1144,7 +1150,7 @@ PHP_FUNCTION(locale_get_all_variants)
1144
1150
1145
1151
int result = 0 ;
1146
1152
char * token = NULL ;
1147
- char * variant = NULL ;
1153
+ zend_string * variant = NULL ;
1148
1154
char * saved_ptr = NULL ;
1149
1155
1150
1156
intl_error_reset ( NULL );
@@ -1174,15 +1180,15 @@ PHP_FUNCTION(locale_get_all_variants)
1174
1180
variant = get_icu_value_internal ( loc_name , LOC_VARIANT_TAG , & result ,0 );
1175
1181
if ( result > 0 && variant ){
1176
1182
/* Tokenize on the "_" or "-" */
1177
- token = php_strtok_r ( variant , DELIMITER , & saved_ptr );
1183
+ token = php_strtok_r ( variant -> val , DELIMITER , & saved_ptr );
1178
1184
add_next_index_stringl ( return_value , token , strlen (token ));
1179
1185
/* tokenize on the "_" or "-" and stop at singleton if any */
1180
1186
while ( (token = php_strtok_r (NULL , DELIMITER , & saved_ptr )) && (strlen (token )> 1 ) ){
1181
1187
add_next_index_stringl ( return_value , token , strlen (token ));
1182
1188
}
1183
1189
}
1184
1190
if ( variant ){
1185
- efree ( variant );
1191
+ zend_string_release ( variant );
1186
1192
}
1187
1193
}
1188
1194
@@ -1241,8 +1247,8 @@ PHP_FUNCTION(locale_filter_matches)
1241
1247
char * token = 0 ;
1242
1248
char * chrcheck = NULL ;
1243
1249
1244
- char * can_lang_tag = NULL ;
1245
- char * can_loc_range = NULL ;
1250
+ zend_string * can_lang_tag = NULL ;
1251
+ zend_string * can_loc_range = NULL ;
1246
1252
1247
1253
char * cur_lang_tag = NULL ;
1248
1254
char * cur_loc_range = NULL ;
@@ -1288,23 +1294,23 @@ PHP_FUNCTION(locale_filter_matches)
1288
1294
}
1289
1295
1290
1296
/* Convert to lower case for case-insensitive comparison */
1291
- cur_lang_tag = ecalloc ( 1 , strlen ( can_lang_tag ) + 1 );
1297
+ cur_lang_tag = ecalloc ( 1 , can_lang_tag -> len + 1 );
1292
1298
1293
1299
/* Convert to lower case for case-insensitive comparison */
1294
- result = strToMatch ( can_lang_tag , cur_lang_tag );
1300
+ result = strToMatch ( can_lang_tag -> val , cur_lang_tag );
1295
1301
if ( result == 0 ) {
1296
1302
efree ( cur_lang_tag );
1297
- efree ( can_lang_tag );
1303
+ zend_string_release ( can_lang_tag );
1298
1304
RETURN_FALSE ;
1299
1305
}
1300
1306
1301
- cur_loc_range = ecalloc ( 1 , strlen ( can_loc_range ) + 1 );
1302
- result = strToMatch ( can_loc_range , cur_loc_range );
1307
+ cur_loc_range = ecalloc ( 1 , can_loc_range -> len + 1 );
1308
+ result = strToMatch ( can_loc_range -> val , cur_loc_range );
1303
1309
if ( result == 0 ) {
1304
1310
efree ( cur_lang_tag );
1305
- efree ( can_lang_tag );
1311
+ zend_string_release ( can_lang_tag );
1306
1312
efree ( cur_loc_range );
1307
- efree ( can_loc_range );
1313
+ zend_string_release ( can_loc_range );
1308
1314
RETURN_FALSE ;
1309
1315
}
1310
1316
@@ -1322,10 +1328,10 @@ PHP_FUNCTION(locale_filter_matches)
1322
1328
efree ( cur_loc_range );
1323
1329
}
1324
1330
if ( can_lang_tag ){
1325
- efree ( can_lang_tag );
1331
+ zend_string_release ( can_lang_tag );
1326
1332
}
1327
1333
if ( can_loc_range ){
1328
- efree ( can_loc_range );
1334
+ zend_string_release ( can_loc_range );
1329
1335
}
1330
1336
RETURN_TRUE ;
1331
1337
}
@@ -1339,10 +1345,10 @@ PHP_FUNCTION(locale_filter_matches)
1339
1345
efree ( cur_loc_range );
1340
1346
}
1341
1347
if ( can_lang_tag ){
1342
- efree ( can_lang_tag );
1348
+ zend_string_release ( can_lang_tag );
1343
1349
}
1344
1350
if ( can_loc_range ){
1345
- efree ( can_loc_range );
1351
+ zend_string_release ( can_loc_range );
1346
1352
}
1347
1353
RETURN_FALSE ;
1348
1354
@@ -1416,12 +1422,12 @@ static zend_string* lookup_loc_range(const char* loc_range, HashTable* hash_arr,
1416
1422
int cur_arr_len = 0 ;
1417
1423
int result = 0 ;
1418
1424
1419
- char * lang_tag = NULL ;
1425
+ zend_string * lang_tag = NULL ;
1420
1426
zval * ele_value = NULL ;
1421
1427
char * * cur_arr = NULL ;
1422
1428
1423
1429
char * cur_loc_range = NULL ;
1424
- char * can_loc_range = NULL ;
1430
+ zend_string * can_loc_range = NULL ;
1425
1431
int saved_pos = 0 ;
1426
1432
1427
1433
zend_string * return_value = NULL ;
@@ -1448,16 +1454,16 @@ static zend_string* lookup_loc_range(const char* loc_range, HashTable* hash_arr,
1448
1454
if (canonicalize ) {
1449
1455
for (i = 0 ; i < cur_arr_len ; i ++ ) {
1450
1456
lang_tag = get_icu_value_internal (cur_arr [i * 2 ], LOC_CANONICALIZE_TAG , & result , 0 );
1451
- if (result != 1 || lang_tag == NULL || !lang_tag [0 ]) {
1457
+ if (result != 1 || lang_tag == NULL || !lang_tag -> val [0 ]) {
1452
1458
if (lang_tag ) {
1453
- efree (lang_tag );
1459
+ zend_string_release (lang_tag );
1454
1460
}
1455
1461
intl_error_set (NULL , U_ILLEGAL_ARGUMENT_ERROR , "lookup_loc_range: unable to canonicalize lang_tag" , 0 );
1456
1462
LOOKUP_CLEAN_RETURN (NULL );
1457
1463
}
1458
- cur_arr [i * 2 ] = erealloc (cur_arr [i * 2 ], strlen ( lang_tag ) + 1 );
1459
- result = strToMatch (lang_tag , cur_arr [i * 2 ]);
1460
- efree (lang_tag );
1464
+ cur_arr [i * 2 ] = erealloc (cur_arr [i * 2 ], lang_tag -> len + 1 );
1465
+ result = strToMatch (lang_tag -> val , cur_arr [i * 2 ]);
1466
+ zend_string_release (lang_tag );
1461
1467
if (result == 0 ) {
1462
1468
intl_error_set (NULL , U_ILLEGAL_ARGUMENT_ERROR , "lookup_loc_range: unable to canonicalize lang_tag" , 0 );
1463
1469
LOOKUP_CLEAN_RETURN (NULL );
@@ -1469,23 +1475,23 @@ static zend_string* lookup_loc_range(const char* loc_range, HashTable* hash_arr,
1469
1475
if (canonicalize ) {
1470
1476
/* Canonicalize the loc_range */
1471
1477
can_loc_range = get_icu_value_internal (loc_range , LOC_CANONICALIZE_TAG , & result , 0 );
1472
- if ( result != 1 || can_loc_range == NULL || !can_loc_range [0 ]) {
1478
+ if ( result != 1 || can_loc_range == NULL || !can_loc_range -> val [0 ]) {
1473
1479
/* Error */
1474
1480
intl_error_set (NULL , U_ILLEGAL_ARGUMENT_ERROR , "lookup_loc_range: unable to canonicalize loc_range" , 0 );
1475
1481
if (can_loc_range ) {
1476
- efree (can_loc_range );
1482
+ zend_string_release (can_loc_range );
1477
1483
}
1478
1484
LOOKUP_CLEAN_RETURN (NULL );
1479
1485
} else {
1480
- loc_range = can_loc_range ;
1486
+ loc_range = can_loc_range -> val ;
1481
1487
}
1482
1488
}
1483
1489
1484
1490
cur_loc_range = ecalloc (1 , strlen (loc_range )+ 1 );
1485
1491
/* convert to lower and replace hyphens */
1486
1492
result = strToMatch (loc_range , cur_loc_range );
1487
1493
if (can_loc_range ) {
1488
- efree (can_loc_range );
1494
+ zend_string_release (can_loc_range );
1489
1495
}
1490
1496
if (result == 0 ) {
1491
1497
intl_error_set (NULL , U_ILLEGAL_ARGUMENT_ERROR , "lookup_loc_range: unable to canonicalize lang_tag" , 0 );
0 commit comments