diff options
author | Jouni Ahto <jah@php.net> | 2000-06-01 10:07:44 +0000 |
---|---|---|
committer | Jouni Ahto <jah@php.net> | 2000-06-01 10:07:44 +0000 |
commit | 3c51a88d0c9ce4d10f33278b8d792194d635b868 (patch) | |
tree | 8132a4d218cb26802c5bb38ca84aa376c9561cd8 /ext | |
parent | f27956eb1920aa145a8d541d0916d0e4c6fb7795 (diff) | |
download | php-git-3c51a88d0c9ce4d10f33278b8d792194d635b868.tar.gz |
(ucwords) Another try to fix #4748.
Diffstat (limited to 'ext')
-rw-r--r-- | ext/standard/string.c | 31 |
1 files changed, 19 insertions, 12 deletions
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(++r<r_end){ - if(isspace(*r)) { - if(r < r_end){ - r++; - *r=toupper((unsigned char)*r); - } else { - break; - } + + for (i = 0; i < (*str)->value.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: + */ |