コード例 #1
0
ファイル: emailcheck.php プロジェクト: vstorm83/propertease
 function Match($line, $lines, $offset)
 {
     $line = trim($line);
     if ($line == "") {
         return false;
     }
     $match = false;
     // check for any starts with
     if (count($this->starts) > 0) {
         foreach ($this->starts as $starts) {
             if (FSS_Helper::stringStartsWith($line, $starts)) {
                 $match = true;
             }
         }
     }
     // check for any regular expressions
     if (count($this->regex) > 0) {
         foreach ($this->regex as $regex) {
             if (preg_match("/" . $regex . "/i", $line)) {
                 $match = true;
             }
         }
     }
     // no match found, so done
     if (!$match) {
         return false;
     }
     // have a match, if there are any nearby clauses, check them all
     if (count($this->nearby) > 0) {
         foreach ($this->nearby as $nearby) {
             // setup default lines before and after
             if (empty($nearby->lines)) {
                 $nearby->lines = 3;
             }
             if (empty($nearby->before)) {
                 $nearby->before = $nearby->lines;
             }
             if (empty($nearby->after)) {
                 $nearby->after = $nearby->lines;
             }
             // if there is a regex in the nearby, check it
             if (isset($nearby->regex)) {
                 // create new match class
                 $test = new TrimMatch();
                 $test->regex[] = $nearby->regex;
                 // work out which lines
                 $start = max(0, $offset - $nearby->before);
                 $end = min(count($lines) - 1, $offset + $nearby->after);
                 $found = false;
                 // check each line
                 for ($i = $start; $i <= $end; $i++) {
                     $subline = trim($lines[$i]);
                     if ($test->Match($subline, $lines, $i)) {
                         $found = true;
                         break;
                     }
                 }
                 // if its not found, we failed for this line
                 if (!$found) {
                     return false;
                 }
             }
         }
     }
     return true;
 }