function _coder_search_string in Coder 6.2
Same name and namespace in other branches
- 5.2 coder.module \_coder_search_string()
- 5 coder.module \_coder_search_string()
- 6 coder.module \_coder_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_search_string()
- do_coder_review_grep in ./
coder.module - Search for a string.
- do_coder_review_grep_invert in ./
coder.module - Search for potentially missing string.
File
- ./
coder.module, line 1789
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);
}