Re: [PHP-CVS] cvs: php-src(PHP_5_3) / NEWS /ext/pcre php_pcre.c /ext/pcre/tests preg_filter.phpt

2008-08-30 Thread Marcus Boerger
Hello Antony,

Friday, August 29, 2008, 11:15:29 PM, you wrote:

 On 29.08.2008 16:13, Marcus Boerger wrote:
 helly Fri Aug 29 12:13:55 2008 UTC
 
   Added files: (Branch: PHP_5_3)
 /php-src/ext/pcre/tests   preg_filter.phpt 

 Don't forget to fix sapi/cli/tests/006.phpt

Fixed - thanks for reminding! :-)

Best regards,
 Marcus


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



[PHP-CVS] cvs: php-src(PHP_5_3) / NEWS /ext/pcre php_pcre.c /ext/pcre/tests preg_filter.phpt

2008-08-29 Thread Marcus Boerger
helly   Fri Aug 29 12:13:55 2008 UTC

  Added files: (Branch: PHP_5_3)
/php-src/ext/pcre/tests preg_filter.phpt 

  Modified files:  
/php-srcNEWS 
/php-src/ext/pcre   php_pcre.c 
  Log:
  - MFH preg_filter()
  # As discussed with Lukas
  # [DOC] check out the test
  
  
http://cvs.php.net/viewvc.cgi/php-src/NEWS?r1=1.2027.2.547.2.965.2.293r2=1.2027.2.547.2.965.2.294diff_format=u
Index: php-src/NEWS
diff -u php-src/NEWS:1.2027.2.547.2.965.2.293 
php-src/NEWS:1.2027.2.547.2.965.2.294
--- php-src/NEWS:1.2027.2.547.2.965.2.293   Fri Aug 29 12:01:32 2008
+++ php-src/NEWSFri Aug 29 12:13:54 2008
@@ -8,6 +8,7 @@
   accessibility (like method_exists()). (Felipe)
 - Changed array_reduce() to allow mixed $initial (Christian Seiler)
 
+- Added function preg_filter() that does grep and replace in one go. (Marcus)
 - Added system independent realpath() implementation which caches intermediate
   directories in realpath-cache. (Dmitry)
 - Added optional clear_realpath_cache and filename parameters to
http://cvs.php.net/viewvc.cgi/php-src/ext/pcre/php_pcre.c?r1=1.168.2.9.2.21.2.21r2=1.168.2.9.2.21.2.22diff_format=u
Index: php-src/ext/pcre/php_pcre.c
diff -u php-src/ext/pcre/php_pcre.c:1.168.2.9.2.21.2.21 
php-src/ext/pcre/php_pcre.c:1.168.2.9.2.21.2.22
--- php-src/ext/pcre/php_pcre.c:1.168.2.9.2.21.2.21 Thu Aug 14 14:37:39 2008
+++ php-src/ext/pcre/php_pcre.c Fri Aug 29 12:13:54 2008
@@ -16,7 +16,7 @@
+--+
  */
 
-/* $Id: php_pcre.c,v 1.168.2.9.2.21.2.21 2008/08/14 14:37:39 nlopess Exp $ */
+/* $Id: php_pcre.c,v 1.168.2.9.2.21.2.22 2008/08/29 12:13:54 helly Exp $ */
 
 #include php.h
 #include php_ini.h
@@ -1196,7 +1196,7 @@
 
 /* {{{ php_replace_in_subject
  */
-static char *php_replace_in_subject(zval *regex, zval *replace, zval 
**subject, int *result_len, int limit, zend_bool is_callable_replace, int 
*replace_count TSRMLS_DC)
+static char *php_replace_in_subject(zval *regex, zval *replace, zval 
**subject, int *result_len, int limit, int is_callable_replace, int 
*replace_count TSRMLS_DC)
 {
zval**regex_entry,
**replace_entry = NULL,
@@ -1284,7 +1284,7 @@
 
 /* {{{ preg_replace_impl
  */
-static void preg_replace_impl(INTERNAL_FUNCTION_PARAMETERS, zend_bool 
is_callable_replace)
+static void preg_replace_impl(INTERNAL_FUNCTION_PARAMETERS, int 
is_callable_replace, int is_filter)
 {
zval   **regex,
   **replace,
@@ -1298,8 +1298,7 @@
char*string_key;
ulongnum_key;
char*callback_name;
-   int  replace_count=0;
-   int *replace_count_ptr=NULL; 
+   int  replace_count=0, old_replace_count;

/* Get function parameters and do error-checking. */
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, ZZZ|lZ, regex, 
replace, subject, limit, zcount) == FAILURE) {
@@ -1312,8 +1311,9 @@
}
 
