]> granicus.if.org Git - php/commitdiff
- Synch RegexIterator with HEAD
authorMarcus Boerger <helly@php.net>
Thu, 20 Jul 2006 22:54:21 +0000 (22:54 +0000)
committerMarcus Boerger <helly@php.net>
Thu, 20 Jul 2006 22:54:21 +0000 (22:54 +0000)
12 files changed:
ext/spl/doxygen.cfg
ext/spl/internal/regexiterator.inc
ext/spl/spl_functions.c
ext/spl/spl_functions.h
ext/spl/spl_iterators.c
ext/spl/spl_iterators.h
ext/spl/tests/iterator_050.phpt
ext/spl/tests/iterator_051.phpt
ext/spl/tests/iterator_052.phpt
ext/spl/tests/iterator_053.phpt
ext/spl/tests/iterator_054.phpt
ext/spl/tests/iterator_055.phpt

index d58017a6ad8a0621c85c143d0a2dd609e55fbcae..4b7178723879582463af53ce63653bfc94f35c99 100755 (executable)
@@ -194,10 +194,10 @@ PERL_PATH              = /usr/bin/perl
 #---------------------------------------------------------------------------
 CLASS_DIAGRAMS         = YES
 HIDE_UNDOC_RELATIONS   = YES
-HAVE_DOT               = NO
+HAVE_DOT               = YES
 CLASS_GRAPH            = YES
 COLLABORATION_GRAPH    = YES
-UML_LOOK               = NO
+UML_LOOK               = YES
 TEMPLATE_RELATIONS     = NO
 INCLUDE_GRAPH          = YES
 INCLUDED_BY_GRAPH      = YES
index 8c38dcc56214026d373196762daa5c3f7d61dce9..fd923eb826d9e030ee0a995845f8966625c32982 100755 (executable)
@@ -12,7 +12,7 @@
 /**
  * @brief   Regular expression filter for iterators
  * @author  Marcus Boerger
- * @version 1.1
+ * @version 1.0
  * @since PHP 5.1
  *
  * This filter iterator assumes that the inner iterator 
@@ -26,6 +26,7 @@ class RegexIterator implements FilterIterator
        const GET_MATCH   = 1; /**< Mode: Return the first matche (if any) */
        const ALL_MATCHES = 2; /**< Mode: Return all matches (if any)      */
        const SPLIT       = 3; /**< Mode: Return the split values (if any) */
+       const REPLACE     = 4; /**< Mode: Replace the input key or current */
        
        private $regex;     /**< the regular expression to match against */
        private $flags;     /**< special flags (self::USE_KEY) */
@@ -33,6 +34,7 @@ class RegexIterator implements FilterIterator
                                 self::GET_MATCH, self::ALL_MATCHES, self::SPLIT) */
        private $preg_flags;/**< PREG_* flags, see preg_match(), preg_match_all(), 
                                 preg_split() */ 
+       private $key;       /**< the value used for key() */
        private $current;   /**< the value used for current() */
 
        /**
@@ -41,13 +43,13 @@ class RegexIterator implements FilterIterator
         *
         * @param it          inner iterator
         * @param regex       the regular expression to match
-        * @param flags       special flags (self::USE_KEY)
         * @param mode        operation mode (one of self::MATCH, self::GET_MATCH, 
         *                    self::ALL_MATCHES, self::SPLIT)
+        * @param flags       special flags (self::USE_KEY)
         * @param preg_flags  global PREG_* flags, see preg_match(), 
         *                    preg_match_all(), preg_split()
         */
