]> granicus.if.org Git - php/commitdiff
Fixed bug in str_word_count() when charlist if specified and "word" starts
authorIlia Alshanetsky <iliaa@php.net>
Sat, 23 Jul 2005 19:44:13 +0000 (19:44 +0000)
committerIlia Alshanetsky <iliaa@php.net>
Sat, 23 Jul 2005 19:44:13 +0000 (19:44 +0000)
with a character found inside the charlist.

ext/standard/string.c
ext/standard/tests/strings/str_word_count.phpt

index e5164d5bfb6adb2d303e675db2cba5d9c29a2976..d48de12172b28fc8d845b18136a33e2d29dee7c8 100644 (file)
@@ -4739,8 +4739,8 @@ PHP_FUNCTION(str_word_count)
        }
        
        while (p < e) {
-               if (isalpha(*p++)) {
-                       s = p - 1;
+               if (isalpha(*p) || (char_list && ch[(unsigned char)*p])) {
+                       s = ++p - 1;
                        while (isalpha(*p) || *p == '\'' || (*p == '-' && isalpha(*(p+1))) || (char_list && ch[(unsigned char)*p])) {
                                p++;
                        }
@@ -4761,7 +4761,9 @@ PHP_FUNCTION(str_word_count)
                                        word_count++;
                                        break;          
                        }
-               }       
+               } else {
+                       p++;
+               }
        }
        
        if (!type) {
index 49e2c4ba4247f6ce29e4c2f47f0f855f3a8661c4..0c6c5ae5660a813e8e51fef97e18329b441a6855 100644 (file)
@@ -118,7 +118,7 @@ array(6) {
   [2]=>
   string(1) "r"
   [3]=>
-  string(1) "s"
+  string(2) "1s"
   [4]=>
   string(3) "bar"
   [5]=>
@@ -130,7 +130,7 @@ array(5) {
   [1]=>
   string(3) "B4r"
   [2]=>
-  string(1) "s"
+  string(2) "1s"
   [3]=>
   string(3) "bar"
   [4]=>
@@ -181,8 +181,8 @@ array(6) {
   string(1) "B"
   [6]=>
   string(1) "r"
-  [9]=>
-  string(1) "s"
+  [8]=>
+  string(2) "1s"
   [11]=>
   string(3) "bar"
   [15]=>
@@ -193,8 +193,8 @@ array(5) {
   string(3) "F0o"
   [4]=>
   string(3) "B4r"
-  [9]=>
-  string(1) "s"
+  [8]=>
+  string(2) "1s"
   [11]=>
   string(3) "bar"
   [15]=>