helly           Sun Jul 16 20:52:21 2006 UTC

  Added files:                 
    /php-src/ext/spl/tests      iterator_050.phpt iterator_051.phpt 
                                iterator_052.phpt iterator_053.phpt 
                                iterator_054.phpt iterator_055.phpt 

  Modified files:              
    /php-src/ext/spl    spl_iterators.c spl_iterators.h 
    /php-src/ext/spl/internal   regexiterator.inc 
  Log:
  - Upgrade RegexIterator capabilities, see docu
  
http://cvs.php.net/viewvc.cgi/php-src/ext/spl/spl_iterators.c?r1=1.137&r2=1.138&diff_format=u
Index: php-src/ext/spl/spl_iterators.c
diff -u php-src/ext/spl/spl_iterators.c:1.137 
php-src/ext/spl/spl_iterators.c:1.138
--- php-src/ext/spl/spl_iterators.c:1.137       Tue Jun  6 20:12:46 2006
+++ php-src/ext/spl/spl_iterators.c     Sun Jul 16 20:52:20 2006
@@ -16,7 +16,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: spl_iterators.c,v 1.137 2006/06/06 20:12:46 tony2001 Exp $ */
+/* $Id: spl_iterators.c,v 1.138 2006/07/16 20:52:20 helly Exp $ */
 
 #ifdef HAVE_CONFIG_H
 # include "config.h"
@@ -1005,12 +1005,20 @@
                        char *regex;
                        int len, poptions, coptions;
                        pcre_extra *extra = NULL;
+                       long mode = REGIT_MODE_MATCH;
 
                        intern->u.regex.flags = 0;
-                       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, 
"Os|l", &zobject, ce_inner, &regex, &len, &intern->u.regex.flags) == FAILURE) {
+                       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) {
                                php_set_error_handling(EH_NORMAL, NULL 
TSRMLS_CC);
                                return NULL;
                        }
+                       if (mode < 0 || mode >= REGIT_MODE_MAX) {
+                               
zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0 TSRMLS_CC, "Illegal 
mode %ld", mode);
+                               php_set_error_handling(EH_NORMAL, NULL 
TSRMLS_CC);
+                               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.pce->refcount++;
@@ -1368,7 +1376,7 @@
 } /* }}} */
 
 #if HAVE_PCRE || HAVE_BUNDLED_PCRE
