Hi -

I'd like to ask that the pcre_match*() functions be modified such that
they can also return position info on where the match(s) occured, akin to
Perl's pos(). I think this would be a very useful addition, plus it
requires minimal code changes since the actual function, php_pcre_match()
computes the values presently but just throws them away.

I've modified my own build to do this, and I've attached a diff...but I'd
regard this as proof-of-concept code since I did it in a hurry (so maybe
it can make 4.2.0?) and I haven't coded in C since my university classes
couple years back. It's actually kinda of embarassing, but heck I don't
know any of you. =P.

The only really difficulty would be deciding how to return the
values...I've thought up a bunch of ways of implementing this
other than the stupidly simple add another nested array I did, like use a
resource, a new function, return a 2nd array, etc.


--Ricky
326d324
< 

328c326
<       zval                    **position;     /* Option to return match positions */

---
> 

342d339
<       int                              position_val      = 0; /* Integer value of 
position_flag */
369,387c366
<                       /* Make sure subpats_order*/ 

<                       convert_to_long_ex(subpats_order);

<               

<                       subpats_order_val = Z_LVAL_PP(subpats_order);

< 

<                       if (subpats_order_val < PREG_PATTERN_ORDER ||

<                               subpats_order_val > PREG_SET_ORDER) {

<                               zend_error(E_WARNING, "Wrong value for parameter 4 in 
call to preg_match_all()");

<                       }

< 

< 

<                       break;

<               case 5:

<                       if (zend_get_parameters_ex(5, &regex, &subject, &subpats, 
&subpats_order, &position) == FAILURE) {

<                               WRONG_PARAM_COUNT;

<                       }

<               

<       
<                       /* Make sure subpats_order/ position flag is a number */
---
>                       /* Make sure subpats_order is a number */
389,390d367
<                       convert_to_long_ex(position);

< 
392,393d368
<                       position_val = Z_LVAL_PP(position);

< 

429d403
<               if (position_val) {

431d404
<               }

439d411
<                       if (position_val) {

443d414
<                       }

482a456,459
>                               /* add position information */

> 

> 
> 
487,491c464
<                                               

<                                               /* add position information */

< 

<                                                       if (position_val) {

<                                                               pos = (char 
*)emalloc(16 * sizeof(char));

---
>                                               pos = (char *)emalloc(5 * 
>sizeof(char));

499,500d471
<                                                       }

< 

525,526d495
< 

<                                               if (position_val) {

531c500
<                                                       pos = (char *)emalloc(16 * 
sizeof(char));                                       
---
>                                               pos = (char *)emalloc(5 * 
>sizeof(char));                                        
542d510
<                                                       
zend_hash_next_index_insert(Z_ARRVAL_P(result_set), &match_sets_pos[0], sizeof(zval 
*), NULL);

545c513
<                                               }

---
>                                               
>zend_hash_next_index_insert(Z_ARRVAL_P(result_set), &match_sets_pos[0], sizeof(zval 
>*), NULL);

590d557
<                       if(position_val) {

592d558
<                       } 
596d561
<               if (position_val) { 

598,600d562
<                       efree(pos); 

<               }

<               
-- 
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to