From: Jouni Ahto Date: Thu, 1 Jun 2000 10:07:44 +0000 (+0000) Subject: (ucwords) Another try to fix #4748. X-Git-Tag: PRE_EIGHT_BYTE_ALLOC_PATCH~159 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3c51a88d0c9ce4d10f33278b8d792194d635b868;p=php (ucwords) Another try to fix #4748. --- diff --git a/ext/standard/string.c b/ext/standard/string.c index c46b8817e3..743c0b80eb 100644 --- a/ext/standard/string.c +++ b/ext/standard/string.c @@ -1139,7 +1139,7 @@ PHP_FUNCTION(ucwords) { zval **str; char *r; - char *r_end; + int i, new_word = 1; if (ARG_COUNT(ht) != 1 || zend_get_parameters_ex(1, &str) == FAILURE) { WRONG_PARAM_COUNT; @@ -1151,18 +1151,18 @@ PHP_FUNCTION(ucwords) } *return_value=**str; zval_copy_ctor(return_value); - *return_value->value.str.val = toupper((unsigned char)*return_value->value.str.val); - r=return_value->value.str.val; - r_end = r + (*str)->value.str.len; - while(++rvalue.str.len; i++, r++) { + /* Alpha char preceeded by white space? Uppercase it. */ + if (new_word && isalpha(*r)) { + *r = toupper((unsigned char)*r); + } + /* Find a word boundary. */ + if (isspace(*r)) { + new_word = 1; + } else { + new_word = 0; } } } @@ -2568,3 +2568,10 @@ PHP_FUNCTION(substr_count) RETURN_LONG(count); } /* }}} */ + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * End: + */