Skip to content

Commit 8a007f0

Browse files
committed
Refactor php_mb_ulcfirst
1 parent 555eb20 commit 8a007f0

File tree

1 file changed

+17
-31
lines changed

1 file changed

+17
-31
lines changed

ext/mbstring/mbstring.c

Lines changed: 17 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2953,22 +2953,7 @@ PHP_FUNCTION(mb_strtolower)
29532953
RETURN_STR(mbstring_convert_case(PHP_UNICODE_CASE_LOWER, ZSTR_VAL(str), ZSTR_LEN(str), enc));
29542954
}
29552955

2956-
static zend_string* php_mb_ulcfirst(zend_string *str, php_case_mode mode, const mbfl_encoding *enc)
2957-
{
2958-
zend_string *first, *second, *head;
2959-
first = mb_get_substr(str, 0, 1, enc);
2960-
second = mb_get_substr(str, 1, MBFL_SUBSTR_UNTIL_END, enc);
2961-
head = mbstring_convert_case(mode, ZSTR_VAL(first), ZSTR_LEN(first), enc);
2962-
zend_string_release_ex(first, false);
2963-
2964-
zend_string *retval = zend_string_concat2(ZSTR_VAL(head), ZSTR_LEN(head), ZSTR_VAL(second), ZSTR_LEN(second));
2965-
zend_string_release_ex(head, false);
2966-
zend_string_release_ex(second, false);
2967-
2968-
return retval;
2969-
}
2970-
2971-
PHP_FUNCTION(mb_ucfirst)
2956+
static void php_mb_ulcfirst(INTERNAL_FUNCTION_PARAMETERS, php_case_mode mode)
29722957
{
29732958
zend_string *str, *from_encoding = NULL;
29742959

@@ -2983,25 +2968,26 @@ PHP_FUNCTION(mb_ucfirst)
29832968
RETURN_THROWS();
29842969
}
29852970

2986-
RETVAL_STR(php_mb_ulcfirst(str, PHP_UNICODE_CASE_TITLE, enc));
2987-
}
2971+
zend_string *first = mb_get_substr(str, 0, 1, enc);
2972+
zend_string *second = mb_get_substr(str, 1, MBFL_SUBSTR_UNTIL_END, enc);
2973+
zend_string *head = mbstring_convert_case(mode, ZSTR_VAL(first), ZSTR_LEN(first), enc);
2974+
zend_string_release_ex(first, false);
29882975

2989-
PHP_FUNCTION(mb_lcfirst)
2990-
{
2991-
zend_string *str, *from_encoding = NULL;
2976+
zend_string *retval = zend_string_concat2(ZSTR_VAL(head), ZSTR_LEN(head), ZSTR_VAL(second), ZSTR_LEN(second));
2977+
zend_string_release_ex(head, false);
2978+
zend_string_release_ex(second, false);
29922979

2993-
ZEND_PARSE_PARAMETERS_START(1, 2)
2994-
Z_PARAM_STR(str)
2995-
Z_PARAM_OPTIONAL
2996-
Z_PARAM_STR_OR_NULL(from_encoding)
2997-
ZEND_PARSE_PARAMETERS_END();
2980+
RETVAL_STR(retval);
2981+
}
29982982

2999-
const mbfl_encoding *enc = php_mb_get_encoding(from_encoding, 2);
3000-
if (!enc) {
3001-
RETURN_THROWS();
3002-
}
2983+
PHP_FUNCTION(mb_ucfirst)
2984+
{
2985+
php_mb_ulcfirst(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_UNICODE_CASE_TITLE);
2986+
}
30032987

3004-
RETVAL_STR(php_mb_ulcfirst(str, PHP_UNICODE_CASE_LOWER, enc));
2988+
PHP_FUNCTION(mb_lcfirst)
2989+
{
2990+
php_mb_ulcfirst(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_UNICODE_CASE_LOWER);
30052991
}
30062992

30072993
typedef enum {

0 commit comments

Comments
 (0)