aharvey                                  Thu, 06 Jan 2011 02:32:02 +0000

Revision: http://svn.php.net/viewvc?view=revision&revision=307147

Log:
Implement request #53659 (Implementing RegexIterator::getRegex() method). Patch
by Joshua Thijssen.

Bug: http://bugs.php.net/53659 (Assigned) Implementing 
RegexIterator::getRegex() method
      
Changed paths:
    U   php/php-src/trunk/NEWS
    U   php/php-src/trunk/UPGRADING
    U   php/php-src/trunk/ext/spl/internal/regexiterator.inc
    U   php/php-src/trunk/ext/spl/spl_iterators.c
    U   php/php-src/trunk/ext/spl/spl_iterators.h
    A   php/php-src/trunk/ext/spl/tests/regexiterator_getregex.phpt

Modified: php/php-src/trunk/NEWS
===================================================================
--- php/php-src/trunk/NEWS      2011-01-06 02:24:49 UTC (rev 307146)
+++ php/php-src/trunk/NEWS      2011-01-06 02:32:02 UTC (rev 307147)
@@ -182,6 +182,7 @@
     either is present at compile time. (Rasmus)

 - Improved SPL extension:
+  . Added RegexIterator::getRegex() method. (Joshua Thijssen)
   . Added SplObjectStorage::getHash() hook. (Etienne)
   . Added SplFileInfo::getExtension(). FR #48767. (Peter Cowburn)


Modified: php/php-src/trunk/UPGRADING
===================================================================
--- php/php-src/trunk/UPGRADING 2011-01-06 02:24:49 UTC (rev 307146)
+++ php/php-src/trunk/UPGRADING 2011-01-06 02:32:02 UTC (rev 307147)
@@ -353,6 +353,9 @@
          - ReflectionClass::getTraitAliases()
          - ReflectionParameter::canBePassedByValue()

+       - RegexIterator
+         - RegexIterator::getRegex()
+
        - PDO_dblib
          - PDO::newRowset()


Modified: php/php-src/trunk/ext/spl/internal/regexiterator.inc
===================================================================
--- php/php-src/trunk/ext/spl/internal/regexiterator.inc        2011-01-06 
02:24:49 UTC (rev 307146)
+++ php/php-src/trunk/ext/spl/internal/regexiterator.inc        2011-01-06 
02:32:02 UTC (rev 307147)
@@ -158,6 +158,13 @@
        {
                $this->preg_flags = $preg_flags;
        }
+
+       /** @return current regular expression
+       */
+       function getRegex()
+       {
+               return $this->regex;
+       }
 }

 ?>

Modified: php/php-src/trunk/ext/spl/spl_iterators.c
===================================================================
--- php/php-src/trunk/ext/spl/spl_iterators.c   2011-01-06 02:24:49 UTC (rev 
307146)
+++ php/php-src/trunk/ext/spl/spl_iterators.c   2011-01-06 02:32:02 UTC (rev 
307147)
@@ -1465,6 +1465,7 @@
                        }
                        intern->u.regex.mode = mode;
                        intern->u.regex.regex = estrndup(regex, regex_len);
+                       intern->u.regex.regex_len = regex_len;
                        intern->u.regex.pce = 
pcre_get_compiled_regex_cache(regex, regex_len TSRMLS_CC);
                        if (intern->u.regex.pce == NULL) {
                                /* pcre_get_compiled_regex_cache has already 
sent error */
@@ -1941,6 +1942,19 @@
        }
 } /* }}} */

+/* {{{ proto string RegexIterator::getRegex()
+   Returns current regular expression */
+SPL_METHOD(RegexIterator, getRegex)
+{
+       spl_dual_it_object *intern = 
(spl_dual_it_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
+
+       if (zend_parse_parameters_none() == FAILURE) {
+               return;
+       }
+
+       RETURN_STRINGL(intern->u.regex.regex, intern->u.regex.regex_len, 1);
+} /* }}} */
+
 /* {{{ proto bool RegexIterator::getMode()
    Returns current operation mode */
 SPL_METHOD(RegexIterator, getMode)
@@ -2205,6 +2219,7 @@
        SPL_ME(RegexIterator,   setFlags,         arginfo_regex_it_set_flags,   
   ZEND_ACC_PUBLIC)
        SPL_ME(RegexIterator,   getPregFlags,     arginfo_recursive_it_void,    
   ZEND_ACC_PUBLIC)
        SPL_ME(RegexIterator,   setPregFlags,     
arginfo_regex_it_set_preg_flags, ZEND_ACC_PUBLIC)
+       SPL_ME(RegexIterator,   getRegex,         arginfo_recursive_it_void,    
   ZEND_ACC_PUBLIC)
        {NULL, NULL, NULL}
 };


Modified: php/php-src/trunk/ext/spl/spl_iterators.h
===================================================================
--- php/php-src/trunk/ext/spl/spl_iterators.h   2011-01-06 02:24:49 UTC (rev 
307146)
+++ php/php-src/trunk/ext/spl/spl_iterators.h   2011-01-06 02:32:02 UTC (rev 
307147)
@@ -154,6 +154,7 @@
                        long             preg_flags;
                        pcre_cache_entry *pce;
                        char             *regex;
+                       uint             regex_len;
                } regex;
 #endif
        } u;

Added: php/php-src/trunk/ext/spl/tests/regexiterator_getregex.phpt
===================================================================
--- php/php-src/trunk/ext/spl/tests/regexiterator_getregex.phpt                 
        (rev 0)
+++ php/php-src/trunk/ext/spl/tests/regexiterator_getregex.phpt 2011-01-06 
02:32:02 UTC (rev 307147)
@@ -0,0 +1,29 @@
+--TEST--
+SPL: RegexIterator::getRegex() basic tests
+--CREDITS--
+Joshua Thijssen <jthijs...@noxlogic.nl>
+--FILE--
+<?php
+
+$array = array('cat', 'hat', 'sat');
+$iterator = new ArrayIterator($array);
+
+# Simple regex
+$regexIterator = new RegexIterator($iterator, '/.at/');
+var_dump($regexIterator->getRegex());
+
+# Empty regular expression
+$regexIterator = new RegexIterator($iterator, '//');
+var_dump($regexIterator->getRegex());
+
+# "Complex" email regular expression
+$regexIterator = new RegexIterator($iterator, 
'|\b[a-z0-9._%...@[a-z0-9.-]+\.[a-z]{2,4}\b|');
+var_dump($regexIterator->getRegex());
+
+
+
+?>
+--EXPECT--
+string(5) "/.at/"
+string(2) "//"
+string(43) "|\b[a-z0-9._%...@[a-z0-9.-]+\.[a-z]{2,4}\b|"

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

Reply via email to