Back to index

php5  5.3.10
Public Member Functions | Public Attributes | Protected Member Functions | Private Attributes
RegexIterator Class Reference

Regular expression filter for iterators. More...

Inheritance diagram for RegexIterator:
Inheritance graph
[legend]
Collaboration diagram for RegexIterator:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 __construct (Iterator $it, $regex, $mode=0, $flags=0, $preg_flags=0)
 Constructs a regular expression filter around an iterator whose elemnts or keys are strings.
 accept ()
 Match current or key against regular expression using mode, flags and preg_flags.
 key ()
 current ()
 getMode ()
 setMode ($mode)
 getFlags ()
 setFlags ($flags)
 getPregFlags ()
 setPregFlags ($preg_flags)
 rewind ()
 Rewind the inner iterator.
 next ()
 Move to next element.
 valid ()
 getInnerIterator ()
 __call ($func, $params)
 Aggregate the inner iterator.

Public Attributes

const USE_KEY = 0x00000001
 If present in $flags the key is used rather then the current value.
const MATCH = 0
 Mode: Executed a plain match only.
const GET_MATCH = 1
 Mode: Return the first matche (if any)
const ALL_MATCHES = 2
 Mode: Return all matches (if any)
const SPLIT = 3
 Mode: Return the split values (if any)
const REPLACE = 4
 Mode: Replace the input key or current.

Protected Member Functions

 fetch ()
 Fetch next element and store it.
 __clone ()
 hidden __clone

Private Attributes

 $regex
 the regular expression to match against
 $mode
 operation mode (one of self::MATCH, self::GET_MATCH, self::ALL_MATCHES, self::SPLIT)
 $flags
 special flags (self::USE_KEY)
 $preg_flags
 PREG_* flags, see preg_match(), preg_match_all(), preg_split()
 $key
 the value used for key()
 $current
 the value used for current()

Detailed Description

Regular expression filter for iterators.

Author:
Marcus Boerger
Version:
1.0
Since:
PHP 5.1

This filter iterator assumes that the inner iterator

Definition at line 20 of file regexiterator.inc.


Constructor & Destructor Documentation

RegexIterator::__construct ( Iterator it,
regex,
mode = 0,
flags = 0,
preg_flags = 0 
)

Constructs a regular expression filter around an iterator whose elemnts or keys are strings.

Parameters:
itinner iterator
regexthe regular expression to match
modeoperation mode (one of self::MATCH, self::GET_MATCH, self::ALL_MATCHES, self::SPLIT)
flagsspecial flags (self::USE_KEY)
preg_flagsglobal PREG_* flags, see preg_match(), preg_match_all(), preg_split()

Definition at line 52 of file regexiterator.inc.

                                                                                          {
              parent::__construct($it);
              $this->regex = $regex;
              $this->flags = $flags;
              $this->mode = $mode;
              $this->preg_flags = $preg_flags;
       }

Member Function Documentation

FilterIterator::__call ( func,
params 
) [inherited]

Aggregate the inner iterator.

Parameters:
funcName of method to invoke
paramsArray of parameters to pass to method

Reimplemented in SearchIterator.

Definition at line 121 of file filteriterator.inc.

       {
              return call_user_func_array(array($this->it, $func), $params);
       }
FilterIterator::__clone ( ) [protected, inherited]

hidden __clone

Reimplemented in KeyFilter.

Definition at line 104 of file filteriterator.inc.

                                    {
              // disallow clone 
       }

Match current or key against regular expression using mode, flags and preg_flags.

Returns:
whether this is a match
Warning:
never call this twice for the same state

Reimplemented from FilterIterator.

Reimplemented in InvertedRegexIterator.

Definition at line 68 of file regexiterator.inc.

       {
              $matches       = array();
              $this->key     = parent::key();
              $this->current = parent::current();
              /* note that we use $this->current, rather than calling parent::current() */
              $subject = ($this->flags & self::USE_KEY) ? $this->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;

                     case self::REPLACE:
                            $this->current = array();
                            $result = preg_replace($this->regex, $this->replacement, $subject);
                            if ($this->flags & self::USE_KEY)
                            {
                                   $this->key = $result;
                            }
                            else
                            {
                                   $this->current = $result;
                            }
              }
       }

