Пример #1
0
 /**
  * @brief Performs a search for the given pattern past the given index.
  * @param $search the pattern to search for
  * @param $index the minimum string index (offset) of a result
  * @param $matches a reference to the return location of the match groups
  * @return the index or false if no match is found.
  */
 public function match($search, $index, &$matches)
 {
     $r = false;
     // return value
     if (isset($this->cache[$search])) {
         $a = $this->cache[$search];
         if ($a === false) {
             return false;
         }
         // no more results
         $r = $a[0];
         $matches = $a[1];
         assert($matches !== null);
         if ($r >= $index) {
             // cache is good!
             return $r;
         }
     }
     // cache not set, or out of date, we have to perform the match
     if (!($ret = preg_match($search, $this->string, $matches_, PREG_OFFSET_CAPTURE, $index))) {
         if ($ret === false && LUMINOUS_DEBUG) {
             throw new Exception('preg_match returned false for pattern: "' . $search . '", with code: ' . LuminousUtils::pcre_error_decode(preg_last_error()));
         }
         $this->cache[$search] = false;
         return false;
     }
     $r = $matches_[0][1];
     // strip the offsets from the match_groups
     foreach ($matches_ as $i => &$v) {
         $v = $v[0];
     }
     $this->cache[$search] = array($r, $matches_);
     $matches = $matches_;
     return $r;
 }