cvs: php-src /ext/standard string.c /ext/standard/tests/strings str_word_count.phpt

From: Date: Sat, 12 Mar 2005 17:51:20 +0000
Subject: cvs: php-src /ext/standard string.c /ext/standard/tests/strings str_word_count.phpt
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-30903@lists.php.net to get a copy of this message
iliaa Sat Mar 12 12:51:20 2005 EDT Modified files: /php-src/ext/standard/tests/strings str_word_count.phpt /php-src/ext/standard string.c Log: A more performance friendly version of Andrey's patch. http://cvs.php.net/diff.php/php-src/ext/standard/tests/strings/str_word_count.phpt?r1=1.2&r2=1.3&ty=u Index: php-src/ext/standard/tests/strings/str_word_count.phpt diff -u php-src/ext/standard/tests/strings/str_word_count.phpt:1.2 php-src/ext/standard/tests/strings/str_word_count.phpt:1.3 --- php-src/ext/standard/tests/strings/str_word_count.phpt:1.2 Sat Mar 12 09:41:20 2005 +++ php-src/ext/standard/tests/strings/str_word_count.phpt Sat Mar 12 12:51:18 2005 @@ -68,35 +68,35 @@ string(5) "today" } int(6) +NULL +NULL +NULL +NULL -Warning: str_word_count(): The specified format parameter, '3' is invalid. in %s on line 9 -bool(false) +Warning: str_word_count() expects parameter 2 to be long, array given in %s on line 13 -Warning: str_word_count(): The specified format parameter, '123' is invalid. in %s on line 10 -bool(false) +Warning: Wrong parameter count for str_word_count() in %s on line 13 +NULL -Warning: str_word_count(): The specified format parameter, '-1' is invalid. in %s on line 11 -bool(false) +Warning: str_word_count() expects parameter 2 to be long, string given in %s on line 14 -Warning: str_word_count(): The specified format parameter, '1569325056' is invalid. in %s on line 12 -bool(false) - -Warning: str_word_count(): The specified format parameter, '0' is invalid. in %s on line 13 -bool(false) - -Warning: str_word_count(): The specified format parameter, '0' is invalid. in %s on line 14 -bool(false) +Warning: Wrong parameter count for str_word_count() in %s on line 14 +NULL string(55) "Hello friend, you're looking good today!" int(5) int(6) int(5) -Notice: Array to string conversion in %s on line 21 -int(7) +Warning: str_word_count() expects parameter 3 to be string, array given in %s on line 21 -Notice: Object of class stdClass to string conversion in %s on line 22 -int(7) +Warning: Wrong parameter count for str_word_count() in %s on line 21 +NULL + +Warning: str_word_count() expects parameter 3 to be string, object given in %s on line 22 + +Warning: Wrong parameter count for str_word_count() in %s on line 22 +NULL int(7) array(5) { [0]=> @@ -137,41 +137,15 @@ string(3) "foo" } -Notice: Array to string conversion in %s on line 27 -array(7) { - [0]=> - string(1) "F" - [1]=> - string(1) "o" - [2]=> - string(1) "B" - [3]=> - string(1) "r" - [4]=> - string(1) "s" - [5]=> - string(3) "bar" - [6]=> - string(3) "foo" -} +Warning: str_word_count() expects parameter 3 to be string, array given in %s on line 27 -Notice: Object of class stdClass to string conversion in %s on line 28 -array(7) { - [0]=> - string(1) "F" - [1]=> - string(1) "o" - [2]=> - string(1) "B" - [3]=> - string(1) "r" - [4]=> - string(1) "s" - [5]=> - string(3) "bar" - [6]=> - string(3) "foo" -} +Warning: Wrong parameter count for str_word_count() in %s on line 27 +NULL + +Warning: str_word_count() expects parameter 3 to be string, object given in %s on line 28 + +Warning: Wrong parameter count for str_word_count() in %s on line 28 +NULL array(7) { [0]=> string(1) "F" @@ -227,41 +201,15 @@ string(3) "foo" } -Notice: Array to string conversion in %s on line 33 -array(7) { - [0]=> - string(1) "F" - [2]=> - string(1) "o" - [4]=> - string(1) "B" - [6]=> - string(1) "r" - [9]=> - string(1) "s" - [11]=> - string(3) "bar" - [15]=> - string(3) "foo" -} +Warning: str_word_count() expects parameter 3 to be string, array given in %s on line 33 -Notice: Object of class stdClass to string conversion in %s on line 34 -array(7) { - [0]=> - string(1) "F" - [2]=> - string(1) "o" - [4]=> - string(1) "B" - [6]=> - string(1) "r" - [9]=> - string(1) "s" - [11]=> - string(3) "bar" - [15]=> - string(3) "foo" -} +Warning: Wrong parameter count for str_word_count() in %s on line 33 +NULL + +Warning: str_word_count() expects parameter 3 to be string, object given in %s on line 34 + +Warning: Wrong parameter count for str_word_count() in %s on line 34 +NULL array(7) { [0]=> string(1) "F" http://cvs.php.net/diff.php/php-src/ext/standard/string.c?r1=1.433&r2=1.434&ty=u Index: php-src/ext/standard/string.c diff -u php-src/ext/standard/string.c:1.433 php-src/ext/standard/string.c:1.434 --- php-src/ext/standard/string.c:1.433 Sat Mar 12 09:41:20 2005 +++ php-src/ext/standard/string.c Sat Mar 12 12:51:19 2005 @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: string.c,v 1.433 2005/03/12 14:41:20 andrey Exp $ */ +/* $Id: string.c,v 1.434 2005/03/12 17:51:19 iliaa Exp $ */ /* Synced with php 3.0 revision 1.193 1999-06-16 [ssb] */ @@ -4656,44 +4656,29 @@ */ PHP_FUNCTION(str_word_count) { - zval **str, **o_format, **also_alphas; - char *s, *e, *p, *buf; - char *p_also = NULL; - int word_count = 0; - int type = 0; - int n_args = ZEND_NUM_ARGS(); - - if (n_args > 3 || n_args < 1 || zend_get_parameters_ex(n_args, &str, &o_format, &also_alphas) == FAILURE) { + char *buf, *str, *char_list = NULL, *p, *e, *s, ch[256]; + int str_len, char_list_len, word_count = 0; + long type = 0; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|ls", &str, &str_len, &type, &char_list, &char_list_len) == FAILURE) { WRONG_PARAM_COUNT; } - switch (n_args) { - case 3: - convert_to_string_ex(also_alphas); - if (Z_STRLEN_PP(also_alphas)) { - p_also = Z_STRVAL_PP(also_alphas); - } - case 2: - convert_to_long_ex(o_format); - type = Z_LVAL_PP(o_format); + + if (char_list) { + php_charmask(char_list, char_list_len, ch TSRMLS_CC); + } + + p = str; + e = str + str_len; - if (type != 1 && type !=2 && !(n_args >= 3 && type == 0)) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "The specified format parameter, '%d' is invalid.", type); - RETURN_FALSE; - } - if (type) { - array_init(return_value); - } + if (type == 1 || type == 2) { + array_init(return_value); } - - convert_to_string_ex(str); - e = Z_STRLEN_PP(str) + (p = s = Z_STRVAL_PP(str)); + while (p < e) { if (isalpha(*p++)) { - s = p - 1; /* the word starts at s */ - while (isalpha(*p) || *p == '\'' || (*p == '-' && isalpha(*(p+1))) - || (p_also && php_memnstr(p_also, p, 1, p_also + Z_STRLEN_PP(also_alphas))) - ) - { + s = p - 1; + while (isalpha(*p) || *p == '\'' || (*p == '-' && isalpha(*(p+1))) || (char_list && ch[(unsigned char)*p])) { p++; } @@ -4706,7 +4691,7 @@ break; case 2: buf = estrndup(s, (p-s)); - add_index_stringl(return_value, (s - Z_STRVAL_PP(str)), buf, p-s, 1); + add_index_stringl(return_value, (s - str), buf, p-s, 1); efree(buf); break; default:

« previous php.cvs (#30903) next »