Пример #1
0
 public function match($string, Node $curmatch)
 {
     $matches = new SimpleNode();
     $matchcount = 0;
     $matchpos = 0;
     do {
         $match = $this->_match(substr($string, $matchpos), $curmatch);
         if ($this->repeat == self::ONE || $this->repeat == self::ZERO_OR_ONE) {
             if ($match !== FALSE) {
                 return $match;
             }
             if ($this->repeat == self::ZERO_OR_ONE) {
                 return $matches;
             }
             return FALSE;
         }
         if ($match !== FALSE) {
             $matchcount++;
             $matchpos += $match->getLen();
             $matches->addLen($match->getLen());
             $matches->addText($match->getText());
         }
     } while ($match);
     if ($matchcount == 0 && $this->repeat == self::ONE_OR_MORE) {
         return FALSE;
     }
     return $matches;
 }
Пример #2
0
 protected function _match($string, Node $curmatch)
 {
     $matches = new SimpleNode();
     $curmatch->startTransaction();
     $matchpos = 0;
     foreach ($this->expressions as $expr) {
         $match = $expr->match(substr($string, $matchpos), $curmatch);
         if ($match === FALSE) {
             $curmatch->revertTransaction();
             return FALSE;
         }
         $matchpos += $match->getLen();
         $matches->addLen($match->getLen());
         if (!$expr->ignore) {
             $matches->addText($match->getText());
         }
     }
     $curmatch->commitTransaction();
     return $matches;
 }