mirror of
https://github.com/php/php-src.git
synced 2025-08-18 06:58:55 +02:00
Merge branch 'PHP-5.6'
This commit is contained in:
commit
7de82eaeef
4 changed files with 37 additions and 8 deletions
|
@ -2284,8 +2284,9 @@ ZEND_BEGIN_ARG_INFO(arginfo_lcfirst, 0)
|
|||
ZEND_ARG_INFO(0, str)
|
||||
ZEND_END_ARG_INFO()
|
||||
|
||||
ZEND_BEGIN_ARG_INFO(arginfo_ucwords, 0)
|
||||
ZEND_BEGIN_ARG_INFO_EX(arginfo_ucwords, 0, 0, 1)
|
||||
ZEND_ARG_INFO(0, str)
|
||||
ZEND_ARG_INFO(0, delimiters)
|
||||
ZEND_END_ARG_INFO()
|
||||
|
||||
ZEND_BEGIN_ARG_INFO_EX(arginfo_strtr, 0, 0, 2)
|
||||
|
|
|
@ -2738,11 +2738,12 @@ PHP_FUNCTION(lcfirst)
|
|||
Uppercase the first character of every word in a string */
|
||||
PHP_FUNCTION(ucwords)
|
||||
{
|
||||
char *str;
|
||||
char *str, *delims = " \t\r\n\f\v";
|
||||
register char *r, *r_end;
|
||||
int str_len;
|
||||
int str_len, delims_len = 6;
|
||||
char mask[256];
|
||||
|
||||
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &str, &str_len) == FAILURE) {
|
||||
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|s", &str, &str_len, &delims, &delims_len) == FAILURE) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -2750,12 +2751,14 @@ PHP_FUNCTION(ucwords)
|
|||
RETURN_EMPTY_STRING();
|
||||
}
|
||||
|
||||
php_charmask((unsigned char *)delims, delims_len, mask TSRMLS_CC);
|
||||
|
||||
ZVAL_STRINGL(return_value, str, str_len, 1);
|
||||
r = Z_STRVAL_P(return_value);
|
||||
|
||||
*r = toupper((unsigned char) *r);
|
||||
for (r_end = r + Z_STRLEN_P(return_value) - 1; r < r_end; ) {
|
||||
if (isspace((int) *(unsigned char *)r++)) {
|
||||
if (mask[(unsigned char)*r++]) {
|
||||
*r = toupper((unsigned char) *r);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@ echo "\n-- Testing ucwords() function with more than expected no. of arguments -
|
|||
$str = 'string_val';
|
||||
$extra_arg = 10;
|
||||
|
||||
var_dump( ucwords($str, $extra_arg) );
|
||||
var_dump( ucwords($str, $extra_arg, $extra_arg) );
|
||||
|
||||
// check if there were any changes made to $str
|
||||
var_dump($str);
|
||||
|
@ -30,12 +30,12 @@ echo "Done\n";
|
|||
|
||||
-- Testing ucwords() function with Zero arguments --
|
||||
|
||||
Warning: ucwords() expects exactly 1 parameter, 0 given in %s on line %d
|
||||
Warning: ucwords() expects at least 1 parameter, 0 given in %s on line %d
|
||||
NULL
|
||||
|
||||
-- Testing ucwords() function with more than expected no. of arguments --
|
||||
|
||||
Warning: ucwords() expects exactly 1 parameter, 2 given in %s on line %d
|
||||
Warning: ucwords() expects at most 2 parameters, 3 given in %s on line %d
|
||||
NULL
|
||||
string(10) "string_val"
|
||||
Done
|
||||
|
|
25
ext/standard/tests/strings/ucwords_variation5.phpt
Normal file
25
ext/standard/tests/strings/ucwords_variation5.phpt
Normal file
|
@ -0,0 +1,25 @@
|
|||
--TEST--
|
||||
Test ucwords() function : usage variations - custom delimiters
|
||||
--FILE--
|
||||
<?php
|
||||
/* Prototype : string ucwords ( string $str )
|
||||
* Description: Uppercase the first character of each word in a string
|
||||
* Source code: ext/standard/string.c
|
||||
*/
|
||||
|
||||
echo "*** Testing ucwords() : usage variations ***\n";
|
||||
|
||||
var_dump(ucwords('testing-dashed-words', '-'));
|
||||
var_dump(ucwords('test(braced)words', '()'));
|
||||
var_dump(ucwords('testing empty delimiters', ''));
|
||||
var_dump(ucwords('testing ranges', 'a..e'));
|
||||
|
||||
echo "Done\n";
|
||||
?>
|
||||
--EXPECTF--
|
||||
*** Testing ucwords() : usage variations ***
|
||||
string(%d) "Testing-Dashed-Words"
|
||||
string(%d) "Test(Braced)Words"
|
||||
string(%d) "Testing empty delimiters"
|
||||
string(%d) "TeSting raNgeS"
|
||||
Done
|
Loading…
Add table
Add a link
Reference in a new issue