You are here

function _coder_review_search_string in Coder 7

Same name and namespace in other branches
  1. 7.2 coder_review/coder_review.common.inc \_coder_review_search_string()

Search for a string.

Uses the fastest available php function for searching.

Parameters

$line: Haystack.

$rule: Rule to process.

Return value

TRUE if needle is in haystack.

2 calls to _coder_review_search_string()
do_coder_review_grep in coder_review/coder_review.module
Search for a string.
do_coder_review_grep_invert in coder_review/coder_review.module
Search for potentially missing string.

File

coder_review/coder_review.module, line 1917

Code

function _coder_review_search_string($line, $rule) {
  static $php5;
  if (!isset($php5)) {
    if (function_exists('stripos')) {
      $php5 = TRUE;
    }
    else {
      $php5 = FALSE;
    }
  }

  // Case-sensitive search with strpos() (supported everywhere).
  if (isset($rule['#case-sensitive'])) {
    return strpos($line, $rule['#value']) !== FALSE;
  }

  // Case-insensitive search with stripos() (supported in PHP 5).
  if ($php5 && !isset($rule['#case-sensitive'])) {
    return stripos($line, $rule['#value']) !== FALSE;
  }

  // Case-insensitive search.
  $regex = '/' . preg_quote($rule['#value']) . '/i';
  return preg_match($regex, $line);
}