[PHP-CVS] cvs: php-src / NEWS /ext/standard string.c /ext/standard/tests/strings stristr.phpt strstr.phpt

2005-08-09 Thread Johannes Schl
johannesTue Aug  9 16:49:19 2005 EDT

  Added files: 
/php-src/ext/standard/tests/strings stristr.phpt 

  Modified files:  
/php-srcNEWS 
/php-src/ext/standard   string.c 
/php-src/ext/standard/tests/strings strstr.phpt 
  Log:
  - Added option to strstr() and stristr() to get a particular haystack 
component
  
http://cvs.php.net/diff.php/php-src/NEWS?r1=1.2030r2=1.2031ty=u
Index: php-src/NEWS
diff -u php-src/NEWS:1.2030 php-src/NEWS:1.2031
--- php-src/NEWS:1.2030 Tue Aug  9 11:07:18 2005
+++ php-src/NEWSTue Aug  9 16:49:12 2005
@@ -6,6 +6,8 @@
   . Added CURLINFO_HEADER_OUT to facilitate request retrieval.
 - Added an optional parameter to parse_url() to allow retrieval of distinct URL
   components. (Ilia)
+- Added an optional parameter to strstr() and stristr() for retrieval of either
+  the part of haystack before or after first occurence of needle. (Johannes)
 
 ?? ??? 2005, PHP 5.1
 - Upgraded PCRE library to version 6.2. (Andrei)
http://cvs.php.net/diff.php/php-src/ext/standard/string.c?r1=1.445r2=1.446ty=u
Index: php-src/ext/standard/string.c
diff -u php-src/ext/standard/string.c:1.445 php-src/ext/standard/string.c:1.446
--- php-src/ext/standard/string.c:1.445 Wed Aug  3 10:08:13 2005
+++ php-src/ext/standard/string.c   Tue Aug  9 16:49:18 2005
@@ -18,7 +18,7 @@
+--+
  */
 
-/* $Id: string.c,v 1.445 2005/08/03 14:08:13 sniper Exp $ */
+/* $Id: string.c,v 1.446 2005/08/09 20:49:18 johannes Exp $ */
 
 /* Synced with php 3.0 revision 1.193 1999-06-16 [ssb] */
 
@@ -1433,52 +1433,60 @@
 }
 /* }}} */
 
-/* {{{ proto string stristr(string haystack, string needle)
+/* {{{ proto string stristr(string haystack, string needle[, bool part])
Finds first occurrence of a string within another, case insensitive */
 PHP_FUNCTION(stristr)
 {
-   zval **haystack, **needle;
+   char *haystack;
+   long haystack_len;
+   zval *needle;
+   zend_bool part = 0;
char *found = NULL;
int  found_offset;
char *haystack_orig;
char needle_char[2];

-   if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, haystack, 
needle) == FAILURE) {
-   WRONG_PARAM_COUNT;
+   if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, sz|b, haystack, 
haystack_len, needle, part) == FAILURE) {
+   return;
}
 
-   SEPARATE_ZVAL(haystack);
-   SEPARATE_ZVAL(needle);
-   
-   convert_to_string_ex(haystack);
+   SEPARATE_ZVAL(needle);
 
-   haystack_orig = estrndup(Z_STRVAL_PP(haystack), Z_STRLEN_PP(haystack));
+   haystack_orig = estrndup(haystack, haystack_len);
 