-       function __construct(Iterator $it, $regex, $flags = 0, $mode = 0, $preg_flags = 0) {
+       function __construct(Iterator $it, $regex, $mode = 0, $flags = 0, $preg_flags = 0) {
                parent::__construct($it);
                $this->regex = $regex;
                $this->flags = $flags;
@@ -66,9 +68,10 @@ class RegexIterator implements FilterIterator
        function accept()
        {
                $matches       = array();
+               $this->key     = parent::key();
                $this->current = parent::current();
                /* note that we use $this->current, rather than calling parent::current() */
-               $subject = ($this->flags & self::USE_KEY) ? parent::key() : $this->current;
+               $subject = ($this->flags & self::USE_KEY) ? $this->key : $this->current;
                switch($this->mode)
                {
                        case self::MATCH:
@@ -85,9 +88,28 @@ class RegexIterator implements FilterIterator
                        case self::SPLIT:
                                $this->current = array();
                                preg_split($this->regex, $subject, $this->current, $this->preg_flags) > 1;
+
+                       case self::REPLACE:
+                               $this->current = array();
+                               $result = preg_replace($this->regex, $this->replacement, $subject);
+                               if ($this->flags & self::USE_KEY)
+                               {
+                                       $this->key = $result;
+                               }
+                               else
+                               {
+                                       $this->current = $result;
+                               }
                }
        }
 
+       /** @return the key after accept has been called
+        */
+       function key()
+       {
+               return $this->key;
+       }
+
        /** @return the current value after accept has been called
         */
        function current()
index 517f9f3e745b241907403cd7f5bc5939ca81b853..4d0864d173594f90a46478687888846e87b9d198 100755 (executable)
@@ -36,7 +36,7 @@ void spl_destroy_class(zend_class_entry ** ppce)
 /* }}} */
 
 /* {{{ spl_register_interface */
-void spl_register_interface(zend_class_entry ** ppce, char * class_name, zend_function_entry *functions TSRMLS_DC)
+void spl_register_interface(zend_class_entry ** ppce, char * class_name, zend_function_entry * functions TSRMLS_DC)
 {
        zend_class_entry ce;
        
@@ -95,14 +95,9 @@ void spl_register_functions(zend_class_entry * class_entry, zend_function_entry
 /* }}} */
 
 /* {{{ spl_register_property */
-void spl_register_property( zend_class_entry * class_entry, char *prop_name, zval *prop_val, int prop_flags TSRMLS_DC)
+void spl_register_property( zend_class_entry * class_entry, char *prop_name, int prop_name_len, int prop_flags TSRMLS_DC)
 {
-       if (!prop_val) {
-               INIT_PZVAL(prop_val);
-               prop_val->type = IS_NULL;
-       }
-
-       zend_declare_property(class_entry, prop_name, strlen(prop_name), prop_val, prop_flags TSRMLS_CC);
+       zend_declare_property_null(class_entry, prop_name, prop_name_len, prop_flags TSRMLS_CC);
 }
 /* }}} */
 
index ac7a0ca89b1e09c8f1c07392c65784ac162d56a6..6b464db84f28b0aae59fa4ef1f3dc2b50382b2db 100755 (executable)
@@ -49,8 +49,8 @@ typedef zend_object_value (*create_object_func_t)(zend_class_entry *class_type T
 #define REGISTER_SPL_FUNCTIONS(class_name, function_list) \
        spl_register_functions(spl_ce_ ## class_name, function_list TSRMLS_CC);
 
-#define REGISTER_SPL_PROPERTY(class_name, prop_name) \
-       spl_register_property(spl_ce_ ## class_name, prop_name, prop_val, prop_flags TSRMLS_CC);
+#define REGISTER_SPL_PROPERTY(class_name, prop_name, prop_flags) \
+       spl_register_property(spl_ce_ ## class_name, prop_name, sizeof(prop_name)-1, prop_flags TSRMLS_CC);
 
 #define REGISTER_SPL_CLASS_CONST_LONG(class_name, const_name, value) \
        zend_declare_class_constant_long(spl_ce_ ## class_name, const_name, sizeof(const_name)-1, (long)value TSRMLS_CC);
@@ -64,7 +64,7 @@ void spl_register_interface(zend_class_entry ** ppce, char * class_name, zend_fu
 
 void spl_register_parent_ce(zend_class_entry * class_entry, zend_class_entry * parent_class TSRMLS_DC);
 void spl_register_functions(zend_class_entry * class_entry, zend_function_entry * function_list TSRMLS_DC);
-void spl_register_property( zend_class_entry * class_entry, char *prop_name, zval *prop_val, int prop_flags TSRMLS_DC);
+void spl_register_property( zend_class_entry * class_entry, char *prop_name, int prop_name_len, int prop_flags TSRMLS_DC);
 
 /* sub: whether to allow subclasses/interfaces
    allow = 0: allow all classes and interfaces
index 42c7d096d2f873c59302aee16fe7ddcc1d7d83eb..756121ab611608af3a7e0dec9419266d9b827e93 100755 (executable)
@@ -994,13 +994,13 @@ static spl_dual_it_object* spl_dual_it_construct(INTERNAL_FUNCTION_PARAMETERS, z
                case DIT_RegexIterator:
                case DIT_RecursiveRegexIterator: {
                        char *regex;
-                       int len, poptions, coptions;
-                       pcre_extra *extra = NULL;
+                       int regex_len;
                        long mode = REGIT_MODE_MATCH;
 
+                       intern->u.regex.use_flags = ZEND_NUM_ARGS() >= 5;
                        intern->u.regex.flags = 0;
                        intern->u.regex.preg_flags = 0;
-                       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Os|lll", &zobject, ce_inner, &regex, &len, &intern->u.regex.flags, &mode, &intern->u.regex.preg_flags) == FAILURE) {
+                       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Os|lll", &zobject, ce_inner, &regex, &regex_len, &mode, &intern->u.regex.flags, &intern->u.regex.preg_flags) == FAILURE) {
                                php_set_error_handling(EH_NORMAL, NULL TSRMLS_CC);
                                return NULL;
                        }
@@ -1010,8 +1010,8 @@ static spl_dual_it_object* spl_dual_it_construct(INTERNAL_FUNCTION_PARAMETERS, z
                                return NULL;
                        }
                        intern->u.regex.mode = mode;
-                       intern->u.regex.regex = estrndup(regex, len);
-                       intern->u.regex.pce = pcre_get_compiled_regex_cache(regex, len, &extra, &poptions, &coptions TSRMLS_CC);
+                       intern->u.regex.regex = estrndup(regex, regex_len);
+                       intern->u.regex.pce = pcre_get_compiled_regex_cache(regex, regex_len TSRMLS_CC);
                        intern->u.regex.pce->refcount++;
                        break;;
                }
@@ -1365,7 +1365,7 @@ SPL_METHOD(ParentIterator, getChildren)
 } /* }}} */
 
 #if HAVE_PCRE || HAVE_BUNDLED_PCRE
-/* {{{ proto void RegexIterator::__construct(Iterator it, string regex [, int flags [, int mode [, int preg_flags]]]) 
+/* {{{ proto void RegexIterator::__construct(Iterator it, string regex [, int mode [, int flags [, int preg_flags]]]) 
    Create an RegexIterator from another iterator and a regular expression */
 SPL_METHOD(RegexIterator, __construct)
 {
@@ -1377,11 +1377,9 @@ SPL_METHOD(RegexIterator, __construct)
 SPL_METHOD(RegexIterator, accept)
 {
        spl_dual_it_object *intern = (spl_dual_it_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
-       char       *subject, tmp[32];
-       int        subject_len, use_copy, count;
-       zval       subject_copy, zcount;
-       pcre       *regex = intern->u.regex.pce->re;
-       pcre_extra *extra = intern->u.regex.pce->extra;
+       char       *subject, tmp[32], *result;
+       int        subject_len, use_copy, count, result_len;
+       zval       subject_copy, zcount, *replacement;
 
        if (intern->u.regex.flags & REGIT_USE_KEY) {
                if (intern->current.key_type == HASH_KEY_IS_LONG) {
@@ -1408,7 +1406,7 @@ SPL_METHOD(RegexIterator, accept)
        {
        case REGIT_MODE_MAX: /* won't happen but makes compiler happy */
        case REGIT_MODE_MATCH:
-               count = pcre_exec(regex, extra, subject, subject_len, 0, 0, NULL, 0);
+               count = pcre_exec(intern->u.regex.pce->re, intern->u.regex.pce->extra, subject, subject_len, 0, 0, NULL, 0);
                RETVAL_BOOL(count >= 0);
                break;
 
@@ -1419,9 +1417,9 @@ SPL_METHOD(RegexIterator, accept)
                        use_copy = 1;
                }
                zval_ptr_dtor(&intern->current.data);
-               MAKE_STD_ZVAL(intern->current.data);
-               php_pcre_match(regex, extra, subject, subject_len, &zcount, 
-                       intern->current.data, intern->u.regex.mode == REGIT_MODE_ALL_MATCHES, 0, 0, 0, 0 TSRMLS_CC);
+               ALLOC_INIT_ZVAL(intern->current.data);
+               php_pcre_match_impl(intern->u.regex.pce, subject, subject_len, &zcount, 
+                       intern->current.data, intern->u.regex.mode == REGIT_MODE_ALL_MATCHES, intern->u.regex.use_flags, intern->u.regex.preg_flags, 0 TSRMLS_CC);
                count = zend_hash_num_elements(Z_ARRVAL_P(intern->current.data));
                RETVAL_BOOL(count > 0);
                break;
@@ -1432,11 +1430,28 @@ SPL_METHOD(RegexIterator, accept)
                        use_copy = 1;
                }
                zval_ptr_dtor(&intern->current.data);
-               MAKE_STD_ZVAL(intern->current.data);
-               php_pcre_split(regex, extra, subject, subject_len, intern->current.data, 0, -1, 0, 0, 0 TSRMLS_CC);
+               ALLOC_INIT_ZVAL(intern->current.data);
+               php_pcre_split_impl(intern->u.regex.pce, subject, subject_len, intern->current.data, -1, intern->u.regex.preg_flags TSRMLS_CC);
                count = zend_hash_num_elements(Z_ARRVAL_P(intern->current.data));
                RETVAL_BOOL(count > 1);
                break;
+
+       case REGIT_MODE_REPLACE:
+               replacement = zend_read_property(intern->std.ce, getThis(), "replacement", sizeof("replacement")-1, 1 TSRMLS_CC);
+               result = php_pcre_replace_impl(intern->u.regex.pce, subject, subject_len, replacement, 0, &result_len, 0, NULL TSRMLS_CC);
+               
+               if (intern->u.regex.flags & REGIT_USE_KEY) {
+                       if (intern->current.key_type != HASH_KEY_IS_LONG) {
+                               efree(intern->current.str_key);
+                       }
+                       intern->current.key_type = HASH_KEY_IS_STRING;
+                       intern->current.str_key = result;
+                       intern->current.str_key_len = result_len + 1;
+               } else {
+                       zval_ptr_dtor(&intern->current.data);
+                       MAKE_STD_ZVAL(intern->current.data);
+                       ZVAL_STRINGL(intern->current.data, result, result_len, 0);
+               }
        }
 
        if (use_copy) {
@@ -1444,7 +1459,7 @@ SPL_METHOD(RegexIterator, accept)
        }
 } /* }}} */
 
-/* {{{ proto void RecursiveRegexIterator::__construct(RecursiveIterator it, string regex [, int flags [, int mode [, int preg_flags]]]) 
+/* {{{ proto void RecursiveRegexIterator::__construct(RecursiveIterator it, string regex [, int mode [, int flags [, int preg_flags]]]) 
    Create an RecursiveRegexIterator from another recursive iterator and a regular expression */
 SPL_METHOD(RecursiveRegexIterator, __construct)
 {
@@ -1584,8 +1599,8 @@ static
 ZEND_BEGIN_ARG_INFO_EX(arginfo_regex_it___construct, 0, 0, 2) 
        ZEND_ARG_OBJ_INFO(0, iterator, Iterator, 0)
        ZEND_ARG_INFO(0, regex)
-       ZEND_ARG_INFO(0, flags)
        ZEND_ARG_INFO(0, mode)
+       ZEND_ARG_INFO(0, flags)
        ZEND_ARG_INFO(0, preg_flags)
 ZEND_END_ARG_INFO();
 
@@ -2779,6 +2794,8 @@ PHP_MINIT_FUNCTION(spl_iterators)
        REGISTER_SPL_CLASS_CONST_LONG(RegexIterator, "GET_MATCH",   REGIT_MODE_GET_MATCH);
        REGISTER_SPL_CLASS_CONST_LONG(RegexIterator, "ALL_MATCHES", REGIT_MODE_ALL_MATCHES);
        REGISTER_SPL_CLASS_CONST_LONG(RegexIterator, "SPLIT",       REGIT_MODE_SPLIT);
+       REGISTER_SPL_CLASS_CONST_LONG(RegexIterator, "REPLACE",     REGIT_MODE_REPLACE);
+       REGISTER_SPL_PROPERTY(RegexIterator, "replacement", 0);
        REGISTER_SPL_SUB_CLASS_EX(RecursiveRegexIterator, RegexIterator, spl_dual_it_new, spl_funcs_RecursiveRegexIterator);
        REGISTER_SPL_IMPLEMENTS(RecursiveRegexIterator, RecursiveIterator);
 #else
index c2ee24949c8af9992922d6e7f39abde54e06c74c..1d05e4b9844e53930c01e43f6cb132826d31b202 100755 (executable)
@@ -100,6 +100,7 @@ typedef enum {
        REGIT_MODE_GET_MATCH,
        REGIT_MODE_ALL_MATCHES,
        REGIT_MODE_SPLIT,
+       REGIT_MODE_REPLACE,
        REGIT_MODE_MAX,
 } regex_mode;
 
@@ -137,6 +138,7 @@ typedef struct _spl_dual_it_object {
                } append;
 #if HAVE_PCRE || HAVE_BUNDLED_PCRE
                struct {
+                       int              use_flags;
                        int              flags;
                        regex_mode       mode;
                        long             preg_flags;
index 983dfa45738440556b963f701166b9933a77129f..6bd84a3a875012fc3badf5a5d0402312e000c552 100755 (executable)
@@ -18,10 +18,10 @@ class MyRegexIterator extends RegexIterator
 }
 
 $ar = new ArrayIterator(array('1','1,2','1,2,3','',NULL,array(),'FooBar',',',',,'));
-$it = new MyRegexIterator($ar, '/(\d),(\d)/', 0, RegexIterator::GET_MATCH);
+$it = new MyRegexIterator($ar, '/(\d),(\d)/', RegexIterator::GET_MATCH);
 $it->show();
 
-$it = new MyRegexIterator($ar, '/(\d)/', 0, RegexIterator::GET_MATCH);
+$it = new MyRegexIterator($ar, '/(\d)/', RegexIterator::GET_MATCH);
 $it->show();
 
 var_dump($ar);
index d396612ca623c95bff076f71309a5d030cbce3fe..626d27474af1a089450b3b5ac4391c562cef397d 100755 (executable)
@@ -18,10 +18,10 @@ class MyRegexIterator extends RegexIterator
 }
 
 $ar = new ArrayIterator(array('1'=>0,'1,2'=>1,'1,2,3'=>2,0=>3,'FooBar'=>4,','=>5,',,'=>6));
-$it = new MyRegexIterator($ar, '/(\d),(\d)/', RegexIterator::USE_KEY, RegexIterator::GET_MATCH);
+$it = new MyRegexIterator($ar, '/(\d),(\d)/', RegexIterator::GET_MATCH, RegexIterator::USE_KEY);
 $it->show();
 
-$it = new MyRegexIterator($ar, '/(\d)/', RegexIterator::USE_KEY, RegexIterator::GET_MATCH);
+$it = new MyRegexIterator($ar, '/(\d)/', RegexIterator::GET_MATCH, RegexIterator::USE_KEY);
 $it->show();
 
 var_dump($ar);
@@ -93,67 +93,3 @@ object(ArrayIterator)#%d (7) {
   int(6)
 }
 ===DONE===
---UEXPECTF--
-unicode(3) "1,2"
-array(3) {
-  [0]=>
-  string(3) "1,2"
-  [1]=>
-  string(1) "1"
-  [2]=>
-  string(1) "2"
-}
-unicode(5) "1,2,3"
-array(3) {
-  [0]=>
-  string(3) "1,2"
-  [1]=>
-  string(1) "1"
-  [2]=>
-  string(1) "2"
-}
-int(1)
-array(2) {
-  [0]=>
-  string(1) "1"
-  [1]=>
-  string(1) "1"
-}
-unicode(3) "1,2"
-array(2) {
-  [0]=>
-  string(1) "1"
-  [1]=>
-  string(1) "1"
-}
-unicode(5) "1,2,3"
-array(2) {
-  [0]=>
-  string(1) "1"
-  [1]=>
-  string(1) "1"
-}
-int(0)
-array(2) {
-  [0]=>
-  string(1) "0"
-  [1]=>
-  string(1) "0"
-}
-object(ArrayIterator)#%d (7) {
-  [1]=>
-  int(0)
-  [u"1,2"]=>
-  int(1)
-  [u"1,2,3"]=>
-  int(2)
-  [0]=>
-  int(3)
-  [u"FooBar"]=>
-  int(4)
-  [u","]=>
-  int(5)
-  [u",,"]=>
-  int(6)
-}
-===DONE===
index 574868bd65f7ef5de671774ed7fff84c63508c43..9bd7d899ec6877965dfc0c02391f8066a123c67e 100755 (executable)
@@ -7,6 +7,15 @@ SPL: RegexIterator::ALL_MATCHES
 
 class MyRegexIterator extends RegexIterator
 {
+       public $uk, $re;
+       
+       function __construct($it, $re, $mode, $flags = 0)
+       {
+               $this->uk = $flags & self::USE_KEY;
+               $this->re = $re;
+               parent::__construct($it, $re, $mode, $flags);
+       }
+
        function show()
        {
                foreach($this as $k => $v)
@@ -15,13 +24,21 @@ class MyRegexIterator extends RegexIterator
                        var_dump($v);
                }
        }
+       
+       function accept()
+       {
+               @preg_match_all($this->re, (string)($this->uk ? $this->key() : $this->current()), $sub);
+               $ret = parent::accept();
+               var_dump($sub == $this->current());
+               return $ret;
+       }
 }
 
 $ar = new ArrayIterator(array('1','1,2','1,2,3','',NULL,array(),'FooBar',',',',,'));
-$it = new MyRegexIterator($ar, '/(\d),(\d)/', 0, RegexIterator::ALL_MATCHES);
+$it = new MyRegexIterator($ar, '/(\d),(\d)/', RegexIterator::ALL_MATCHES);
 $it->show();
 
-$it = new MyRegexIterator($ar, '/(\d)/', 0, RegexIterator::ALL_MATCHES);
+$it = new MyRegexIterator($ar, '/(\d)/', RegexIterator::ALL_MATCHES);
 $it->show();
 
 var_dump($ar);
@@ -30,40 +47,150 @@ var_dump($ar);
 ===DONE===
 <?php exit(0); ?>
 --EXPECTF--
+bool(true)
+int(0)
+array(3) {
+  [0]=>
+  array(0) {
+  }
+  [1]=>
+  array(0) {
+  }
+  [2]=>
+  array(0) {
+  }
+}
+bool(true)
 int(1)
-array(1) {
+array(3) {
   [0]=>
-  array(3) {
+  array(1) {
     [0]=>
     string(3) "1,2"
-    [1]=>
+  }
+  [1]=>
+  array(1) {
+    [0]=>
     string(1) "1"
-    [2]=>
+  }
+  [2]=>
+  array(1) {
+    [0]=>
     string(1) "2"
   }
 }
+bool(true)
 int(2)
-array(1) {
+array(3) {
   [0]=>
-  array(3) {
+  array(1) {
     [0]=>
     string(3) "1,2"
-    [1]=>
+  }
+  [1]=>
+  array(1) {
+    [0]=>
     string(1) "1"
-    [2]=>
+  }
+  [2]=>
+  array(1) {
+    [0]=>
     string(1) "2"
   }
 }
+bool(true)
+int(3)
+array(3) {
+  [0]=>
+  array(0) {
+  }
+  [1]=>
+  array(0) {
+  }
+  [2]=>
+  array(0) {
+  }
+}
+bool(true)
+int(4)
+array(3) {
+  [0]=>
+  array(0) {
+  }
+  [1]=>
+  array(0) {
+  }
+  [2]=>
+  array(0) {
+  }
+}
+bool(true)
+int(5)
+array(3) {
+  [0]=>
+  array(0) {
+  }
+  [1]=>
+  array(0) {
+  }
+  [2]=>
+  array(0) {
+  }
+}
+bool(true)
+int(6)
+array(3) {
+  [0]=>
+  array(0) {
+  }
+  [1]=>
+  array(0) {
+  }
+  [2]=>
+  array(0) {
+  }
+}
+bool(true)
+int(7)
+array(3) {
+  [0]=>
+  array(0) {
+  }
+  [1]=>
+  array(0) {
+  }
+  [2]=>
+  array(0) {
+  }
+}
+bool(true)
+int(8)
+array(3) {
+  [0]=>
+  array(0) {
+  }
+  [1]=>
+  array(0) {
+  }
+  [2]=>
+  array(0) {
+  }
+}
+bool(true)
 int(0)
-array(1) {
+array(2) {
   [0]=>
-  array(2) {
+  array(1) {
     [0]=>
     string(1) "1"
-    [1]=>
+  }
+  [1]=>
+  array(1) {
+    [0]=>
     string(1) "1"
   }
 }
+bool(true)
 int(1)
 array(2) {
   [0]=>
@@ -71,40 +198,98 @@ array(2) {
     [0]=>
     string(1) "1"
     [1]=>
-    string(1) "1"
+    string(1) "2"
   }
   [1]=>
   array(2) {
     [0]=>
-    string(1) "2"
+    string(1) "1"
     [1]=>
     string(1) "2"
   }
 }
+bool(true)
 int(2)
-array(3) {
+array(2) {
   [0]=>
-  array(2) {
+  array(3) {
     [0]=>
     string(1) "1"
     [1]=>
-    string(1) "1"
+    string(1) "2"
+    [2]=>
+    string(1) "3"
   }
   [1]=>
-  array(2) {
+  array(3) {
     [0]=>
-    string(1) "2"
+    string(1) "1"
     [1]=>
     string(1) "2"
-  }
-  [2]=>
-  array(2) {
-    [0]=>
-    string(1) "3"
-    [1]=>
+    [2]=>
     string(1) "3"
   }
 }
+bool(true)
+int(3)
+array(2) {
+  [0]=>
+  array(0) {
+  }
+  [1]=>
+  array(0) {
+  }
+}
+bool(true)
+int(4)
+array(2) {
+  [0]=>
+  array(0) {
+  }
+  [1]=>
+  array(0) {
+  }
+}
+bool(true)
+int(5)
+array(2) {
+  [0]=>
+  array(0) {
+  }
+  [1]=>
+  array(0) {
+  }
+}
+bool(true)
+int(6)
+array(2) {
+  [0]=>
+  array(0) {
+  }
+  [1]=>
+  array(0) {
+  }
+}
+bool(true)
+int(7)
+array(2) {
+  [0]=>
+  array(0) {
+  }
+  [1]=>
+  array(0) {
+  }
+}
+bool(true)
+int(8)
+array(2) {
+  [0]=>
+  array(0) {
+  }
+  [1]=>
+  array(0) {
+  }
+}
 object(ArrayIterator)#%d (9) {
   [0]=>
   %s(1) "1"
index bc4b1440d66dd7e9d50ce349b89cb8e20d782276..4d68b0113f0bce20f52956bca1971d5751cd9abf 100755 (executable)
@@ -1,5 +1,5 @@
 --TEST--
-SPL: RegexIterator::ALL_MATCHES, USE_KEY
+SPL: RegexIterator::ALL_MATCHES
 --SKIPIF--
 <?php if (!extension_loaded("spl")) print "skip"; ?>
 --FILE--
@@ -7,6 +7,15 @@ SPL: RegexIterator::ALL_MATCHES, USE_KEY
 
 class MyRegexIterator extends RegexIterator
 {
+       public $uk, $re;
+       
+       function __construct($it, $re, $mode, $flags = 0)
+       {
+               $this->uk = $flags & self::USE_KEY;
+               $this->re = $re;
+               parent::__construct($it, $re, $mode, $flags);
+       }
+
        function show()
        {
                foreach($this as $k => $v)
@@ -15,13 +24,21 @@ class MyRegexIterator extends RegexIterator
                        var_dump($v);
                }
        }
+       
+       function accept()
+       {
+               @preg_match_all($this->re, (string)($this->uk ? $this->key() : $this->current()), $sub);
+               $ret = parent::accept();
+               var_dump($sub == $this->current());
+               return $ret;
+       }
 }
 
-$ar = new ArrayIterator(array('1'=>0,'1,2'=>1,'1,2,3'=>2,0=>3,'FooBar'=>4,','=>5,',,'=>6));
-$it = new MyRegexIterator($ar, '/(\d),(\d)/', RegexIterator::USE_KEY, RegexIterator::ALL_MATCHES);
+$ar = new ArrayIterator(array('1','1,2','1,2,3','',NULL,array(),'FooBar',',',',,'));
+$it = new MyRegexIterator($ar, '/(\d),(\d)/', RegexIterator::ALL_MATCHES, RegexIterator::USE_KEY);
 $it->show();
 
-$it = new MyRegexIterator($ar, '/(\d)/', RegexIterator::USE_KEY, RegexIterator::ALL_MATCHES);
+$it = new MyRegexIterator($ar, '/(\d)/', RegexIterator::ALL_MATCHES, RegexIterator::USE_KEY);
 $it->show();
 
 var_dump($ar);
@@ -30,208 +47,268 @@ var_dump($ar);
 ===DONE===
 <?php exit(0); ?>
 --EXPECTF--
-string(3) "1,2"
-array(1) {
+bool(true)
+int(0)
+array(3) {
   [0]=>
-  array(3) {
-    [0]=>
-    string(3) "1,2"
-    [1]=>
-    string(1) "1"
-    [2]=>
-    string(1) "2"
+  array(0) {
+  }
+  [1]=>
+  array(0) {
+  }
+  [2]=>
+  array(0) {
   }
 }
-string(5) "1,2,3"
-array(1) {
+bool(true)
+int(1)
+array(3) {
   [0]=>
-  array(3) {
-    [0]=>
-    string(3) "1,2"
-    [1]=>
-    string(1) "1"
-    [2]=>
-    string(1) "2"
+  array(0) {
+  }
+  [1]=>
+  array(0) {
+  }
+  [2]=>
+  array(0) {
   }
 }
-int(1)
-array(1) {
+bool(true)
+int(2)
+array(3) {
   [0]=>
-  array(2) {
-    [0]=>
-    string(1) "1"
-    [1]=>
-    string(1) "1"
+  array(0) {
+  }
+  [1]=>
+  array(0) {
+  }
+  [2]=>
+  array(0) {
   }
 }
-string(3) "1,2"
-array(2) {
+bool(true)
+int(3)
+array(3) {
   [0]=>
-  array(2) {
-    [0]=>
-    string(1) "1"
-    [1]=>
-    string(1) "1"
+  array(0) {
   }
   [1]=>
-  array(2) {
-    [0]=>
-    string(1) "2"
-    [1]=>
-    string(1) "2"
+  array(0) {
+  }
+  [2]=>
+  array(0) {
   }
 }
-string(5) "1,2,3"
+bool(true)
+int(4)
 array(3) {
   [0]=>
-  array(2) {
-    [0]=>
-    string(1) "1"
-    [1]=>
-    string(1) "1"
+  array(0) {
   }
   [1]=>
-  array(2) {
-    [0]=>
-    string(1) "2"
-    [1]=>
-    string(1) "2"
+  array(0) {
   }
   [2]=>
-  array(2) {
-    [0]=>
-    string(1) "3"
-    [1]=>
-    string(1) "3"
+  array(0) {
   }
 }
-int(0)
-array(1) {
+bool(true)
+int(5)
+array(3) {
   [0]=>
-  array(2) {
-    [0]=>
-    string(1) "0"
-    [1]=>
-    string(1) "0"
+  array(0) {
+  }
+  [1]=>
+  array(0) {
+  }
+  [2]=>
+  array(0) {
   }
 }
-object(ArrayIterator)#%d (7) {
+bool(true)
+int(6)
+array(3) {
+  [0]=>
+  array(0) {
+  }
   [1]=>
-  int(0)
-  ["1,2"]=>
-  int(1)
-  ["1,2,3"]=>
-  int(2)
+  array(0) {
+  }
+  [2]=>
+  array(0) {
+  }
+}
+bool(true)
+int(7)
+array(3) {
   [0]=>
-  int(3)
-  ["FooBar"]=>
-  int(4)
-  [","]=>
-  int(5)
-  [",,"]=>
-  int(6)
+  array(0) {
+  }
+  [1]=>
+  array(0) {
+  }
+  [2]=>
+  array(0) {
+  }
 }
-===DONE===
---UEXPECTF--
-unicode(3) "1,2"
-array(1) {
+bool(true)
+int(8)
+array(3) {
   [0]=>
-  array(3) {
-    [0]=>
-    string(3) "1,2"
-    [1]=>
-    string(1) "1"
-    [2]=>
-    string(1) "2"
+  array(0) {
+  }
+  [1]=>
+  array(0) {
+  }
+  [2]=>
+  array(0) {
   }
 }
-unicode(5) "1,2,3"
-array(1) {
+bool(true)
+int(0)
+array(2) {
   [0]=>
-  array(3) {
+  array(1) {
     [0]=>
-    string(3) "1,2"
-    [1]=>
-    string(1) "1"
-    [2]=>
-    string(1) "2"
+    string(1) "0"
+  }
+  [1]=>
+  array(1) {
+    [0]=>
+    string(1) "0"
   }
 }
+bool(true)
 int(1)
-array(1) {
+array(2) {
   [0]=>
-  array(2) {
+  array(1) {
     [0]=>
     string(1) "1"
-    [1]=>
+  }
+  [1]=>
+  array(1) {
+    [0]=>
     string(1) "1"
   }
 }
-unicode(3) "1,2"
+bool(true)
+int(2)
 array(2) {
   [0]=>
-  array(2) {
+  array(1) {
     [0]=>
-    string(1) "1"
-    [1]=>
-    string(1) "1"
+    string(1) "2"
   }
   [1]=>
-  array(2) {
+  array(1) {
     [0]=>
     string(1) "2"
-    [1]=>
-    string(1) "2"
   }
 }
-unicode(5) "1,2,3"
-array(3) {
+bool(true)
+int(3)
+array(2) {
   [0]=>
-  array(2) {
+  array(1) {
     [0]=>
-    string(1) "1"
-    [1]=>
-    string(1) "1"
+    string(1) "3"
   }
   [1]=>
-  array(2) {
+  array(1) {
     [0]=>
-    string(1) "2"
-    [1]=>
-    string(1) "2"
+    string(1) "3"
   }
-  [2]=>
-  array(2) {
+}
+bool(true)
+int(4)
+array(2) {
+  [0]=>
+  array(1) {
     [0]=>
-    string(1) "3"
-    [1]=>
-    string(1) "3"
+    string(1) "4"
+  }
+  [1]=>
+  array(1) {
+    [0]=>
+    string(1) "4"
   }
 }
-int(0)
-array(1) {
+bool(true)
+int(5)
+array(2) {
   [0]=>
-  array(2) {
+  array(1) {
     [0]=>
-    string(1) "0"
-    [1]=>
-    string(1) "0"
+    string(1) "5"
+  }
+  [1]=>
+  array(1) {
+    [0]=>
+    string(1) "5"
   }
 }
-object(ArrayIterator)#%d (7) {
+bool(true)
+int(6)
+array(2) {
+  [0]=>
+  array(1) {
+    [0]=>
+    string(1) "6"
+  }
   [1]=>
-  int(0)
-  [u"1,2"]=>
-  int(1)
-  [u"1,2,3"]=>
-  int(2)
+  array(1) {
+    [0]=>
+    string(1) "6"
+  }
+}
+bool(true)
+int(7)
+array(2) {
   [0]=>
-  int(3)
-  [u"FooBar"]=>
-  int(4)
-  [u","]=>
-  int(5)
-  [u",,"]=>
-  int(6)
+  array(1) {
+    [0]=>
+    string(1) "7"
+  }
+  [1]=>
+  array(1) {
+    [0]=>
+    string(1) "7"
+  }
+}
+bool(true)
+int(8)
+array(2) {
+  [0]=>
+  array(1) {
+    [0]=>
+    string(1) "8"
+  }
+  [1]=>
+  array(1) {
+    [0]=>
+    string(1) "8"
+  }
+}
+object(ArrayIterator)#%d (9) {
+  [0]=>
+  %s(1) "1"
+  [1]=>
+  %s(3) "1,2"
+  [2]=>
+  %s(5) "1,2,3"
+  [3]=>
+  %s(0) ""
+  [4]=>
+  NULL
+  [5]=>
+  array(0) {
+  }
+  [6]=>
+  %s(6) "FooBar"
+  [7]=>
+  %s(1) ","
+  [8]=>
+  %s(2) ",,"
 }
 ===DONE===
index b3aaf4f45fc5efd741b40fb75971340f5516e9f3..3f724697a9218136aad21ab8649c65bc643265d0 100755 (executable)
@@ -18,7 +18,7 @@ class MyRegexIterator extends RegexIterator
 }
 
 $ar = new ArrayIterator(array('1','1,2','1,2,3','',NULL,array(),'FooBar',',',',,'));
-$it = new MyRegexIterator($ar, '/,/', 0, RegexIterator::SPLIT);
+$it = new MyRegexIterator($ar, '/,/', RegexIterator::SPLIT);
 
 $it->show();
 
index 9d881a112923768d9f8d589e1e0cd2034936e6bb..35a050c39619c7ed2be297293ddf8ff33cb22f96 100755 (executable)
@@ -18,7 +18,7 @@ class MyRegexIterator extends RegexIterator
 }
 
 $ar = new ArrayIterator(array('1'=>0,'1,2'=>1,'1,2,3'=>2,0=>3,'FooBar'=>4,','=>5,',,'=>6));
-$it = new MyRegexIterator($ar, '/(\d),(\d)/', RegexIterator::USE_KEY, RegexIterator::SPLIT);
+$it = new MyRegexIterator($ar, '/(\d),(\d)/', RegexIterator::SPLIT, RegexIterator::USE_KEY);
 
 $it->show();
 
@@ -59,35 +59,3 @@ object(ArrayIterator)#%d (7) {
   int(6)
 }
 ===DONE===
---UEXPECTF--
-unicode(3) "1,2"
-array(2) {
-  [0]=>
-  string(0) ""
-  [1]=>
-  string(0) ""
-}
-unicode(5) "1,2,3"
-array(2) {
-  [0]=>
-  string(0) ""
-  [1]=>
-  string(2) ",3"
-}
-object(ArrayIterator)#%d (7) {
-  [1]=>
-  int(0)
-  [u"1,2"]=>
-  int(1)
-  [u"1,2,3"]=>
-  int(2)
-  [0]=>
-  int(3)
-  [u"FooBar"]=>
-  int(4)
-  [u","]=>
-  int(5)
-  [u",,"]=>
-  int(6)
-}
-===DONE===