function _coder_review_search_string in Coder 7.2
Same name and namespace in other branches
- 7 coder_review/coder_review.module \_coder_review_search_string()
Searches for the occurance of a string in a line of text.
This function uses the fastest available PHP function for searching.
Parameters
string $line: Haystack.
array $rule: A Rule array to process.
Return value
TRUE if needle is in haystack; otherwise, FALSE.
2 calls to _coder_review_search_string()
- do_coder_review_grep in coder_review/
coder_review.common.inc - Performs a 'grep' type of coder_review.
- do_coder_review_grep_invert in coder_review/
coder_review.common.inc - Performs a 'grep_invert' type of coder_review.
File
- coder_review/
coder_review.common.inc, line 1266 - Common functions used by both the drush and form interfaces.
Code
function _coder_review_search_string($line, $rule) {
// Case-sensitive search with strpos() (supported everywhere).
if (isset($rule['#case-sensitive'])) {
return strpos($line, $rule['#value']) !== FALSE;
}
// Case-insensitive search with stripos().
if (!isset($rule['#case-sensitive'])) {
return stripos($line, $rule['#value']) !== FALSE;
}
// Case-insensitive search.
$regex = '/' . preg_quote($rule['#value']) . '/i';
return preg_match($regex, $line);
}