Skip to content

Commit

Permalink
ext/standard/string.c: Refactor php_spn_common_handler()
Browse files Browse the repository at this point in the history
Main objective is to remove the PHP_STR_STR(C)SPN symbols which are only used with this static function
  • Loading branch information
Girgias committed Sep 12, 2024
1 parent 312f789 commit 1b87772
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
3 changes: 0 additions & 3 deletions ext/standard/php_string.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,4 @@ PHPAPI bool php_binary_string_shuffle(php_random_algo_with_state engine, char *s
#define PHP_PATHINFO_FILENAME 8
#define PHP_PATHINFO_ALL (PHP_PATHINFO_DIRNAME | PHP_PATHINFO_BASENAME | PHP_PATHINFO_EXTENSION | PHP_PATHINFO_FILENAME)

#define PHP_STR_STRSPN 0
#define PHP_STR_STRCSPN 1

#endif /* PHP_STRING_H */
9 changes: 4 additions & 5 deletions ext/standard/string.c
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ PHP_FUNCTION(hex2bin)
}
/* }}} */

static void php_spn_common_handler(INTERNAL_FUNCTION_PARAMETERS, int behavior) /* {{{ */
static void php_spn_common_handler(INTERNAL_FUNCTION_PARAMETERS, bool is_strspn) /* {{{ */
{
zend_string *s11, *s22;
zend_long start = 0, len = 0;
Expand Down Expand Up @@ -249,13 +249,12 @@ static void php_spn_common_handler(INTERNAL_FUNCTION_PARAMETERS, int behavior) /
RETURN_LONG(0);
}

if (behavior == PHP_STR_STRSPN) {
if (is_strspn) {
RETURN_LONG(php_strspn(ZSTR_VAL(s11) + start /*str1_start*/,
ZSTR_VAL(s22) /*str2_start*/,
ZSTR_VAL(s11) + start + len /*str1_end*/,
ZSTR_VAL(s22) + ZSTR_LEN(s22) /*str2_end*/));
} else {
ZEND_ASSERT(behavior == PHP_STR_STRCSPN);
RETURN_LONG(php_strcspn(ZSTR_VAL(s11) + start /*str1_start*/,
ZSTR_VAL(s22) /*str2_start*/,
ZSTR_VAL(s11) + start + len /*str1_end*/,
Expand All @@ -267,14 +266,14 @@ static void php_spn_common_handler(INTERNAL_FUNCTION_PARAMETERS, int behavior) /
/* {{{ Finds length of initial segment consisting entirely of characters found in mask. If start or/and length is provided works like strspn(substr($s,$start,$len),$good_chars) */
PHP_FUNCTION(strspn)
{
php_spn_common_handler(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_STR_STRSPN);
php_spn_common_handler(INTERNAL_FUNCTION_PARAM_PASSTHRU, /* is_strspn */ true);
}
/* }}} */

/* {{{ Finds length of initial segment consisting entirely of characters not found in mask. If start or/and length is provide works like strcspn(substr($s,$start,$len),$bad_chars) */
PHP_FUNCTION(strcspn)
{
php_spn_common_handler(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_STR_STRCSPN);
php_spn_common_handler(INTERNAL_FUNCTION_PARAM_PASSTHRU, /* is_strspn */ false);
}
/* }}} */

Expand Down

0 comments on commit 1b87772

Please sign in to comment.