cvs: php4 /ext/standard/ string.c

[email protected] ("Hartmut Holzgraefe") Thu, 01 Jun 2000 11:47:48 -0000
Newsgroups php.version4
Message-ID <cvshholzgra959860068@cvsserver>
hholzgra		Thu Jun  1 04:47:48 2000 EDT

  Modified files:
    /php4/ext/standard	string.c 
  Log:
  uh, off by one?!! this time it's regression-tested, fast and compact
  
  
Index: php4/ext/standard/string.c
diff -u php4/ext/standard/string.c:1.117 php4/ext/standard/string.c:1.118
--- php4/ext/standard/string.c:1.117	Thu Jun  1 03:07:44 2000
+++ php4/ext/standard/string.c	Thu Jun  1 04:47:48 2000
@@ -18,7 +18,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: string.c,v 1.117 2000/06/01 10:07:44 jah Exp $ */
+/* $Id: string.c,v 1.118 2000/06/01 11:47:48 hholzgra Exp $ */
 
 /* Synced with php 3.0 revision 1.193 1999-06-16 [ssb] */
 
@@ -1138,8 +1138,7 @@
 PHP_FUNCTION(ucwords)
 {
 	zval **str;
-	char *r;
-	int i, new_word = 1;
+	register char *r,*r_end;
 	
 	if (ARG_COUNT(ht) != 1 || zend_get_parameters_ex(1, &str) == FAILURE) {
 		WRONG_PARAM_COUNT;
@@ -1151,18 +1150,12 @@
 	}
 	*return_value=**str;
 	zval_copy_ctor(return_value);
-	r=return_value->value.str.val;
 
-	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;
+	r=return_value->value.str.val;
+	*r=toupper((unsigned char)*r);
+	for(r_end = r + return_value->value.str.len -1 ; r < r_end ; r++ ) {
+		if(isspace(*r)) {
+			*++r=toupper((unsigned char)*r);
 		}
 	}
 }