regex = $regex; $this->flags = $flags; $this->mode = $mode; $this->preg_flags = $preg_flags; } /** * Match current or key against regular expression using mode, flags and * preg_flags. * * @return whether this is a match * * @warning never call this twice for the same state */ function accept() { $matches = array(); $this->current = parent::current(); /* note that we use $this->current, rather than calling parent::current() */ $subject = ($this->flags & self::USE_KEY) ? parent::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; } } /** @return the current value after accept has been called */ function current() { return $this->current; } } ?>