helly Mon Apr 26 18:01:12 2004 EDT Modified files: /php-src/ext/spl/examples appenditerator.inc Log: Complete implementation http://cvs.php.net/diff.php/php-src/ext/spl/examples/appenditerator.inc?r1=1.1&r2=1.2&ty=u Index: php-src/ext/spl/examples/appenditerator.inc diff -u php-src/ext/spl/examples/appenditerator.inc:1.1 php-src/ext/spl/examples/appenditerator.inc:1.2 --- php-src/ext/spl/examples/appenditerator.inc:1.1 Sun Apr 25 09:06:15 2004 +++ php-src/ext/spl/examples/appenditerator.inc Mon Apr 26 18:01:12 2004 @@ -28,6 +28,10 @@ function rewind() { $this->iterators->rewind(); + if ($this->iterators->valid()) + { + $this->iterators->rewind(); + } } function valid() @@ -37,20 +41,36 @@ function current() { - return $this->getInnerIterator()->current(); + /* Using $this->valid() would be exactly the same; it would omit + * the access to a non valid element in the inner iterator. Since + * the user didn't respect the valid() return value false this + * must be intended hence we go on. */ + return $this->iterators->valid() ? $this->getInnerIterator()->current() : NULL; } function key() { - return $this->getInnerIterator()->key(); + return $this->iterators->valid() ? $this->getInnerIterator()->key() : NULL; } function next() { - while($this->iterators->valid()) { - $this->getInnerIterator()->next(); - if ($this->valid()) { - return; + if (!$this->iterators->valid()) + { + return; /* done all */ + } + $this->getInnerIterator()->next(); + if ($this->getInnerIterator()->valid()) + { + return; /* found valid element in current inner iterator */ + } + $this->iterators->next(); + while ($this->iterators->valid()) + { + $this->getInnerIterator()->rewind(); + if ($this->getInnerIterator()->valid()) + { + return; /* found element as first elemet in another iterator */ } $this->iterators->next(); }
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php