SEPARATE_ZVAL(replace);
-   if (Z_TYPE_PP(replace) != IS_ARRAY  (Z_TYPE_PP(replace) != IS_OBJECT 
|| !is_callable_replace))
+   if (Z_TYPE_PP(replace) != IS_ARRAY  (Z_TYPE_PP(replace) != IS_OBJECT 
|| !is_callable_replace)) {
convert_to_string_ex(replace);
+   }
if (is_callable_replace) {
if (!zend_is_callable(*replace, 0, callback_name TSRMLS_CC)) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, Requires 
argument 2, '%s', to be a valid callback, callback_name);
@@ -1332,9 +1332,6 @@
if (ZEND_NUM_ARGS()  3) {
limit_val = limit;
}
-   if (ZEND_NUM_ARGS()  4) {
-   replace_count_ptr = replace_count;
-   }

if (Z_TYPE_PP(regex) != IS_ARRAY)
convert_to_string_ex(regex);
@@ -1348,10 +1345,12 @@
   and add the result to the return_value array. */
while (zend_hash_get_current_data(Z_ARRVAL_PP(subject), (void 
**)subject_entry) == SUCCESS) {
SEPARATE_ZVAL(subject_entry);
-   if ((result = php_replace_in_subject(*regex, *replace, 
subject_entry, result_len, limit_val, is_callable_replace, replace_count_ptr 
TSRMLS_CC)) != NULL) {
-   /* Add to return array */
-   
switch(zend_hash_get_current_key(Z_ARRVAL_PP(subject), string_key, num_key, 
0))
-   {
+   old_replace_count = replace_count;
+   if ((result = php_replace_in_subject(*regex, *replace, 
subject_entry, result_len, limit_val, is_callable_replace, replace_count 
TSRMLS_CC)) != NULL) {
+   if (!is_filter || replace_count  
old_replace_count) {
+

Re: [PHP-CVS] cvs: php-src(PHP_5_3) / NEWS /ext/pcre php_pcre.c /ext/pcre/tests preg_filter.phpt

2008-08-29 Thread Hannes Magnusson
On Fri, Aug 29, 2008 at 14:13, Marcus Boerger [EMAIL PROTECTED] wrote:
[...]
 @@ -1879,6 +1894,7 @@
PHP_FE(preg_match_all,  arginfo_preg_match_all)
PHP_FE(preg_replace,arginfo_preg_replace)
PHP_FE(preg_replace_callback,   arginfo_preg_replace_callback)
 +   PHP_FE(preg_filter, arginfo_preg_replace)

The second argument of arginfo_preg_replace is called `callback`...

-Hannes

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



[PHP-CVS] Re: [PHP-DOC] Re: [PHP-CVS] cvs: php-src(PHP_5_3) / NEWS /ext/pcre php_pcre.c /ext/pcre/tests preg_filter.phpt

2008-08-29 Thread Felipe Pena
Em Sex, 2008-08-29 às 21:07 +0200, Hannes Magnusson escreveu:
 On Fri, Aug 29, 2008 at 14:13, Marcus Boerger [EMAIL PROTECTED] wrote:
 [...]
  @@ -1879,6 +1894,7 @@
 PHP_FE(preg_match_all,  arginfo_preg_match_all)
 PHP_FE(preg_replace,arginfo_preg_replace)
 PHP_FE(preg_replace_callback,   arginfo_preg_replace_callback)
  +   PHP_FE(preg_filter, 
  arginfo_preg_replace)
 
 The second argument of arginfo_preg_replace is called `callback`...
 
No, 'callback' is the second argument of arginfo_preg_replace_callback.

 -Hannes
-- 
Regards,
Felipe Pena.


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



[PHP-CVS] Re: [PHP-DOC] Re: [PHP-CVS] cvs: php-src(PHP_5_3) / NEWS /ext/pcre php_pcre.c /ext/pcre/tests preg_filter.phpt

2008-08-29 Thread Hannes Magnusson
On Fri, Aug 29, 2008 at 21:16, Felipe Pena [EMAIL PROTECTED] wrote:
 Em Sex, 2008-08-29 às 21:07 +0200, Hannes Magnusson escreveu:
 On Fri, Aug 29, 2008 at 14:13, Marcus Boerger [EMAIL PROTECTED] wrote:
 [...]
  @@ -1879,6 +1894,7 @@
 PHP_FE(preg_match_all,  arginfo_preg_match_all)
 PHP_FE(preg_replace,arginfo_preg_replace)
 PHP_FE(preg_replace_callback,   arginfo_preg_replace_callback)
  +   PHP_FE(preg_filter, 
  arginfo_preg_replace)

 The second argument of arginfo_preg_replace is called `callback`...

 No, 'callback' is the second argument of arginfo_preg_replace_callback.

Hah! Indeed.
Don't know how I manage to misread that one :D

-Hannes

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



Re: [PHP-CVS] cvs: php-src(PHP_5_3) / NEWS /ext/pcre php_pcre.c /ext/pcre/tests preg_filter.phpt

2008-08-29 Thread Antony Dovgal

On 29.08.2008 16:13, Marcus Boerger wrote:

helly   Fri Aug 29 12:13:55 2008 UTC

  Added files: (Branch: PHP_5_3)
/php-src/ext/pcre/tests	preg_filter.phpt 


Don't forget to fix sapi/cli/tests/006.phpt

--
Wbr, 
Antony Dovgal


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