Skip to content

Commit bc6a5a3

Browse files
committed
Merge 5afa761 into 02b661e
2 parents 02b661e + 5afa761 commit bc6a5a3

File tree

4 files changed

+37
-8
lines changed

4 files changed

+37
-8
lines changed

ext/standard/basic_functions.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2309,8 +2309,9 @@ ZEND_BEGIN_ARG_INFO(arginfo_lcfirst, 0)
23092309
ZEND_ARG_INFO(0, str)
23102310
ZEND_END_ARG_INFO()
23112311

2312-
ZEND_BEGIN_ARG_INFO(arginfo_ucwords, 0)
2312+
ZEND_BEGIN_ARG_INFO_EX(arginfo_ucwords, 0, 0, 1)
23132313
ZEND_ARG_INFO(0, str)
2314+
ZEND_ARG_INFO(0, delimiters)
23142315
ZEND_END_ARG_INFO()
23152316

23162317
ZEND_BEGIN_ARG_INFO_EX(arginfo_strtr, 0, 0, 2)

ext/standard/string.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2742,24 +2742,27 @@ PHP_FUNCTION(lcfirst)
27422742
Uppercase the first character of every word in a string */
27432743
PHP_FUNCTION(ucwords)
27442744
{
2745-
char *str;
2745+
char *str, *delims = " \t\r\n\f\v";
27462746
register char *r, *r_end;
2747-
int str_len;
2747+
int str_len, delims_len = 6;
2748+
char mask[256];
27482749

2749-
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &str, &str_len) == FAILURE) {
2750+
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|s", &str, &str_len, &delims, &delims_len) == FAILURE) {
27502751
return;
27512752
}
27522753

27532754
if (!str_len) {
27542755
RETURN_EMPTY_STRING();
27552756
}
27562757

2758+
php_charmask((unsigned char *)delims, delims_len, mask TSRMLS_CC);
2759+
27572760
ZVAL_STRINGL(return_value, str, str_len, 1);
27582761
r = Z_STRVAL_P(return_value);
27592762

27602763
*r = toupper((unsigned char) *r);
27612764
for (r_end = r + Z_STRLEN_P(return_value) - 1; r < r_end; ) {
2762-
if (isspace((int) *(unsigned char *)r++)) {
2765+
if (mask[(unsigned char)*r++]) {
27632766
*r = toupper((unsigned char) *r);
27642767
}
27652768
}

ext/standard/tests/strings/ucwords_error.phpt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ echo "\n-- Testing ucwords() function with more than expected no. of arguments -
1818
$str = 'string_val';
1919
$extra_arg = 10;
2020

21-
var_dump( ucwords($str, $extra_arg) );
21+
var_dump( ucwords($str, $extra_arg, $extra_arg) );
2222

2323
// check if there were any changes made to $str
2424
var_dump($str);
@@ -30,12 +30,12 @@ echo "Done\n";
3030

3131
-- Testing ucwords() function with Zero arguments --
3232

33-
Warning: ucwords() expects exactly 1 parameter, 0 given in %s on line %d
33+
Warning: ucwords() expects at least 1 parameter, 0 given in %s on line %d
3434
NULL
3535

3636
-- Testing ucwords() function with more than expected no. of arguments --
3737

38-
Warning: ucwords() expects exactly 1 parameter, 2 given in %s on line %d
38+
Warning: ucwords() expects at most 2 parameters, 3 given in %s on line %d
3939
NULL
4040
string(10) "string_val"
4141
Done
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
--TEST--
2+
Test ucwords() function : usage variations - custom delimiters
3+
--FILE--
4+
<?php
5+
/* Prototype : string ucwords ( string $str )
6+
* Description: Uppercase the first character of each word in a string
7+
* Source code: ext/standard/string.c
8+
*/
9+
10+
echo "*** Testing ucwords() : usage variations ***\n";
11+
12+
var_dump(ucwords('testing-dashed-words', '-'));
13+
var_dump(ucwords('test(braced)words', '()'));
14+
var_dump(ucwords('testing empty delimiters', ''));
15+
var_dump(ucwords('testing ranges', 'a..e'));
16+
17+
echo "Done\n";
18+
?>
19+
--EXPECTF--
20+
*** Testing ucwords() : usage variations ***
21+
string(%d) "Testing-Dashed-Words"
22+
string(%d) "Test(Braced)Words"
23+
string(%d) "Testing empty delimiters"
24+
string(%d) "TeSting raNgeS"
25+
Done

0 commit comments

Comments
 (0)