diff options
author | Lorry Tar Creator <lorry-tar-importer@baserock.org> | 2013-03-14 05:42:27 +0000 |
---|---|---|
committer | <> | 2013-04-03 16:25:08 +0000 |
commit | c4dd7a1a684490673e25aaf4fabec5df138854c4 (patch) | |
tree | 4d57c44caae4480efff02b90b9be86f44bf25409 /ext/spl/examples/keyfilter.inc | |
download | php2-master.tar.gz |
Imported from /home/lorry/working-area/delta_php2/php-5.4.13.tar.bz2.HEADphp-5.4.13master
Diffstat (limited to 'ext/spl/examples/keyfilter.inc')
-rw-r--r-- | ext/spl/examples/keyfilter.inc | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/ext/spl/examples/keyfilter.inc b/ext/spl/examples/keyfilter.inc new file mode 100644 index 0000000..eaf6b77 --- /dev/null +++ b/ext/spl/examples/keyfilter.inc @@ -0,0 +1,64 @@ +<?php + +/** @file keyfilter.inc + * @ingroup Examples + * @brief class KeyFilter + * @author Marcus Boerger + * @date 2003 - 2005 + * + * SPL - Standard PHP Library + */ + +/** @ingroup Examples + * @brief Regular expression filter for string iterators + * @author Marcus Boerger + * @version 1.1 + * + * Instances of this class act as a filter around iterators whose elements + * are strings. In other words you can put an iterator into the constructor + * and the instance will only return elements which match the given regular + * expression. + */ +class KeyFilter extends FilterIterator +{ + /** @internal regular exoression used as filter */ + private $regex; + + /** + * Constructs a filter around an iterator whose elemnts are strings. + * If the given iterator is of type spl_sequence then its rewind() + * method is called. + * + * @param it Object that implements at least spl_forward + * @param regex Regular expression used as a filter. + */ + function __construct(Iterator $it, $regex) + { + parent::__construct($it); + $this->regex = $regex; + } + + /** \return whether the current key mathes the regular expression + */ + function accept() + { + return ereg($this->regex, $this->getInnerIterator()->key()); + } + + /** @return regular expression used as filter + */ + function getRegex() + { + return $this->regex; + } + + /** + * hidden __clone + */ + protected function __clone() + { + // disallow clone + } +} + +?>
\ No newline at end of file |