-/* {{{ proto void RegexIterator::__construct(Iterator it, string $regex [, int 
$flags]) 
+/* {{{ proto void RegexIterator::__construct(Iterator it, string regex [, int 
flags [, int mode [, int preg_flags]]]) 
    Create an RegexIterator from another iterator and a regular expression */
 SPL_METHOD(RegexIterator, __construct)
 {
@@ -1379,23 +1387,36 @@
    Match (string)current() against regular expression */
 SPL_METHOD(RegexIterator, accept)
 {
-       spl_dual_it_object   *intern;
-       int count;
-       char *subject, tmp[32];
-       int subject_len, use_copy = 0;
-       zval subject_copy;
-       pcre_extra *extra;
+       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;
 
-       intern = (spl_dual_it_object*)zend_object_store_get_object(getThis() 
TSRMLS_CC);
-       
        if (intern->u.regex.flags & REGIT_USE_KEY) {
                if (intern->current.key_type == HASH_KEY_IS_LONG) {
                        subject_len = snprintf(tmp, sizeof(tmp), "%ld", 
intern->current.int_key);
                        subject = &tmp[0];
+                       use_copy = 0;
+               } else if (intern->current.key_type == HASH_KEY_IS_UNICODE) {
+                       subject_len = intern->current.str_key_len - 1;
+                       subject = 
zend_unicode_to_ascii(intern->current.str_key.u, subject_len TSRMLS_DC);
+                       if (!subject) {
+                               /* FIXME: Unicode support??? : how to handle 
this error, with that exception? */
+                               if (intern->u.regex.mode != REGIT_MODE_MATCH) {
+                                       zval_ptr_dtor(&intern->current.data);
+                                       MAKE_STD_ZVAL(intern->current.data);
+                                       array_init(intern->current.data);
+                               }
+                               
zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0 TSRMLS_CC, "Unicode 
key could not be converted to ascii");
+                               RETURN_FALSE;
+                       }
+                       use_copy = 1;
                } else {
-                       subject_len = intern->current.str_key_len;
-                       /* FIXME: Unicode support??? */
-                       subject = intern->current.str_key.s;
+                       subject_len = intern->current.str_key_len - 1;
+                       subject = estrndup(intern->current.str_key.s, 
subject_len);
+                       use_copy = 1;
                }
        } else {
                zend_make_printable_zval(intern->current.data, &subject_copy, 
&use_copy);
@@ -1408,17 +1429,49 @@
                }
        }
 
-       extra = intern->u.regex.pce->extra;
-       count = pcre_exec(intern->u.regex.pce->re, extra, subject, subject_len, 
0, 0, NULL, 0);
+       switch (intern->u.regex.mode)
+       {
+       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);
+               RETVAL_BOOL(count >= 0);
+               break;
+
+       case REGIT_MODE_ALL_MATCHES:
+       case REGIT_MODE_GET_MATCH:
+               if (!use_copy) {
+                       subject = estrndup(subject, subject_len);
+                       use_copy = 1;
+               }
+               zval_ptr_dtor(&intern->current.data);
+               MAKE_STD_ZVAL(intern->current.data);
+               array_init(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);
+               count = 
zend_hash_num_elements(Z_ARRVAL_P(intern->current.data));
+               RETVAL_BOOL(count > 0);
+               break;
+
+       case REGIT_MODE_SPLIT:
+               if (!use_copy) {
+                       subject = estrndup(subject, subject_len);
+                       use_copy = 1;
+               }
+               zval_ptr_dtor(&intern->current.data);
+               MAKE_STD_ZVAL(intern->current.data);
+               array_init(intern->current.data);
+               php_pcre_split(regex, extra, subject, subject_len, 
intern->current.data, 0, -1, 0, 0, 0 TSRMLS_CC);
+               count = 
zend_hash_num_elements(Z_ARRVAL_P(intern->current.data));
+               RETVAL_BOOL(count > 1);
+               break;
+       }
 
        if (use_copy) {
-               zval_dtor(&subject_copy);
+               efree(subject);
        }
-
-       RETURN_BOOL(count >= 0);
 } /* }}} */
 
-/* {{{ proto void RecursiveRegexIterator::__construct(RecursiveIterator it, 
string $regex [, int $flags]) 
+/* {{{ proto void RecursiveRegexIterator::__construct(RecursiveIterator it, 
string regex [, int flags [, int mode [, int preg_flags]]]) 
    Create an RecursiveRegexIterator from another recursive iterator and a 
regular expression */
 SPL_METHOD(RecursiveRegexIterator, __construct)
 {
@@ -1559,6 +1612,8 @@
        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, preg_flags)
 ZEND_END_ARG_INFO();
 
 static zend_function_entry spl_funcs_RegexIterator[] = {
@@ -2772,7 +2827,11 @@
        REGISTER_SPL_SUB_CLASS_EX(InfiniteIterator, IteratorIterator, 
spl_dual_it_new, spl_funcs_InfiniteIterator);
 #if HAVE_PCRE || HAVE_BUNDLED_PCRE
        REGISTER_SPL_SUB_CLASS_EX(RegexIterator, FilterIterator, 
spl_dual_it_new, spl_funcs_RegexIterator);
-       REGISTER_SPL_CLASS_CONST_LONG(RegexIterator, "USE_KEY", REGIT_USE_KEY);
+       REGISTER_SPL_CLASS_CONST_LONG(RegexIterator, "USE_KEY",     
REGIT_USE_KEY);
+       REGISTER_SPL_CLASS_CONST_LONG(RegexIterator, "MATCH",       
REGIT_MODE_MATCH);
+       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_SUB_CLASS_EX(RecursiveRegexIterator, RegexIterator, 
spl_dual_it_new, spl_funcs_RecursiveRegexIterator);
        REGISTER_SPL_IMPLEMENTS(RecursiveRegexIterator, RecursiveIterator);
 #else
http://cvs.php.net/viewvc.cgi/php-src/ext/spl/spl_iterators.h?r1=1.36&r2=1.37&diff_format=u
Index: php-src/ext/spl/spl_iterators.h
diff -u php-src/ext/spl/spl_iterators.h:1.36 
php-src/ext/spl/spl_iterators.h:1.37
--- php-src/ext/spl/spl_iterators.h:1.36        Fri May 26 00:37:33 2006
+++ php-src/ext/spl/spl_iterators.h     Sun Jul 16 20:52:20 2006
@@ -16,7 +16,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: spl_iterators.h,v 1.36 2006/05/26 00:37:33 helly Exp $ */
+/* $Id: spl_iterators.h,v 1.37 2006/07/16 20:52:20 helly Exp $ */
 
 #ifndef SPL_ITERATORS_H
 #define SPL_ITERATORS_H
@@ -95,6 +95,14 @@
        REGIT_USE_KEY            = 0x00000001,
 };
 
