Skip to content

Remove duplicate string APIs #8195

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion UPGRADING.INTERNALS
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,16 @@ PHP 8.2 INTERNALS UPGRADE NOTES
========================
3. Module changes
========================

a. ext/standard
- The PHP APIs php_strtoupper(), php_string_toupper(), php_strtolower(),
and php_string_tolower() have been removed.
Use zend_str_toupper(), zend_string_toupper(), zend_str_tolower(),
and zend_string_tolower() respectively instead.

- The PHP APIs string_natural_compare_function_ex(),
string_natural_case_compare_function(), and string_natural_compare_function()
have been removed. They always returned SUCCESS and were a wrapper around
strnatcmp_ex(). Use strnatcmp_ex() directly instead.
========================
4. OpCode changes
========================
Expand Down
4 changes: 2 additions & 2 deletions ext/standard/array.c
Original file line number Diff line number Diff line change
Expand Up @@ -4529,9 +4529,9 @@ PHP_FUNCTION(array_change_key_case)
entry = zend_hash_index_update(Z_ARRVAL_P(return_value), num_key, entry);
} else {
if (change_to_upper) {
new_key = php_string_toupper(string_key);
new_key = zend_string_toupper(string_key);
} else {
new_key = php_string_tolower(string_key);
new_key = zend_string_tolower(string_key);
}
entry = zend_hash_update(Z_ARRVAL_P(return_value), new_key, entry);
zend_string_release_ex(new_key, 0);
Expand Down
8 changes: 0 additions & 8 deletions ext/standard/php_string.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,6 @@ PHP_MINIT_FUNCTION(string_intrin);
strnatcmp_ex(a, strlen(a), b, strlen(b), 1)
PHPAPI int strnatcmp_ex(char const *a, size_t a_len, char const *b, size_t b_len, int fold_case);
PHPAPI struct lconv *localeconv_r(struct lconv *out);
PHPAPI char *php_strtoupper(char *s, size_t len);
PHPAPI char *php_strtolower(char *s, size_t len);
PHPAPI zend_string *php_string_toupper(zend_string *s);
PHPAPI zend_string *php_string_tolower(zend_string *s);
PHPAPI char *php_strtr(char *str, size_t len, const char *str_from, const char *str_to, size_t trlen);
PHPAPI zend_string *php_addslashes(zend_string *str);
PHPAPI void php_stripslashes(zend_string *str);
Expand All @@ -59,10 +55,6 @@ PHPAPI void php_explode(const zend_string *delim, zend_string *str, zval *return
PHPAPI size_t php_strspn(const char *s1, const char *s2, const char *s1_end, const char *s2_end);
PHPAPI size_t php_strcspn(const char *s1, const char *s2, const char *s1_end, const char *s2_end);

PHPAPI int string_natural_compare_function_ex(zval *result, zval *op1, zval *op2, bool case_insensitive);
PHPAPI int string_natural_compare_function(zval *result, zval *op1, zval *op2);
PHPAPI int string_natural_case_compare_function(zval *result, zval *op1, zval *op2);

#if defined(_REENTRANT)
# ifdef PHP_WIN32
# include <wchar.h>
Expand Down
62 changes: 3 additions & 59 deletions ext/standard/string.c
Original file line number Diff line number Diff line change
Expand Up @@ -1343,21 +1343,6 @@ PHP_FUNCTION(strtok)
}
/* }}} */

/* {{{ php_strtoupper */
PHPAPI char *php_strtoupper(char *s, size_t len)
{
zend_str_toupper(s, len);
return s;
}
/* }}} */

/* {{{ php_string_toupper */
PHPAPI zend_string *php_string_toupper(zend_string *s)
{
return zend_string_toupper(s);
}
/* }}} */

/* {{{ Makes a string uppercase */
PHP_FUNCTION(strtoupper)
{
Expand All @@ -1371,21 +1356,6 @@ PHP_FUNCTION(strtoupper)
}
/* }}} */

/* {{{ php_strtolower */
PHPAPI char *php_strtolower(char *s, size_t len)
{
zend_str_tolower(s, len);
return s;
}
/* }}} */

/* {{{ php_string_tolower */
PHPAPI zend_string *php_string_tolower(zend_string *s)
{
return zend_string_tolower(s);
}
/* }}} */

/* {{{ Makes a string lowercase */
PHP_FUNCTION(strtolower)
{
Expand Down Expand Up @@ -3120,7 +3090,7 @@ static zend_string *php_str_to_str_i_ex(zend_string *haystack, const char *lc_ha
char *e;

if (ZSTR_LEN(needle) == str_len) {
lc_needle = php_string_tolower(needle);
lc_needle = zend_string_tolower(needle);
end = lc_haystack + ZSTR_LEN(haystack);
for (p = lc_haystack; (r = (char*)php_memnstr(p, ZSTR_VAL(lc_needle), ZSTR_LEN(lc_needle), end)); p = r + ZSTR_LEN(lc_needle)) {
if (!new_str) {
Expand All @@ -3141,7 +3111,7 @@ static zend_string *php_str_to_str_i_ex(zend_string *haystack, const char *lc_ha
const char *n;
const char *endp = o + ZSTR_LEN(haystack);

lc_needle = php_string_tolower(needle);
lc_needle = zend_string_tolower(needle);
n = ZSTR_VAL(lc_needle);

while ((o = (char*)php_memnstr(o, n, ZSTR_LEN(lc_needle), endp))) {
Expand Down Expand Up @@ -3185,7 +3155,7 @@ static zend_string *php_str_to_str_i_ex(zend_string *haystack, const char *lc_ha
nothing_todo:
return zend_string_copy(haystack);
} else {
lc_needle = php_string_tolower(needle);
lc_needle = zend_string_tolower(needle);

if (memcmp(lc_haystack, ZSTR_VAL(lc_needle), ZSTR_LEN(lc_needle))) {
zend_string_release_ex(lc_needle, 0);
Expand Down Expand Up @@ -5406,32 +5376,6 @@ static void php_strnatcmp(INTERNAL_FUNCTION_PARAMETERS, int fold_case)
}
/* }}} */

PHPAPI int string_natural_compare_function_ex(zval *result, zval *op1, zval *op2, bool case_insensitive) /* {{{ */
{
zend_string *tmp_str1, *tmp_str2;
zend_string *str1 = zval_get_tmp_string(op1, &tmp_str1);
zend_string *str2 = zval_get_tmp_string(op2, &tmp_str2);

ZVAL_LONG(result, strnatcmp_ex(ZSTR_VAL(str1), ZSTR_LEN(str1), ZSTR_VAL(str2), ZSTR_LEN(str2), case_insensitive));

zend_tmp_string_release(tmp_str1);
zend_tmp_string_release(tmp_str2);
return SUCCESS;
}
/* }}} */

PHPAPI int string_natural_case_compare_function(zval *result, zval *op1, zval *op2) /* {{{ */
{
return string_natural_compare_function_ex(result, op1, op2, 1);
}
/* }}} */

PHPAPI int string_natural_compare_function(zval *result, zval *op1, zval *op2) /* {{{ */
{
return string_natural_compare_function_ex(result, op1, op2, 0);
}
/* }}} */

/* {{{ Returns the result of string comparison using 'natural' algorithm */
PHP_FUNCTION(strnatcmp)
{
Expand Down