Justtechjobs.com Find a programming school near you






Online Campus Both


php4-beta | 200004

[PHP4BETA] cvs: /php4 TODO /php4/ext/pcre php_pcre.c /php4/ext/standard basic_functions.c php_string.h string.c From: Andrei Zmievski (andrei <email protected>)
Date: 04/25/00

andrei Tue Apr 25 17:30:00 2000 EDT

  Modified files:
    /php4 TODO
    /php4/ext/pcre php_pcre.c
    /php4/ext/standard basic_functions.c php_string.h string.c
  Log:
   <email protected> substr_count() from Peter Kovacs. (Andrei)
  # also some todo stuff
  
  
Index: php4/TODO
diff -u php4/TODO:1.68 php4/TODO:1.69
--- php4/TODO:1.68 Sun Apr 23 12:19:55 2000
+++ php4/TODO Tue Apr 25 17:29:58 2000
@@ -31,6 +31,8 @@
     * find a better way to implement script timeouts. SIGVTALRM is used
       by some POSIX threads implementations (i.e. OpenBSD) and is not
       available in ZTS mode.
+ * add aliases to functions to conform to new naming conventions, e.g.
+ str_to_upper().
 
 documentation
 -------------
Index: php4/ext/pcre/php_pcre.c
diff -u php4/ext/pcre/php_pcre.c:1.46 php4/ext/pcre/php_pcre.c:1.47
--- php4/ext/pcre/php_pcre.c:1.46 Thu Apr 6 14:07:41 2000
+++ php4/ext/pcre/php_pcre.c Tue Apr 25 17:29:58 2000
@@ -16,7 +16,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: php_pcre.c,v 1.46 2000/04/06 21:07:41 cmv Exp $ */
+/* $Id: php_pcre.c,v 1.47 2000/04/26 00:29:58 andrei Exp $ */
 
 /*
         TODO:
@@ -24,6 +24,7 @@
         - Make new modifier, similar to /e, that passes matches to
           a user-defined function
         - add option to preg_grep() to return entries that _don't_ match
+ - add option to preg_grep() to return the matching keys
 */
 
 #include "php.h"
Index: php4/ext/standard/basic_functions.c
diff -u php4/ext/standard/basic_functions.c:1.185 php4/ext/standard/basic_functions.c:1.186
--- php4/ext/standard/basic_functions.c:1.185 Wed Apr 19 11:36:50 2000
+++ php4/ext/standard/basic_functions.c Tue Apr 25 17:29:59 2000
@@ -122,6 +122,7 @@
         
         PHP_FE(strnatcmp, NULL)
         PHP_FE(strnatcasecmp, NULL)
+ PHP_FE(substr_count, NULL)
         PHP_FE(strspn, NULL)
         PHP_FE(strcspn, NULL)
         PHP_FE(strtok, NULL)
Index: php4/ext/standard/php_string.h
diff -u php4/ext/standard/php_string.h:1.11 php4/ext/standard/php_string.h:1.12
--- php4/ext/standard/php_string.h:1.11 Wed Apr 12 12:39:02 2000
+++ php4/ext/standard/php_string.h Tue Apr 25 17:29:59 2000
@@ -29,7 +29,7 @@
  */
 
 
-/* $Id: php_string.h,v 1.11 2000/04/12 19:39:02 andrei Exp $ */
+/* $Id: php_string.h,v 1.12 2000/04/26 00:29:59 andrei Exp $ */
 
 /* Synced with php 3.0 revision 1.43 1999-06-16 [ssb] */
 
@@ -84,6 +84,7 @@
 PHP_FUNCTION(substr_replace);
 PHP_FUNCTION(strnatcmp);
 PHP_FUNCTION(strnatcasecmp);
+PHP_FUNCTION(substr_count);
 
 #define strnatcmp(a, b) \
         strnatcmp_ex(a, strlen(a), b, strlen(b), 0)
Index: php4/ext/standard/string.c
diff -u php4/ext/standard/string.c:1.106 php4/ext/standard/string.c:1.107
--- php4/ext/standard/string.c:1.106 Wed Apr 12 12:39:02 2000
+++ php4/ext/standard/string.c Tue Apr 25 17:29:59 2000
@@ -18,7 +18,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: string.c,v 1.106 2000/04/12 19:39:02 andrei Exp $ */
+/* $Id: string.c,v 1.107 2000/04/26 00:29:59 andrei Exp $ */
 
 /* Synced with php 3.0 revision 1.193 1999-06-16 [ssb] */
 
@@ -2473,12 +2473,65 @@
                                                          fold_case));
 }
 
+
+/* {{{ proto int strnatcmp(string s1, string s2)
+ Returns the result of string comparison using 'natural' algorithm */
 PHP_FUNCTION(strnatcmp)
 {
         php_strnatcmp(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0);
 }
+/* }}} */
 
+
+/* {{{ proto int strnatcasecmp(string s1, string s2)
+ Returns the result of case-insensitive string comparison using 'natural' algorithm */
 PHP_FUNCTION(strnatcasecmp)
 {
         php_strnatcmp(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1);
 }
+/* }}} */
+
+
+/* {{{ proto int str_count(string haystack, string needle)
+ Returns the number of times a substring occurs in the string. */
+PHP_FUNCTION(substr_count)
+{
+ zval **haystack, **needle;
+ int i, length, count = 0;
+ char *p, *endp, cmp;
+
+ if (ARG_COUNT(ht) != 2 || zend_get_parameters_ex(2, &haystack, &needle) == FAILURE) {
+ WRONG_PARAM_COUNT;
+ }
+
+ convert_to_string_ex(haystack);
+ convert_to_string_ex(needle);
+
+ if ((*needle)->value.str.len == 0) {
+ php_error(E_WARNING, "Empty substring");
+ RETURN_FALSE;
+ } else if ((*needle)->value.str.len == 1) {
+ // Special optimized case to avoid calls to php_memnstr
+ for (i = 0, p = (*haystack)->value.str.val,
+ length = (*haystack)->value.str.len, cmp = (*needle)->value.str.val[0];
+ i < length; i++) {
+ if (p[i] == cmp) {
+ count++;
+ }
+ }
+ } else {
+ p = (*haystack)->value.str.val;
+ endp = p + (*haystack)->value.str.len;
+ while (p <= endp) {
+ if( (p = php_memnstr(p, (*needle)->value.str.val, (*needle)->value.str.len, endp)) != NULL ) {
+ p += (*needle)->value.str.len;
+ count++;
+ } else {
+ break;
+ }
+ }
+ }
+
+ RETURN_LONG(count);
+}
+/* }}} */

-- 
PHP 4.0 Beta Mailing List <http://www.php.net/version4/>
To unsubscribe, e-mail: php4beta-unsubscribe <email protected>
For additional commands, e-mail: php4beta-help <email protected>
To contact the list administrators, e-mail: php4beta-admin <email protected>