Here is the call graph for this function:

Returns:
the current value after accept has been called

Reimplemented from FilterIterator.

Definition at line 115 of file regexiterator.inc.

       {
              return $this->current;
       }

Here is the caller graph for this function:

FilterIterator::fetch ( ) [protected, inherited]

Fetch next element and store it.

Returns:
void

Definition at line 61 of file filteriterator.inc.

                                  {
              while ($this->it->valid()) {
                     if ($this->accept()) {
                            return;
                     }
                     $this->it->next();
              };
       }

Here is the call graph for this function:

Here is the caller graph for this function:

Returns:
current operation flags

Definition at line 136 of file regexiterator.inc.

       {
              return $this->flags;
       }
Returns:
The inner iterator

Implements OuterIterator.

Definition at line 111 of file filteriterator.inc.

       {
              return $this->it;
       }

Here is the caller graph for this function:

Returns:
current operation mode

Definition at line 122 of file regexiterator.inc.

       {
              return $this->mode;
       }
Returns:
current PREG flags

Definition at line 150 of file regexiterator.inc.

       {
              return $this->preg_flags;
       }
Returns:
the key after accept has been called

Reimplemented from FilterIterator.

Definition at line 108 of file regexiterator.inc.

       {
              return $this->key;
       }

Here is the caller graph for this function:

FilterIterator::next ( ) [inherited]

Move to next element.

Returns:
void

Implements Iterator.

Reimplemented in SearchIterator.

Definition at line 75 of file filteriterator.inc.

                       {
              $this->it->next();
              $this->fetch();
       }

Here is the call graph for this function:

FilterIterator::rewind ( ) [inherited]

Rewind the inner iterator.

Implements Iterator.

Reimplemented in SearchIterator.

Definition at line 42 of file filteriterator.inc.

                         {  
              $this->it->rewind();
              $this->fetch();
       }

Here is the call graph for this function:

Parameters:
flagsnew operaion flags

Definition at line 143 of file regexiterator.inc.

       {
              $this->flags = $flags;
       }
Parameters:
modenew operaion mode

Definition at line 129 of file regexiterator.inc.

       {
              $this->mode = $mode;
       }
RegexIterator::setPregFlags ( preg_flags)
Parameters:
preg_flagsnew PREG flags

Definition at line 157 of file regexiterator.inc.

       {
              $this->preg_flags = $preg_flags;
       }
FilterIterator::valid ( ) [inherited]
Returns:
Whether more elements are available

Implements Iterator.

Reimplemented in SearchIterator.

Definition at line 83 of file filteriterator.inc.

                        {
              return $this->it->valid();
       }

Member Data Documentation

the value used for current()

Definition at line 38 of file regexiterator.inc.

special flags (self::USE_KEY)

Definition at line 34 of file regexiterator.inc.

the value used for key()

Definition at line 37 of file regexiterator.inc.

operation mode (one of self::MATCH, self::GET_MATCH, self::ALL_MATCHES, self::SPLIT)

Definition at line 32 of file regexiterator.inc.

PREG_* flags, see preg_match(), preg_match_all(), preg_split()

Definition at line 35 of file regexiterator.inc.

the regular expression to match against

Definition at line 31 of file regexiterator.inc.

Mode: Return all matches (if any)

Definition at line 27 of file regexiterator.inc.

Mode: Return the first matche (if any)

Definition at line 26 of file regexiterator.inc.

Mode: Executed a plain match only.

Definition at line 25 of file regexiterator.inc.

Mode: Replace the input key or current.

Definition at line 29 of file regexiterator.inc.

Mode: Return the split values (if any)

Definition at line 28 of file regexiterator.inc.

const RegexIterator::USE_KEY = 0x00000001

If present in $flags the key is used rather then the current value.

Definition at line 22 of file regexiterator.inc.


The documentation for this class was generated from the following file: