@@ -1342,52 +1342,15 @@ PHP_FUNCTION(strtok)
1342
1342
/* {{{ php_strtoupper */
1343
1343
PHPAPI char * php_strtoupper (char * s , size_t len )
1344
1344
{
1345
- unsigned char * c ;
1346
- const unsigned char * e ;
1347
-
1348
- c = (unsigned char * )s ;
1349
- e = (unsigned char * )c + len ;
1350
-
1351
- while (c < e ) {
1352
- * c = toupper (* c );
1353
- c ++ ;
1354
- }
1345
+ zend_str_toupper (s , len );
1355
1346
return s ;
1356
1347
}
1357
1348
/* }}} */
1358
1349
1359
1350
/* {{{ php_string_toupper */
1360
1351
PHPAPI zend_string * php_string_toupper (zend_string * s )
1361
1352
{
1362
- unsigned char * c ;
1363
- const unsigned char * e ;
1364
-
1365
- if (EXPECTED (!BG (ctype_string ))) {
1366
- return zend_string_toupper (s );
1367
- }
1368
- c = (unsigned char * )ZSTR_VAL (s );
1369
- e = c + ZSTR_LEN (s );
1370
-
1371
- while (c < e ) {
1372
- if (islower (* c )) {
1373
- unsigned char * r ;
1374
- zend_string * res = zend_string_alloc (ZSTR_LEN (s ), 0 );
1375
-
1376
- if (c != (unsigned char * )ZSTR_VAL (s )) {
1377
- memcpy (ZSTR_VAL (res ), ZSTR_VAL (s ), c - (unsigned char * )ZSTR_VAL (s ));
1378
- }
1379
- r = c + (ZSTR_VAL (res ) - ZSTR_VAL (s ));
1380
- while (c < e ) {
1381
- * r = toupper (* c );
1382
- r ++ ;
1383
- c ++ ;
1384
- }
1385
- * r = '\0' ;
1386
- return res ;
1387
- }
1388
- c ++ ;
1389
- }
1390
- return zend_string_copy (s );
1353
+ return zend_string_toupper (s );
1391
1354
}
1392
1355
/* }}} */
1393
1356
@@ -1400,56 +1363,22 @@ PHP_FUNCTION(strtoupper)
1400
1363
Z_PARAM_STR (arg )
1401
1364
ZEND_PARSE_PARAMETERS_END ();
1402
1365
1403
- RETURN_STR (php_string_toupper (arg ));
1366
+ RETURN_STR (zend_string_toupper (arg ));
1404
1367
}
1405
1368
/* }}} */
1406
1369
1407
1370
/* {{{ php_strtolower */
1408
1371
PHPAPI char * php_strtolower (char * s , size_t len )
1409
1372
{
1410
- unsigned char * c ;
1411
- const unsigned char * e ;
1412
-
1413
- c = (unsigned char * )s ;
1414
- e = c + len ;
1415
-
1416
- while (c < e ) {
1417
- * c = tolower (* c );
1418
- c ++ ;
1419
- }
1373
+ zend_str_tolower (s , len );
1420
1374
return s ;
1421
1375
}
1422
1376
/* }}} */
1423
1377
1424
1378
/* {{{ php_string_tolower */
1425
1379
PHPAPI zend_string * php_string_tolower (zend_string * s )
1426
1380
{
1427
- if (EXPECTED (!BG (ctype_string ))) {
1428
- return zend_string_tolower (s );
1429
- }
1430
-
1431
- unsigned char * c = (unsigned char * )ZSTR_VAL (s );
1432
- const unsigned char * e = c + ZSTR_LEN (s );
1433
- while (c < e ) {
1434
- if (isupper (* c )) {
1435
- unsigned char * r ;
1436
- zend_string * res = zend_string_alloc (ZSTR_LEN (s ), 0 );
1437
-
1438
- if (c != (unsigned char * )ZSTR_VAL (s )) {
1439
- memcpy (ZSTR_VAL (res ), ZSTR_VAL (s ), c - (unsigned char * )ZSTR_VAL (s ));
1440
- }
1441
- r = c + (ZSTR_VAL (res ) - ZSTR_VAL (s ));
1442
- while (c < e ) {
1443
- * r = tolower (* c );
1444
- r ++ ;
1445
- c ++ ;
1446
- }
1447
- * r = '\0' ;
1448
- return res ;
1449
- }
1450
- c ++ ;
1451
- }
1452
- return zend_string_copy (s );
1381
+ return zend_string_tolower (s );
1453
1382
}
1454
1383
/* }}} */
1455
1384
@@ -1462,7 +1391,7 @@ PHP_FUNCTION(strtolower)
1462
1391
Z_PARAM_STR (str )
1463
1392
ZEND_PARSE_PARAMETERS_END ();
1464
1393
1465
- RETURN_STR (php_string_tolower (str ));
1394
+ RETURN_STR (zend_string_tolower (str ));
1466
1395
}
1467
1396
/* }}} */
1468
1397
@@ -1754,8 +1683,8 @@ PHP_FUNCTION(pathinfo)
1754
1683
case insensitive strstr */
1755
1684
PHPAPI char * php_stristr (char * s , char * t , size_t s_len , size_t t_len )
1756
1685
{
1757
- php_strtolower (s , s_len );
1758
- php_strtolower (t , t_len );
1686
+ zend_str_tolower (s , s_len );
1687
+ zend_str_tolower (t , t_len );
1759
1688
return (char * )php_memnstr (s , t , t_len , s + s_len );
1760
1689
}
1761
1690
/* }}} */
@@ -1978,8 +1907,8 @@ PHP_FUNCTION(stripos)
1978
1907
RETURN_FALSE ;
1979
1908
}
1980
1909
1981
- haystack_dup = php_string_tolower (haystack );
1982
- needle_dup = php_string_tolower (needle );
1910
+ haystack_dup = zend_string_tolower (haystack );
1911
+ needle_dup = zend_string_tolower (needle );
1983
1912
found = (char * )php_memnstr (ZSTR_VAL (haystack_dup ) + offset ,
1984
1913
ZSTR_VAL (needle_dup ), ZSTR_LEN (needle_dup ), ZSTR_VAL (haystack_dup ) + ZSTR_LEN (haystack ));
1985
1914
@@ -2073,18 +2002,17 @@ PHP_FUNCTION(strripos)
2073
2002
}
2074
2003
e = ZSTR_VAL (haystack ) + (ZSTR_LEN (haystack ) + (size_t )offset );
2075
2004
}
2076
- /* Borrow that ord_needle buffer to avoid repeatedly tolower()ing needle */
2077
- lowered = tolower (* ZSTR_VAL (needle ));
2005
+ lowered = zend_tolower_ascii (* ZSTR_VAL (needle ));
2078
2006
while (e >= p ) {
2079
- if (tolower (* e ) == lowered ) {
2007
+ if (zend_tolower_ascii (* e ) == lowered ) {
2080
2008
RETURN_LONG (e - p + (offset > 0 ? offset : 0 ));
2081
2009
}
2082
2010
e -- ;
2083
2011
}
2084
2012
RETURN_FALSE ;
2085
2013
}
2086
2014
2087
- haystack_dup = php_string_tolower (haystack );
2015
+ haystack_dup = zend_string_tolower (haystack );
2088
2016
if (offset >= 0 ) {
2089
2017
if ((size_t )offset > ZSTR_LEN (haystack )) {
2090
2018
zend_string_release_ex (haystack_dup , 0 );
@@ -2108,7 +2036,7 @@ PHP_FUNCTION(strripos)
2108
2036
}
2109
2037
}
2110
2038
2111
- needle_dup = php_string_tolower (needle );
2039
+ needle_dup = zend_string_tolower (needle );
2112
2040
if ((found = (char * )zend_memnrstr (p , ZSTR_VAL (needle_dup ), ZSTR_LEN (needle_dup ), e ))) {
2113
2041
RETVAL_LONG (found - ZSTR_VAL (haystack_dup ));
2114
2042
zend_string_release_ex (needle_dup , 0 );
@@ -2603,7 +2531,7 @@ PHP_FUNCTION(chr)
2603
2531
static zend_string * php_ucfirst (zend_string * str )
2604
2532
{
2605
2533
const unsigned char ch = ZSTR_VAL (str )[0 ];
2606
- unsigned char r = toupper (ch );
2534
+ unsigned char r = zend_toupper_ascii (ch );
2607
2535
if (r == ch ) {
2608
2536
return zend_string_copy (str );
2609
2537
} else {
@@ -2635,7 +2563,7 @@ PHP_FUNCTION(ucfirst)
2635
2563
Lowercase the first character of the word in a native string */
2636
2564
static zend_string * php_lcfirst (zend_string * str )
2637
2565
{
2638
- unsigned char r = tolower (ZSTR_VAL (str )[0 ]);
2566
+ unsigned char r = zend_tolower_ascii (ZSTR_VAL (str )[0 ]);
2639
2567
if (r == ZSTR_VAL (str )[0 ]) {
2640
2568
return zend_string_copy (str );
2641
2569
} else {
@@ -2688,10 +2616,10 @@ PHP_FUNCTION(ucwords)
2688
2616
ZVAL_STRINGL (return_value , ZSTR_VAL (str ), ZSTR_LEN (str ));
2689
2617
r = Z_STRVAL_P (return_value );
2690
2618
2691
- * r = toupper ((unsigned char ) * r );
2619
+ * r = zend_toupper_ascii ((unsigned char ) * r );
2692
2620
for (r_end = r + Z_STRLEN_P (return_value ) - 1 ; r < r_end ; ) {
2693
2621
if (mask [(unsigned char )* r ++ ]) {
2694
- * r = toupper ((unsigned char ) * r );
2622
+ * r = zend_toupper_ascii ((unsigned char ) * r );
2695
2623
}
2696
2624
}
2697
2625
}
@@ -2937,9 +2865,9 @@ static zend_string* php_char_to_str_ex(zend_string *str, char from, char *to, si
2937
2865
p ++ ;
2938
2866
}
2939
2867
} else {
2940
- lc_from = tolower (from );
2868
+ lc_from = zend_tolower_ascii (from );
2941
2869
for (source = ZSTR_VAL (str ); source < source_end ; source ++ ) {
2942
- if (tolower (* source ) == lc_from ) {
2870
+ if (zend_tolower_ascii (* source ) == lc_from ) {
2943
2871
char_count ++ ;
2944
2872
}
2945
2873
}
@@ -2975,7 +2903,7 @@ static zend_string* php_char_to_str_ex(zend_string *str, char from, char *to, si
2975
2903
}
2976
2904
} else {
2977
2905
for (source = ZSTR_VAL (str ); source < source_end ; source ++ ) {
2978
- if (tolower (* source ) == lc_from ) {
2906
+ if (zend_tolower_ascii (* source ) == lc_from ) {
2979
2907
if (replace_count ) {
2980
2908
* replace_count += 1 ;
2981
2909
}
@@ -4202,7 +4130,7 @@ static zend_long php_str_replace_in_subject(
4202
4130
zend_long old_replace_count = replace_count ;
4203
4131
4204
4132
if (!lc_subject_str ) {
4205
- lc_subject_str = php_string_tolower (subject_str );
4133
+ lc_subject_str = zend_string_tolower (subject_str );
4206
4134
}
4207
4135
tmp_result = php_str_to_str_i_ex (subject_str , ZSTR_VAL (lc_subject_str ),
4208
4136
search_str , replace_value , replace_len , & replace_count );
@@ -4255,7 +4183,7 @@ static zend_long php_str_replace_in_subject(
4255
4183
ZSTR_VAL (search_str ), ZSTR_LEN (search_str ),
4256
4184
ZSTR_VAL (replace_str ), ZSTR_LEN (replace_str ), & replace_count ));
4257
4185
} else {
4258
- lc_subject_str = php_string_tolower (subject_str );
4186
+ lc_subject_str = zend_string_tolower (subject_str );
4259
4187
ZVAL_STR (result , php_str_to_str_i_ex (subject_str , ZSTR_VAL (lc_subject_str ),
4260
4188
search_str , ZSTR_VAL (replace_str ), ZSTR_LEN (replace_str ), & replace_count ));
4261
4189
zend_string_release_ex (lc_subject_str , 0 );
@@ -4798,7 +4726,7 @@ int php_tag_find(char *tag, size_t len, const char *set) {
4798
4726
4799
4727
n = norm ;
4800
4728
t = tag ;
4801
- c = tolower (* t );
4729
+ c = zend_tolower_ascii (* t );
4802
4730
/*
4803
4731
normalize the tag removing leading and trailing whitespace
4804
4732
and turn any <a whatever...> into just <a> and any </tag>
@@ -4826,7 +4754,7 @@ int php_tag_find(char *tag, size_t len, const char *set) {
4826
4754
}
4827
4755
break ;
4828
4756
}
4829
- c = tolower (* (++ t ));
4757
+ c = zend_tolower_ascii (* (++ t ));
4830
4758
}
4831
4759
* (n ++ ) = '>' ;
4832
4760
* n = '\0' ;
0 commit comments