@@ -89,8 +89,6 @@ void register_string_constants(INIT_FUNC_ARGS)
89
89
}
90
90
/* }}} */
91
91
92
- int php_tag_find (char * tag , size_t len , const char * set );
93
-
94
92
/* this is read-only, so it's ok */
95
93
ZEND_SET_ALIGNED (16 , static const char hexconvtab [ ]) = "0123456789abcdef" ;
96
94
@@ -695,11 +693,11 @@ PHP_FUNCTION(strcoll)
695
693
* it needs to be incrementing.
696
694
* Returns: FAILURE/SUCCESS whether the input was correct (i.e. no range errors)
697
695
*/
698
- static inline int php_charmask (const unsigned char * input , size_t len , char * mask )
696
+ static inline zend_result php_charmask (const unsigned char * input , size_t len , char * mask )
699
697
{
700
698
const unsigned char * end ;
701
699
unsigned char c ;
702
- int result = SUCCESS ;
700
+ zend_result result = SUCCESS ;
703
701
704
702
memset (mask , 0 , 256 );
705
703
for (end = input + len ; input < end ; input ++ ) {
@@ -1144,7 +1142,7 @@ PHP_FUNCTION(explode)
1144
1142
PHPAPI void php_implode (const zend_string * glue , HashTable * pieces , zval * return_value )
1145
1143
{
1146
1144
zval * tmp ;
1147
- int numelems ;
1145
+ uint32_t numelems ;
1148
1146
zend_string * str ;
1149
1147
char * cptr ;
1150
1148
size_t len = 0 ;
@@ -1606,7 +1604,7 @@ PHP_FUNCTION(pathinfo)
1606
1604
zval tmp ;
1607
1605
char * path , * dirname ;
1608
1606
size_t path_len ;
1609
- int have_basename ;
1607
+ bool have_basename ;
1610
1608
zend_long opt = PHP_PATHINFO_ALL ;
1611
1609
zend_string * ret = NULL ;
1612
1610
@@ -1744,16 +1742,14 @@ PHP_FUNCTION(stristr)
1744
1742
1745
1743
found = php_stristr (ZSTR_VAL (haystack ), ZSTR_VAL (needle ), ZSTR_LEN (haystack ), ZSTR_LEN (needle ));
1746
1744
1747
- if (found ) {
1748
- found_offset = found - ZSTR_VAL (haystack );
1749
- if (part ) {
1750
- RETVAL_STRINGL (ZSTR_VAL (haystack ), found_offset );
1751
- } else {
1752
- RETVAL_STRINGL (ZSTR_VAL (haystack ) + found_offset , ZSTR_LEN (haystack ) - found_offset );
1753
- }
1754
- } else {
1755
- RETVAL_FALSE ;
1745
+ if (!found ) {
1746
+ RETURN_FALSE ;
1747
+ }
1748
+ found_offset = found - ZSTR_VAL (haystack );
1749
+ if (part ) {
1750
+ RETURN_STRINGL (ZSTR_VAL (haystack ), found_offset );
1756
1751
}
1752
+ RETURN_STRINGL (ZSTR_VAL (haystack ) + found_offset , ZSTR_LEN (haystack ) - found_offset );
1757
1753
}
1758
1754
/* }}} */
1759
1755
@@ -1774,15 +1770,14 @@ PHP_FUNCTION(strstr)
1774
1770
1775
1771
found = php_memnstr (ZSTR_VAL (haystack ), ZSTR_VAL (needle ), ZSTR_LEN (needle ), ZSTR_VAL (haystack ) + ZSTR_LEN (haystack ));
1776
1772
1777
- if (found ) {
1778
- found_offset = found - ZSTR_VAL (haystack );
1779
- if (part ) {
1780
- RETURN_STRINGL (ZSTR_VAL (haystack ), found_offset );
1781
- } else {
1782
- RETURN_STRINGL (found , ZSTR_LEN (haystack ) - found_offset );
1783
- }
1773
+ if (!found ) {
1774
+ RETURN_FALSE ;
1784
1775
}
1785
- RETURN_FALSE ;
1776
+ found_offset = found - ZSTR_VAL (haystack );
1777
+ if (part ) {
1778
+ RETURN_STRINGL (ZSTR_VAL (haystack ), found_offset );
1779
+ }
1780
+ RETURN_STRINGL (ZSTR_VAL (haystack ) + found_offset , ZSTR_LEN (haystack ) - found_offset );
1786
1781
}
1787
1782
/* }}} */
1788
1783
@@ -1867,11 +1862,10 @@ PHP_FUNCTION(strpos)
1867
1862
ZSTR_VAL (needle ), ZSTR_LEN (needle ),
1868
1863
ZSTR_VAL (haystack ) + ZSTR_LEN (haystack ));
1869
1864
1870
- if (found ) {
1871
- RETURN_LONG (found - ZSTR_VAL (haystack ));
1872
- } else {
1865
+ if (!found ) {
1873
1866
RETURN_FALSE ;
1874
1867
}
1868
+ RETURN_LONG (found - ZSTR_VAL (haystack ));
1875
1869
}
1876
1870
/* }}} */
1877
1871
@@ -1900,11 +1894,10 @@ PHP_FUNCTION(stripos)
1900
1894
found = (char * )php_memnistr (ZSTR_VAL (haystack ) + offset ,
1901
1895
ZSTR_VAL (needle ), ZSTR_LEN (needle ), ZSTR_VAL (haystack ) + ZSTR_LEN (haystack ));
1902
1896
1903
- if (found ) {
1904
- RETVAL_LONG (found - ZSTR_VAL (haystack ));
1905
- } else {
1906
- RETVAL_FALSE ;
1897
+ if (!found ) {
1898
+ RETURN_FALSE ;
1907
1899
}
1900
+ RETURN_LONG (found - ZSTR_VAL (haystack ));
1908
1901
}
1909
1902
/* }}} */
1910
1903
@@ -1944,11 +1937,12 @@ PHP_FUNCTION(strrpos)
1944
1937
}
1945
1938
}
1946
1939
1947
- if ((found = zend_memnrstr (p , ZSTR_VAL (needle ), ZSTR_LEN (needle ), e ))) {
1948
- RETURN_LONG (found - ZSTR_VAL (haystack ));
1949
- }
1940
+ found = zend_memnrstr (p , ZSTR_VAL (needle ), ZSTR_LEN (needle ), e );
1950
1941
1951
- RETURN_FALSE ;
1942
+ if (!found ) {
1943
+ RETURN_FALSE ;
1944
+ }
1945
+ RETURN_LONG (found - ZSTR_VAL (haystack ));
1952
1946
}
1953
1947
/* }}} */
1954
1948
@@ -2047,12 +2041,11 @@ PHP_FUNCTION(strrchr)
2047
2041
ZEND_PARSE_PARAMETERS_END ();
2048
2042
2049
2043
found = zend_memrchr (ZSTR_VAL (haystack ), * ZSTR_VAL (needle ), ZSTR_LEN (haystack ));
2050
- if (found ) {
2051
- found_offset = found - ZSTR_VAL (haystack );
2052
- RETURN_STRINGL (found , ZSTR_LEN (haystack ) - found_offset );
2053
- } else {
2044
+ if (!found ) {
2054
2045
RETURN_FALSE ;
2055
2046
}
2047
+ found_offset = found - ZSTR_VAL (haystack );
2048
+ RETURN_STRINGL (found , ZSTR_LEN (haystack ) - found_offset );
2056
2049
}
2057
2050
/* }}} */
2058
2051
@@ -2786,7 +2779,7 @@ static void php_strtr_array(zval *return_value, zend_string *input, HashTable *p
2786
2779
zend_ulong num_key ;
2787
2780
zend_string * str_key ;
2788
2781
size_t len , pos , old_pos ;
2789
- int num_keys = 0 ;
2782
+ bool has_num_keys = false ;
2790
2783
size_t minlen = 128 * 1024 ;
2791
2784
size_t maxlen = 0 ;
2792
2785
HashTable str_hash ;
@@ -2803,10 +2796,10 @@ static void php_strtr_array(zval *return_value, zend_string *input, HashTable *p
2803
2796
/* check if original array has numeric keys */
2804
2797
ZEND_HASH_FOREACH_STR_KEY (pats , str_key ) {
2805
2798
if (UNEXPECTED (!str_key )) {
2806
- num_keys = 1 ;
2799
+ has_num_keys = true ;
2807
2800
} else {
2808
2801
len = ZSTR_LEN (str_key );
2809
- if (UNEXPECTED (len < 1 )) {
2802
+ if (UNEXPECTED (len == 0 )) {
2810
2803
php_error_docref (NULL , E_WARNING , "Ignoring replacement of empty string" );
2811
2804
continue ;
2812
2805
} else if (UNEXPECTED (len > slen )) {
@@ -2825,7 +2818,7 @@ static void php_strtr_array(zval *return_value, zend_string *input, HashTable *p
2825
2818
}
2826
2819
} ZEND_HASH_FOREACH_END ();
2827
2820
2828
- if (UNEXPECTED (num_keys )) {
2821
+ if (UNEXPECTED (has_num_keys )) {
2829
2822
zend_string * key_used ;
2830
2823
/* we have to rebuild HashTable with numeric keys */
2831
2824
zend_hash_init (& str_hash , zend_hash_num_elements (pats ), NULL , NULL , 0 );
@@ -2965,7 +2958,7 @@ static zend_always_inline zend_long count_chars(const char *p, zend_long length,
2965
2958
/* }}} */
2966
2959
2967
2960
/* {{{ php_char_to_str_ex */
2968
- static zend_string * php_char_to_str_ex (zend_string * str , char from , char * to , size_t to_len , int case_sensitivity , zend_long * replace_count )
2961
+ static zend_string * php_char_to_str_ex (zend_string * str , char from , char * to , size_t to_len , bool case_sensitivity , zend_long * replace_count )
2969
2962
{
2970
2963
zend_string * result ;
2971
2964
size_t char_count ;
@@ -3323,7 +3316,7 @@ PHP_FUNCTION(strtr)
3323
3316
ZSTR_VAL (str_key )[0 ],
3324
3317
ZSTR_VAL (replace ),
3325
3318
ZSTR_LEN (replace ),
3326
- 1 ,
3319
+ /* case_sensitive */ true ,
3327
3320
NULL ));
3328
3321
} else {
3329
3322
zend_long dummy ;
@@ -3459,7 +3452,7 @@ PHP_FUNCTION(similar_text)
3459
3452
{
3460
3453
zend_string * t1 , * t2 ;
3461
3454
zval * percent = NULL ;
3462
- int ac = ZEND_NUM_ARGS ();
3455
+ bool compute_percentage = ZEND_NUM_ARGS () == 3 ;
3463
3456
size_t sim ;
3464
3457
3465
3458
ZEND_PARSE_PARAMETERS_START (2 , 3 )
@@ -3470,7 +3463,7 @@ PHP_FUNCTION(similar_text)
3470
3463
ZEND_PARSE_PARAMETERS_END ();
3471
3464
3472
3465
if (ZSTR_LEN (t1 ) + ZSTR_LEN (t2 ) == 0 ) {
3473
- if (ac > 2 ) {
3466
+ if (compute_percentage ) {
3474
3467
ZEND_TRY_ASSIGN_REF_DOUBLE (percent , 0 );
3475
3468
}
3476
3469
@@ -3479,7 +3472,7 @@ PHP_FUNCTION(similar_text)
3479
3472
3480
3473
sim = php_similar_char (ZSTR_VAL (t1 ), ZSTR_LEN (t1 ), ZSTR_VAL (t2 ), ZSTR_LEN (t2 ));
3481
3474
3482
- if (ac > 2 ) {
3475
+ if (compute_percentage ) {
3483
3476
ZEND_TRY_ASSIGN_REF_DOUBLE (percent , sim * 200.0 / (ZSTR_LEN (t1 ) + ZSTR_LEN (t2 )));
3484
3477
}
3485
3478
@@ -3897,8 +3890,7 @@ static zend_always_inline quad_word aarch64_contains_slash_chars(uint8x16_t x) {
3897
3890
3898
3891
static zend_always_inline char * aarch64_add_slashes (quad_word res , const char * source , char * target )
3899
3892
{
3900
- int i = 0 ;
3901
- for (; i < 16 ; i ++ ) {
3893
+ for (int i = 0 ; i < 16 ; i ++ ) {
3902
3894
char s = source [i ];
3903
3895
if (res .mem [i ] == 0 )
3904
3896
* target ++ = s ;
@@ -4160,7 +4152,7 @@ PHPAPI void php_stripslashes(zend_string *str)
4160
4152
/* {{{ php_str_replace_in_subject */
4161
4153
static zend_long php_str_replace_in_subject (
4162
4154
zend_string * search_str , HashTable * search_ht , zend_string * replace_str , HashTable * replace_ht ,
4163
- zend_string * subject_str , zval * result , int case_sensitivity
4155
+ zend_string * subject_str , zval * result , bool case_sensitivity
4164
4156
) {
4165
4157
zval * search_entry ;
4166
4158
zend_string * tmp_result ;
@@ -4321,7 +4313,7 @@ static zend_long php_str_replace_in_subject(
4321
4313
/* }}} */
4322
4314
4323
4315
/* {{{ php_str_replace_common */
4324
- static void php_str_replace_common (INTERNAL_FUNCTION_PARAMETERS , int case_sensitivity )
4316
+ static void php_str_replace_common (INTERNAL_FUNCTION_PARAMETERS , bool case_sensitivity )
4325
4317
{
4326
4318
zend_string * search_str ;
4327
4319
HashTable * search_ht ;
@@ -4836,10 +4828,11 @@ PHP_FUNCTION(parse_str)
4836
4828
* 0 start tag
4837
4829
* 1 first non-whitespace char seen
4838
4830
*/
4839
- int php_tag_find (char * tag , size_t len , const char * set ) {
4831
+ static bool php_tag_find (char * tag , size_t len , const char * set ) {
4840
4832
char c , * n ;
4841
4833
const char * t ;
4842
- int state = 0 , done = 0 ;
4834
+ int state = 0 ;
4835
+ bool done = 0 ;
4843
4836
char * norm ;
4844
4837
4845
4838
if (len == 0 ) {
@@ -5391,7 +5384,7 @@ PHP_FUNCTION(count_chars)
5391
5384
/* }}} */
5392
5385
5393
5386
/* {{{ php_strnatcmp */
5394
- static void php_strnatcmp (INTERNAL_FUNCTION_PARAMETERS , int fold_case )
5387
+ static void php_strnatcmp (INTERNAL_FUNCTION_PARAMETERS , bool is_case_insensitive )
5395
5388
{
5396
5389
zend_string * s1 , * s2 ;
5397
5390
@@ -5402,7 +5395,7 @@ static void php_strnatcmp(INTERNAL_FUNCTION_PARAMETERS, int fold_case)
5402
5395
5403
5396
RETURN_LONG (strnatcmp_ex (ZSTR_VAL (s1 ), ZSTR_LEN (s1 ),
5404
5397
ZSTR_VAL (s2 ), ZSTR_LEN (s2 ),
5405
- fold_case ));
5398
+ is_case_insensitive ));
5406
5399
}
5407
5400
/* }}} */
5408
5401
@@ -5439,11 +5432,18 @@ PHP_FUNCTION(strnatcmp)
5439
5432
}
5440
5433
/* }}} */
5441
5434
5435
+ /* {{{ Returns the result of case-insensitive string comparison using 'natural' algorithm */
5436
+ PHP_FUNCTION (strnatcasecmp )
5437
+ {
5438
+ php_strnatcmp (INTERNAL_FUNCTION_PARAM_PASSTHRU , 1 );
5439
+ }
5440
+ /* }}} */
5441
+
5442
5442
/* {{{ Returns numeric formatting information based on the current locale */
5443
5443
PHP_FUNCTION (localeconv )
5444
5444
{
5445
5445
zval grouping , mon_grouping ;
5446
- int len , i ;
5446
+ size_t len , i ;
5447
5447
5448
5448
ZEND_PARSE_PARAMETERS_NONE ();
5449
5449
@@ -5457,14 +5457,14 @@ PHP_FUNCTION(localeconv)
5457
5457
localeconv_r ( & currlocdata );
5458
5458
5459
5459
/* Grab the grouping data out of the array */
5460
- len = ( int ) strlen (currlocdata .grouping );
5460
+ len = strlen (currlocdata .grouping );
5461
5461
5462
5462
for (i = 0 ; i < len ; i ++ ) {
5463
5463
add_index_long (& grouping , i , currlocdata .grouping [i ]);
5464
5464
}
5465
5465
5466
5466
/* Grab the monetary grouping data out of the array */
5467
- len = ( int ) strlen (currlocdata .mon_grouping );
5467
+ len = strlen (currlocdata .mon_grouping );
5468
5468
5469
5469
for (i = 0 ; i < len ; i ++ ) {
5470
5470
add_index_long (& mon_grouping , i , currlocdata .mon_grouping [i ]);
@@ -5493,13 +5493,6 @@ PHP_FUNCTION(localeconv)
5493
5493
}
5494
5494
/* }}} */
5495
5495
5496
- /* {{{ Returns the result of case-insensitive string comparison using 'natural' algorithm */
5497
- PHP_FUNCTION (strnatcasecmp )
5498
- {
5499
- php_strnatcmp (INTERNAL_FUNCTION_PARAM_PASSTHRU , 1 );
5500
- }
5501
- /* }}} */
5502
-
5503
5496
/* {{{ Returns the number of times a substring occurs in the string */
5504
5497
PHP_FUNCTION (substr_count )
5505
5498
{
@@ -5771,7 +5764,7 @@ PHP_FUNCTION(str_rot13)
5771
5764
}
5772
5765
/* }}} */
5773
5766
5774
- static void php_string_shuffle (char * str , zend_long len ) /* {{{ */
5767
+ static void php_string_shuffle (char * str , size_t len ) /* {{{ */
5775
5768
{
5776
5769
zend_long n_elems , rnd_idx , n_left ;
5777
5770
char temp ;
@@ -5807,7 +5800,7 @@ PHP_FUNCTION(str_shuffle)
5807
5800
5808
5801
RETVAL_STRINGL (ZSTR_VAL (arg ), ZSTR_LEN (arg ));
5809
5802
if (Z_STRLEN_P (return_value ) > 1 ) {
5810
- php_string_shuffle (Z_STRVAL_P (return_value ), ( zend_long ) Z_STRLEN_P (return_value ));
5803
+ php_string_shuffle (Z_STRVAL_P (return_value ), Z_STRLEN_P (return_value ));
5811
5804
}
5812
5805
}
5813
5806
/* }}} */
0 commit comments