cvs: spl /examples limititerator.inc seekableiterator.inc

From: Date: Tue, 11 Nov 2003 18:31:51 +0000
Subject: cvs: spl /examples limititerator.inc seekableiterator.inc
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-24486@lists.php.net to get a copy of this message
helly Tue Nov 11 13:31:51 2003 EDT Added files: /spl/examples seekableiterator.inc Modified files: /spl/examples limititerator.inc Log: Add shortcut interface SeekableIterator to LimitIterator Index: spl/examples/limititerator.inc diff -u spl/examples/limititerator.inc:1.1 spl/examples/limititerator.inc:1.2 --- spl/examples/limititerator.inc:1.1 Sun Nov 9 09:05:36 2003 +++ spl/examples/limititerator.inc Tue Nov 11 13:31:50 2003 @@ -21,8 +21,12 @@ { $this->it->rewind(); $this->index = 0; - while($this->index < $this->offset && $this->it->hasMore()) { - $this->next(); + if (is_a($this->it, 'SeekableIterator')) { + $this->index = $this->it->seek($this->offset); + } else { + while($this->index < $this->offset && $this->it->hasMore()) { + $this->next(); + } } } Index: spl/examples/seekableiterator.inc +++ spl/examples/seekableiterator.inc <?php class SeekableIterator implements Iterator { function seek($index) { $this->rewind(); $position = 0; while($position < $index && $this->it->hasMore()) { $this->next(); $position++; } return $position; } } ?>

« previous php.cvs (#24486) next »