+typedef enum {
+       REGIT_MODE_MATCH,
+       REGIT_MODE_GET_MATCH,
+       REGIT_MODE_ALL_MATCHES,
+       REGIT_MODE_SPLIT,
+       REGIT_MODE_MAX,
+} regex_mode;
+
 typedef struct _spl_dual_it_object {
        zend_object              std;
        struct {
@@ -130,6 +138,8 @@
 #if HAVE_PCRE || HAVE_BUNDLED_PCRE
                struct {
                        int              flags;
+                       regex_mode       mode;
+                       long             preg_flags;
                        pcre_cache_entry *pce;
                        char             *regex;
                } regex;
http://cvs.php.net/viewvc.cgi/php-src/ext/spl/internal/regexiterator.inc?r1=1.1&r2=1.2&diff_format=u
Index: php-src/ext/spl/internal/regexiterator.inc
diff -u php-src/ext/spl/internal/regexiterator.inc:1.1 
php-src/ext/spl/internal/regexiterator.inc:1.2
--- php-src/ext/spl/internal/regexiterator.inc:1.1      Sun Jul 16 19:16:03 2006
+++ php-src/ext/spl/internal/regexiterator.inc  Sun Jul 16 20:52:20 2006
@@ -12,7 +12,7 @@
 /**
  * @brief   Regular expression filter for iterators
  * @author  Marcus Boerger
- * @version 1.0
+ * @version 1.1
  * @since PHP 5.1
  *
  * This filter iterator assumes that the inner iterator 
@@ -20,9 +20,17 @@
 class RegexIterator implements FilterIterator
 {
        const USE_KEY     = 0x00000001;
+
+       const MATCH       = 0;
+       const GET_MATCH   = 1;
+       const ALL_MATCHES = 2;
+       const SPLIT       = 3;
        
        private $regex;     /**< the regular expression to match against */
        private $flags;     /**< special flags (USE_KEY) */
+       private $mode;      /**< operation mode (MATCH, GET_MATCH, ALL_MATCHES, 
SPLIT) */
+       private $preg_flags;/**< PREG_* flags, see preg_match(), 
preg_match_all(), preg_split() */ 
+       private $current;   /**< the value used for current() */
 
        /**
         * Constructs a regular expression filter around an iterator whose 
@@ -30,21 +38,52 @@
         *
         * @param it     Object that implements at least
         */
-       function __construct(Iterator $it, $regex, $flags = 0) {
+       function __construct(Iterator $it, $regex, $flags = 0, $mode = 0, 
$preg_flags = 0) {
                parent::__construct($it);
                $this->regex = $regex;
                $this->flags = $flags;
+               $this->mode = $mode;
+               $this->preg_flags = $preg_flags;
        }
 
        /**
-        * Match current or key against regular expression.
+        * Match current or key against regular expression using mode, flags and
+        * preg_flags.
         *
         * @return whether this is a match
+        *
+        * @warning never call this twice for the same state
         */
        function accept()
        {
-               $subject = ($this->flags & self::USE_KEY) ? parent::key() : 
parent::current();
-               return preg_match($this->regex, $subject);
+               $matches       = array();
+               $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;
+               switch($this->mode)
+               {
+                       case self::MATCH:
+                               return preg_match($this->regex, $subject, 
$matches, $this->preg_flags);
+
+                       case self::GET_MATCH:
+                               $this->current = array();
+                               return preg_match($this->regex, $subject, 
$this->current, $this->preg_flags) > 0;
+
+                       case self::ALL_MATCHES:
+                               $this->current = array();
+                               return preg_match_all($this->regex, $subject, 
$this->current, $this->preg_flags) > 0;
+
+                       case self::SPLIT:
+                               $this->current = array();
+                               preg_split($this->regex, $subject, 
$this->current, $this->preg_flags) > 1;
+               }
+       }
+
+       /** @return the current value after accept has been called
+        */
+       function current()
+       {
+               return $this->current;
        }
 }
 

http://cvs.php.net/viewvc.cgi/php-src/ext/spl/tests/iterator_050.phpt?view=markup&rev=1.1
Index: php-src/ext/spl/tests/iterator_050.phpt
+++ php-src/ext/spl/tests/iterator_050.phpt
--TEST--
SPL: RegexIterator::GET_MATCH
--SKIPIF--
<?php if (!extension_loaded("spl")) print "skip"; ?>
--FILE--
<?php

class MyRegexIterator extends RegexIterator
{
        function show()
        {
                foreach($this as $k => $v)
                {
                        var_dump($k);
                        var_dump($v);
                }
        }
}

$ar = new 
ArrayIterator(array('1','1,2','1,2,3','',NULL,array(),'FooBar',',',',,'));
$it = new MyRegexIterator($ar, '/(\d),(\d)/', 0, RegexIterator::GET_MATCH);
$it->show();

$it = new MyRegexIterator($ar, '/(\d)/', 0, RegexIterator::GET_MATCH);
$it->show();

var_dump($ar);

?>
===DONE===
<?php exit(0); ?>
--EXPECTF--
int(1)
array(3) {
  [0]=>
  string(3) "1,2"
  [1]=>
  string(1) "1"
  [2]=>
  string(1) "2"
}
int(2)
array(3) {
  [0]=>
  string(3) "1,2"
  [1]=>
  string(1) "1"
  [2]=>
  string(1) "2"
}
int(0)
array(2) {
  [0]=>
  string(1) "1"
  [1]=>
  string(1) "1"
}
int(1)
array(2) {
  [0]=>
  string(1) "1"
  [1]=>
  string(1) "1"
}
int(2)
array(2) {
  [0]=>
  string(1) "1"
  [1]=>
  string(1) "1"
}
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===

http://cvs.php.net/viewvc.cgi/php-src/ext/spl/tests/iterator_051.phpt?view=markup&rev=1.1
Index: php-src/ext/spl/tests/iterator_051.phpt
+++ php-src/ext/spl/tests/iterator_051.phpt
--TEST--
SPL: RegexIterator::GET_MATCH, USE_KEY
--SKIPIF--
<?php if (!extension_loaded("spl")) print "skip"; ?>
--FILE--
<?php

class MyRegexIterator extends RegexIterator
{
        function show()
        {
                foreach($this as $k => $v)
                {
                        var_dump($k);
                        var_dump($v);
                }
        }
}

$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->show();

$it = new MyRegexIterator($ar, '/(\d)/', RegexIterator::USE_KEY, 
RegexIterator::GET_MATCH);
$it->show();

var_dump($ar);

?>
===DONE===
<?php exit(0); ?>
--EXPECTF--
string(3) "1,2"
array(3) {
  [0]=>
  string(3) "1,2"
  [1]=>
  string(1) "1"
  [2]=>
  string(1) "2"
}
string(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"
}
string(3) "1,2"
array(2) {
  [0]=>
  string(1) "1"
  [1]=>
  string(1) "1"
}
string(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)
  ["1,2"]=>
  int(1)
  ["1,2,3"]=>
  int(2)
  [0]=>
  int(3)
  ["FooBar"]=>
  int(4)
  [","]=>
  int(5)
  [",,"]=>
  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===

http://cvs.php.net/viewvc.cgi/php-src/ext/spl/tests/iterator_052.phpt?view=markup&rev=1.1
Index: php-src/ext/spl/tests/iterator_052.phpt
+++ php-src/ext/spl/tests/iterator_052.phpt
--TEST--
SPL: RegexIterator::ALL_MATCHES
--SKIPIF--
<?php if (!extension_loaded("spl")) print "skip"; ?>
--FILE--
<?php

class MyRegexIterator extends RegexIterator
{
        function show()
        {
                foreach($this as $k => $v)
                {
                        var_dump($k);
                        var_dump($v);
                }
        }
}

$ar = new 
ArrayIterator(array('1','1,2','1,2,3','',NULL,array(),'FooBar',',',',,'));
$it = new MyRegexIterator($ar, '/(\d),(\d)/', 0, RegexIterator::ALL_MATCHES);
$it->show();

$it = new MyRegexIterator($ar, '/(\d)/', 0, RegexIterator::ALL_MATCHES);
$it->show();

var_dump($ar);

?>
===DONE===
<?php exit(0); ?>
--EXPECTF--
int(1)
array(1) {
  [0]=>
  array(3) {
    [0]=>
    string(3) "1,2"
    [1]=>
    string(1) "1"
    [2]=>
    string(1) "2"
  }
}
int(2)
array(1) {
  [0]=>
  array(3) {
    [0]=>
    string(3) "1,2"
    [1]=>
    string(1) "1"
    [2]=>
    string(1) "2"
  }
}
int(0)
array(1) {
  [0]=>
  array(2) {
    [0]=>
    string(1) "1"
    [1]=>
    string(1) "1"
  }
}
int(1)
array(2) {
  [0]=>
  array(2) {
    [0]=>
    string(1) "1"
    [1]=>
    string(1) "1"
  }
  [1]=>
  array(2) {
    [0]=>
    string(1) "2"
    [1]=>
    string(1) "2"
  }
}
int(2)
array(3) {
  [0]=>
  array(2) {
    [0]=>
    string(1) "1"
    [1]=>
    string(1) "1"
  }
  [1]=>
  array(2) {
    [0]=>
    string(1) "2"
    [1]=>
    string(1) "2"
  }
  [2]=>
  array(2) {
    [0]=>
    string(1) "3"
    [1]=>
    string(1) "3"
  }
}
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===

http://cvs.php.net/viewvc.cgi/php-src/ext/spl/tests/iterator_053.phpt?view=markup&rev=1.1
Index: php-src/ext/spl/tests/iterator_053.phpt
+++ php-src/ext/spl/tests/iterator_053.phpt
--TEST--
SPL: RegexIterator::ALL_MATCHES, USE_KEY
--SKIPIF--
<?php if (!extension_loaded("spl")) print "skip"; ?>
--FILE--
<?php

class MyRegexIterator extends RegexIterator
{
        function show()
        {
                foreach($this as $k => $v)
                {
                        var_dump($k);
                        var_dump($v);
                }
        }
}

$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);
$it->show();

$it = new MyRegexIterator($ar, '/(\d)/', RegexIterator::USE_KEY, 
RegexIterator::ALL_MATCHES);
$it->show();

var_dump($ar);

?>
===DONE===
<?php exit(0); ?>
--EXPECTF--
string(3) "1,2"
array(1) {
  [0]=>
  array(3) {
    [0]=>
    string(3) "1,2"
    [1]=>
    string(1) "1"
    [2]=>
    string(1) "2"
  }
}
string(5) "1,2,3"
array(1) {
  [0]=>
  array(3) {
    [0]=>
    string(3) "1,2"
    [1]=>
    string(1) "1"
    [2]=>
    string(1) "2"
  }
}
int(1)
array(1) {
  [0]=>
  array(2) {
    [0]=>
    string(1) "1"
    [1]=>
    string(1) "1"
  }
}
string(3) "1,2"
array(2) {
  [0]=>
  array(2) {
    [0]=>
    string(1) "1"
    [1]=>
    string(1) "1"
  }
  [1]=>
  array(2) {
    [0]=>
    string(1) "2"
    [1]=>
    string(1) "2"
  }
}
string(5) "1,2,3"
array(3) {
  [0]=>
  array(2) {
    [0]=>
    string(1) "1"
    [1]=>
    string(1) "1"
  }
  [1]=>
  array(2) {
    [0]=>
    string(1) "2"
    [1]=>
    string(1) "2"
  }
  [2]=>
  array(2) {
    [0]=>
    string(1) "3"
    [1]=>
    string(1) "3"
  }
}
int(0)
array(1) {
  [0]=>
  array(2) {
    [0]=>
    string(1) "0"
    [1]=>
    string(1) "0"
  }
}
object(ArrayIterator)#%d (7) {
  [1]=>
  int(0)
  ["1,2"]=>
  int(1)
  ["1,2,3"]=>
  int(2)
  [0]=>
  int(3)
  ["FooBar"]=>
  int(4)
  [","]=>
  int(5)
  [",,"]=>
  int(6)
}
===DONE===
--UEXPECTF--
unicode(3) "1,2"
array(1) {
  [0]=>
  array(3) {
    [0]=>
    string(3) "1,2"
    [1]=>
    string(1) "1"
    [2]=>
    string(1) "2"
  }
}
unicode(5) "1,2,3"
array(1) {
  [0]=>
  array(3) {
    [0]=>
    string(3) "1,2"
    [1]=>
    string(1) "1"
    [2]=>
    string(1) "2"
  }
}
int(1)
array(1) {
  [0]=>
  array(2) {
    [0]=>
    string(1) "1"
    [1]=>
    string(1) "1"
  }
}
unicode(3) "1,2"
array(2) {
  [0]=>
  array(2) {
    [0]=>
    string(1) "1"
    [1]=>
    string(1) "1"
  }
  [1]=>
  array(2) {
    [0]=>
    string(1) "2"
    [1]=>
    string(1) "2"
  }
}
unicode(5) "1,2,3"
array(3) {
  [0]=>
  array(2) {
    [0]=>
    string(1) "1"
    [1]=>
    string(1) "1"
  }
  [1]=>
  array(2) {
    [0]=>
    string(1) "2"
    [1]=>
    string(1) "2"
  }
  [2]=>
  array(2) {
    [0]=>
    string(1) "3"
    [1]=>
    string(1) "3"
  }
}
int(0)
array(1) {
  [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===

http://cvs.php.net/viewvc.cgi/php-src/ext/spl/tests/iterator_054.phpt?view=markup&rev=1.1
Index: php-src/ext/spl/tests/iterator_054.phpt
+++ php-src/ext/spl/tests/iterator_054.phpt
--TEST--
SPL: RegexIterator::SPLIT
--SKIPIF--
<?php if (!extension_loaded("spl")) print "skip"; ?>
--FILE--
<?php

class MyRegexIterator extends RegexIterator
{
        function show()
        {
                foreach($this as $k => $v)
                {
                        var_dump($k);
                        var_dump($v);
                }
        }
}

$ar = new 
ArrayIterator(array('1','1,2','1,2,3','',NULL,array(),'FooBar',',',',,'));
$it = new MyRegexIterator($ar, '/,/', 0, RegexIterator::SPLIT);

$it->show();

var_dump($ar);

?>
===DONE===
<?php exit(0); ?>
--EXPECTF--
int(1)
array(2) {
  [0]=>
  string(1) "1"
  [1]=>
  string(1) "2"
}
int(2)
array(3) {
  [0]=>
  string(1) "1"
  [1]=>
  string(1) "2"
  [2]=>
  string(1) "3"
}
int(7)
array(2) {
  [0]=>
  string(0) ""
  [1]=>
  string(0) ""
}
int(8)
array(3) {
  [0]=>
  string(0) ""
  [1]=>
  string(0) ""
  [2]=>
  string(0) ""
}
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===

http://cvs.php.net/viewvc.cgi/php-src/ext/spl/tests/iterator_055.phpt?view=markup&rev=1.1
Index: php-src/ext/spl/tests/iterator_055.phpt
+++ php-src/ext/spl/tests/iterator_055.phpt
--TEST--
SPL: RegexIterator::SPLIT, USE_KEY
--SKIPIF--
<?php if (!extension_loaded("spl")) print "skip"; ?>
--FILE--
<?php

class MyRegexIterator extends RegexIterator
{
        function show()
        {
                foreach($this as $k => $v)
                {
                        var_dump($k);
                        var_dump($v);
                }
        }
}

$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->show();

var_dump($ar);

?>
===DONE===
<?php exit(0); ?>
--EXPECTF--
string(3) "1,2"
array(2) {
  [0]=>
  string(0) ""
  [1]=>
  string(0) ""
}
string(5) "1,2,3"
array(2) {
  [0]=>
  string(0) ""
  [1]=>
  string(2) ",3"
}
object(ArrayIterator)#%d (7) {
  [1]=>
  int(0)
  ["1,2"]=>
  int(1)
  ["1,2,3"]=>
  int(2)
  [0]=>
  int(3)
  ["FooBar"]=>
  int(4)
  [","]=>
  int(5)
  [",,"]=>
  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===

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

Reply via email to