You are here

function _coder_search_string in Coder 5

Same name and namespace in other branches
  1. 5.2 coder.module \_coder_search_string()
  2. 6.2 coder.module \_coder_search_string()
  3. 6 coder.module \_coder_search_string()

Search for a string.

Uses strpos() and stripos() if available for performance optimization or preg_match().

Parameters

string $line Haystack:

array $rule Rule to process:

Return value

bool True if needle is in haystack.

2 calls to _coder_search_string()
do_coder_review_grep in ./coder.module
Searches for a string.
do_coder_review_grep_invert in ./coder.module
Searches for potentially missing string.

File

./coder.module, line 1140
Developer Module that assists with code review and version upgrade that supports a plug-in extensible hook system so contributed modules can define additional review standards.

Code

function _coder_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);
}