Skip to content

Commit 2334d83

Browse files
committed
use more suitable types here, too
and simplify the loop
1 parent 198c2ec commit 2334d83

File tree

1 file changed

+35
-39
lines changed

1 file changed

+35
-39
lines changed

ext/intl/locale/locale_methods.c

+35-39
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ PHP_NAMED_FUNCTION(zif_locale_get_default)
219219
/* {{{ proto static string Locale::setDefault( string $locale )
220220
Set default locale */
221221
/* }}} */
222-
/* {{{ proto static string locale_set_default( string $locale )
222+
/* {{{ proto sta tic string locale_set_default( string $locale )
223223
Set default locale */
224224
PHP_NAMED_FUNCTION(zif_locale_set_default)
225225
{
@@ -258,15 +258,15 @@ PHP_NAMED_FUNCTION(zif_locale_set_default)
258258
*/
259259
static zend_string* get_icu_value_internal( const char* loc_name , char* tag_name, int* result , int fromParseLocale)
260260
{
261-
zend_string* tag_value = NULL;
262-
int32_t tag_value_len = 512;
261+
zend_string* tag_value = NULL;
262+
int32_t tag_value_len = 512;
263263

264-
int singletonPos = 0;
265-
char* mod_loc_name = NULL;
266-
int grOffset = 0;
264+
zend_off_t singletonPos = 0;
265+
char* mod_loc_name = NULL;
266+
zend_off_t grOffset = 0;
267267

268-
int32_t buflen = 512;
269-
UErrorCode status = U_ZERO_ERROR;
268+
int32_t buflen = 512;
269+
UErrorCode status = U_ZERO_ERROR;
270270

271271

272272
if( strcmp(tag_name, LOC_CANONICALIZE_TAG) != 0 ){
@@ -433,12 +433,12 @@ static void get_icu_value_src_php( char* tag_name, INTERNAL_FUNCTION_PARAMETERS)
433433
}
434434

435435
}
436-
/* }}} */
436+
/* }}} */
437437

438-
/* {{{ proto static string Locale::getScript($locale)
438+
/* {{{ proto stat ic string Locale::getScript($locale)
439439
* gets the script for the $locale
440440
}}} */
441-
/* {{{ proto static string locale_get_script($locale)
441+
/* {{{ proto stati c string locale_get_script($locale)
442442
* gets the script for the $locale
443443
*/
444444
PHP_FUNCTION( locale_get_script )
@@ -449,8 +449,8 @@ PHP_FUNCTION( locale_get_script )
449449

450450
/* {{{ proto static string Locale::getRegion($locale)
451451
* gets the region for the $locale
452-
}}} */
453-
/* {{{ proto static string locale_get_region($locale)
452+
}}} */
453+
/* {{{ p roto static string locale_get_region($locale)
454454
* gets the region for the $locale
455455
*/
456456
PHP_FUNCTION( locale_get_region )
@@ -992,40 +992,36 @@ PHP_FUNCTION(locale_compose)
992992
*/
993993
static zend_string* get_private_subtags(const char* loc_name)
994994
{
995-
zend_string* result =NULL;
996-
int singletonPos = 0;
997-
int len =0;
998-
const char* mod_loc_name =NULL;
995+
zend_string* result = NULL;
996+
zend_off_t singletonPos = 0;
997+
size_t len = 0;
998+
const char* mod_loc_name =NULL;
999999

10001000
if( loc_name && (len = strlen(loc_name)>0 ) ){
10011001
mod_loc_name = loc_name ;
10021002
len = strlen(mod_loc_name);
1003-
while( (singletonPos = getSingletonPos(mod_loc_name))!= -1){
1004-
1005-
if( singletonPos!=-1){
1006-
if( (*(mod_loc_name+singletonPos)=='x') || (*(mod_loc_name+singletonPos)=='X') ){
1007-
/* private subtag start found */
1008-
if( singletonPos + 2 == len){
1009-
/* loc_name ends with '-x-' ; return NULL */
1010-
}
1011-
else{
1012-
/* result = mod_loc_name + singletonPos +2; */
1013-
result = zend_string_init(mod_loc_name + singletonPos+2 , (len -( singletonPos +2) ), 0);
1014-
}
1015-
break;
1003+
while( (singletonPos = getSingletonPos(mod_loc_name)) > -1){
1004+
if( (*(mod_loc_name+singletonPos)=='x') || (*(mod_loc_name+singletonPos)=='X') ){
1005+
/* private subtag start found */
1006+
if( singletonPos + 2 == len){
1007+
/* loc_name ends with '-x-' ; return NULL */
10161008
}
10171009
else{
1018-
if( singletonPos + 1 >= len){
1019-
/* String end */
1020-
break;
1021-
} else {
1022-
/* singleton found but not a private subtag , hence check further in the string for the private subtag */
1023-
mod_loc_name = mod_loc_name + singletonPos +1;
1024-
len = strlen(mod_loc_name);
1025-
}
1010+
/* result = mod_loc_name + singletonPos +2; */
1011+
result = zend_string_init(mod_loc_name + singletonPos+2 , (len -( singletonPos +2) ), 0);
1012+
}
1013+
break;
1014+
}
1015+
else{
1016+
if((size_t)(singletonPos + 1) >= len){
1017+
/* String end */
1018+
break;
1019+
} else {
1020+
/* singleton found but not a private subtag , hence check further in the string for the private subtag */
1021+
mod_loc_name = mod_loc_name + singletonPos +1;
1022+
len = strlen(mod_loc_name);
10261023
}
10271024
}
1028-
10291025
} /* end of while */
10301026
}
10311027

0 commit comments

Comments
 (0)