File: keyfilter.inc

package info (click to toggle)
php5 5.2.6.dfsg.1-1%2Blenny16
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 81,956 kB
  • ctags: 45,717
  • sloc: ansic: 545,818; sh: 18,463; php: 12,555; xml: 4,362; yacc: 2,430; lex: 2,294; makefile: 1,193; tcl: 1,128; awk: 693; cpp: 682; perl: 71; pascal: 24; sql: 22
file content (64 lines) | stat: -rwxr-xr-x 1,467 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
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 
	}
}

?>