-   if (Z_TYPE_PP(needle) == IS_STRING) {
-   if (!Z_STRLEN_PP(needle)) {
+   if (Z_TYPE_P(needle) == IS_STRING) {
+   if (!Z_STRLEN_P(needle)) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, Empty 
delimiter.);
efree(haystack_orig);
RETURN_FALSE;
}
 
-   found = php_stristr(Z_STRVAL_PP(haystack),
-   Z_STRVAL_PP(needle),
-   Z_STRLEN_PP(haystack),
-   Z_STRLEN_PP(needle));
+   found = php_stristr(haystack,
+   Z_STRVAL_P(needle),
+   haystack_len,
+   Z_STRLEN_P(needle));
} else {
-   convert_to_long_ex(needle);
-   needle_char[0] = (char) Z_LVAL_PP(needle);
+   convert_to_long_ex(needle);
+   needle_char[0] = (char) Z_LVAL_P(needle);
needle_char[1] = 0;
 
-   found = php_stristr(Z_STRVAL_PP(haystack),
+   found = php_stristr(haystack,
needle_char,
-   Z_STRLEN_PP(haystack),
+   haystack_len,
1);
}
 
if (found) {
-   found_offset = found - Z_STRVAL_PP(haystack);
-   RETVAL_STRINGL(haystack_orig + found_offset, 
Z_STRLEN_PP(haystack) - found_offset, 1);
+   found_offset = found - haystack;
+   if (part) {
+   char *ret;
+   ret = emalloc(found_offset + 1);
+   strncpy(ret, haystack_orig, found_offset);
+   ret[found_offset] = '\0';
+   RETVAL_STRINGL(ret , found_offset, 0);
+   } else {
+   RETVAL_STRINGL(haystack_orig + found_offset, 
haystack_len - found_offset, 

Re: [PHP-CVS] cvs: php-src / NEWS /ext/standard string.c /ext/standard/tests/strings stristr.phpt strstr.phpt

2005-08-09 Thread Wez Furlong
Err, aren't we in a feature freeze?

--Wez.

On 8/9/05, Johannes Schlüter [EMAIL PROTECTED] wrote:
 johannesTue Aug  9 16:49:19 2005 EDT
 
   Added files:
 /php-src/ext/standard/tests/strings stristr.phpt
 
   Modified files:
 /php-srcNEWS
 /php-src/ext/standard   string.c
 /php-src/ext/standard/tests/strings strstr.phpt
   Log:
   - Added option to strstr() and stristr() to get a particular haystack 
 component
 
 http://cvs.php.net/diff.php/php-src/NEWS?r1=1.2030r2=1.2031ty=u
 Index: php-src/NEWS
 diff -u php-src/NEWS:1.2030 php-src/NEWS:1.2031
 --- php-src/NEWS:1.2030 Tue Aug  9 11:07:18 2005
 +++ php-src/NEWSTue Aug  9 16:49:12 2005
 @@ -6,6 +6,8 @@
. Added CURLINFO_HEADER_OUT to facilitate request retrieval.
  - Added an optional parameter to parse_url() to allow retrieval of distinct 
 URL
components. (Ilia)
 +- Added an optional parameter to strstr() and stristr() for retrieval of 
 either
 +  the part of haystack before or after first occurence of needle. (Johannes)
 
  ?? ??? 2005, PHP 5.1
  - Upgraded PCRE library to version 6.2. (Andrei)
 http://cvs.php.net/diff.php/php-src/ext/standard/string.c?r1=1.445r2=1.446ty=u
 Index: php-src/ext/standard/string.c
 diff -u php-src/ext/standard/string.c:1.445 
 php-src/ext/standard/string.c:1.446
 --- php-src/ext/standard/string.c:1.445 Wed Aug  3 10:08:13 2005
 +++ php-src/ext/standard/string.c   Tue Aug  9 16:49:18 2005
 @@ -18,7 +18,7 @@
 +--+
   */
 
 -/* $Id: string.c,v 1.445 2005/08/03 14:08:13 sniper Exp $ */
 +/* $Id: string.c,v 1.446 2005/08/09 20:49:18 johannes Exp $ */
 
  /* Synced with php 3.0 revision 1.193 1999-06-16 [ssb] */
 
 @@ -1433,52 +1433,60 @@
  }
  /* }}} */
 
 -/* {{{ proto string stristr(string haystack, string needle)
 +/* {{{ proto string stristr(string haystack, string needle[, bool part])
 Finds first occurrence of a string within another, case insensitive */
  PHP_FUNCTION(stristr)
  {
 -   zval **haystack, **needle;
 +   char *haystack;
 +   long haystack_len;
 +   zval *needle;
 +   zend_bool part = 0;
 char *found = NULL;
 int  found_offset;
 char *haystack_orig;
 char needle_char[2];
 
 -   if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, haystack, 
 needle) == FAILURE) {
 -   WRONG_PARAM_COUNT;
 +   if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, sz|b, 
 haystack, haystack_len, needle, part) == FAILURE) {
 +   return;
 }
 
 -   SEPARATE_ZVAL(haystack);
 -   SEPARATE_ZVAL(needle);
 -
 -   convert_to_string_ex(haystack);
 +   SEPARATE_ZVAL(needle);
 
 -   haystack_orig = estrndup(Z_STRVAL_PP(haystack), 
 Z_STRLEN_PP(haystack));
 +   haystack_orig = estrndup(haystack, haystack_len);
 
 -   if (Z_TYPE_PP(needle) == IS_STRING) {
 -   if (!Z_STRLEN_PP(needle)) {
 +   if (Z_TYPE_P(needle) == IS_STRING) {
 +   if (!Z_STRLEN_P(needle)) {
 php_error_docref(NULL TSRMLS_CC, E_WARNING, Empty 
 delimiter.);
 efree(haystack_orig);
 RETURN_FALSE;
 }
 
 -   found = php_stristr(Z_STRVAL_PP(haystack),
 -   Z_STRVAL_PP(needle),
 -   Z_STRLEN_PP(haystack),
 -   Z_STRLEN_PP(needle));
 +   found = php_stristr(haystack,
 +   Z_STRVAL_P(needle),
 +   haystack_len,
 +   Z_STRLEN_P(needle));
 } else {
 -   convert_to_long_ex(needle);
 -   needle_char[0] = (char) Z_LVAL_PP(needle);
 +   convert_to_long_ex(needle);
 +   needle_char[0] = (char) Z_LVAL_P(needle);
 needle_char[1] = 0;
 
 -   found = php_stristr(Z_STRVAL_PP(haystack),
 +   found = php_stristr(haystack,
 needle_char,
 -   Z_STRLEN_PP(haystack),
 +   haystack_len,
 1);
 }
 
 if (found) {
 -   found_offset = found - Z_STRVAL_PP(haystack);
 -   RETVAL_STRINGL(haystack_orig + found_offset, 
 Z_STRLEN_PP(haystack) - found_offset, 1);
 +   found_offset = found - haystack;
 +   if (part) {
 +   char *ret;
 +   ret = emalloc(found_offset + 1);
 +   strncpy(ret, haystack_orig, found_offset);
 +   ret[found_offset] = '\0';
 + 

Re: [PHP-CVS] cvs: php-src / NEWS /ext/standard string.c /ext/standard/tests/strings stristr.phpt strstr.phpt

2005-08-09 Thread Rasmus Lerdorf
Wez Furlong wrote:
 We quite clearly agreed to a total freeze while Andrei and Dmitry
 merge the unicode stuff.
 It's a *huge* patch, so let's please respect the time they are
 investing into this and keep our f***ing hands off the repos until
 they're done.

Well, it's going to take a while to merge this stuff.  But yes, try to
avoid any changes to Zend/* or main/* or ext/standard/*

I think most other areas should be ok.

-Rasmus

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-CVS] cvs: php-src / NEWS /ext/standard string.c /ext/standard/tests/strings stristr.phpt strstr.phpt

2005-08-09 Thread Andrei Zmievski
Yep, those are the bigs ones. The merge won't happen until a day or two 
from now (struggling with stupid 'patch' program), but please, don't 
commit anything in those areas.


-Andrei

On Aug 9, 2005, at 2:12 PM, Rasmus Lerdorf wrote:


Wez Furlong wrote:

We quite clearly agreed to a total freeze while Andrei and Dmitry
merge the unicode stuff.
It's a *huge* patch, so let's please respect the time they are
investing into this and keep our f***ing hands off the repos until
they're done.


Well, it's going to take a while to merge this stuff.  But yes, try to
avoid any changes to Zend/* or main/* or ext/standard/*

I think most other areas should be ok.

-Rasmus

--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-CVS] cvs: php-src / NEWS /ext/standard string.c /ext/standard/tests/strings stristr.phpt strstr.phpt

2005-08-09 Thread Adam Maccabee Trachtenberg
On Tue, 9 Aug 2005, Andrei Zmievski wrote:

 Yep, those are the bigs ones. The merge won't happen until a day or two
 from now (struggling with stupid 'patch' program), but please, don't
 commit anything in those areas.

If only Rasmus had written patch instead of Larry, then patch would be
PHP's friend instead of Perl's. :)

-adam

-- 
[EMAIL PROTECTED] | http://www.trachtenberg.com
author of o'reilly's upgrading to php 5 and php cookbook
avoid the holiday rush, buy your copies today!

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-CVS] cvs: php-src / NEWS /ext/standard string.c /ext/standard/tests/strings stristr.phpt strstr.phpt

2005-08-09 Thread Andi Gutmans

Please use strlcpy() and not strncpy().
http://www.courtesan.com/todd/papers/strlcpy.html for more info

PHP bundles this functionality...

Andi

At 08:49 PM 8/9/2005 +, Johannes Schlüter wrote:

johannesTue Aug  9 16:49:19 2005 EDT

  Added files:
/php-src/ext/standard/tests/strings stristr.phpt

  Modified files:
/php-srcNEWS
/php-src/ext/standard   string.c
/php-src/ext/standard/tests/strings strstr.phpt
  Log:
  - Added option to strstr() and stristr() to get a particular haystack 
component


http://cvs.php.net/diff.php/php-src/NEWS?r1=1.2030r2=1.2031ty=u
Index: php-src/NEWS
diff -u php-src/NEWS:1.2030 php-src/NEWS:1.2031
--- php-src/NEWS:1.2030 Tue Aug  9 11:07:18 2005
+++ php-src/NEWSTue Aug  9 16:49:12 2005
@@ -6,6 +6,8 @@
   . Added CURLINFO_HEADER_OUT to facilitate request retrieval.
 - Added an optional parameter to parse_url() to allow retrieval of 
distinct URL

   components. (Ilia)
+- Added an optional parameter to strstr() and stristr() for retrieval of 
either

+  the part of haystack before or after first occurence of needle. (Johannes)

 ?? ??? 2005, PHP 5.1
 - Upgraded PCRE library to version 6.2. (Andrei)
http://cvs.php.net/diff.php/php-src/ext/standard/string.c?r1=1.445r2=1.446ty=u
Index: php-src/ext/standard/string.c
diff -u php-src/ext/standard/string.c:1.445 
php-src/ext/standard/string.c:1.446

--- php-src/ext/standard/string.c:1.445 Wed Aug  3 10:08:13 2005
+++ php-src/ext/standard/string.c   Tue Aug  9 16:49:18 2005
@@ -18,7 +18,7 @@
+--+
  */

-/* $Id: string.c,v 1.445 2005/08/03 14:08:13 sniper Exp $ */
+/* $Id: string.c,v 1.446 2005/08/09 20:49:18 johannes Exp $ */

 /* Synced with php 3.0 revision 1.193 1999-06-16 [ssb] */

@@ -1433,52 +1433,60 @@
 }
 /* }}} */

-/* {{{ proto string stristr(string haystack, string needle)
+/* {{{ proto string stristr(string haystack, string needle[, bool part])
Finds first occurrence of a string within another, case insensitive */
 PHP_FUNCTION(stristr)
 {
-   zval **haystack, **needle;
+   char *haystack;
+   long haystack_len;
+   zval *needle;
+   zend_bool part = 0;
char *found = NULL;
int  found_offset;
char *haystack_orig;
char needle_char[2];

-   if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, haystack, 
needle) == FAILURE) {

-   WRONG_PARAM_COUNT;
+   if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, sz|b, 
haystack, haystack_len, needle, part) == FAILURE) {

+   return;
}

-   SEPARATE_ZVAL(haystack);
-   SEPARATE_ZVAL(needle);
-
-   convert_to_string_ex(haystack);
+   SEPARATE_ZVAL(needle);

-   haystack_orig = estrndup(Z_STRVAL_PP(haystack), 
Z_STRLEN_PP(haystack));

+   haystack_orig = estrndup(haystack, haystack_len);

-   if (Z_TYPE_PP(needle) == IS_STRING) {
-   if (!Z_STRLEN_PP(needle)) {
+   if (Z_TYPE_P(needle) == IS_STRING) {
+   if (!Z_STRLEN_P(needle)) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, 
Empty delimiter.);

efree(haystack_orig);
RETURN_FALSE;
}

-   found = php_stristr(Z_STRVAL_PP(haystack),
-   Z_STRVAL_PP(needle),
-   Z_STRLEN_PP(haystack),
-   Z_STRLEN_PP(needle));
+   found = php_stristr(haystack,
+   Z_STRVAL_P(needle),
+   haystack_len,
+   Z_STRLEN_P(needle));
} else {
-   convert_to_long_ex(needle);
-   needle_char[0] = (char) Z_LVAL_PP(needle);
+   convert_to_long_ex(needle);
+   needle_char[0] = (char) Z_LVAL_P(needle);
needle_char[1] = 0;

-   found = php_stristr(Z_STRVAL_PP(haystack),
+   found = php_stristr(haystack,
needle_char,
-   Z_STRLEN_PP(haystack),
+   haystack_len,
1);
}

if (found) {
-   found_offset = found - Z_STRVAL_PP(haystack);
-   RETVAL_STRINGL(haystack_orig + found_offset, 
Z_STRLEN_PP(haystack) - found_offset, 1);

+   found_offset = found - haystack;
+   if (part) {
+   char *ret;
+   ret = emalloc(found_offset + 1);
+   strncpy(ret, haystack_orig, found_offset);
+   ret[found_offset] = '\0';
+