summaryrefslogtreecommitdiff
path: root/it.class
diff options
context:
space:
mode:
authorUrban Müller2017-11-30 15:20:06 +0100
committerUrban Müller2017-11-30 15:20:06 +0100
commit31a609e61f9f400b338dc008c468ff7c07188d31 (patch)
treecff29bf6b83f77b4cb2b7cf1f85154830b622dca /it.class
parent1c08b5b21792e5d8b8c44c13b0cddf36ef950db7 (diff)
downloaditools-31a609e61f9f400b338dc008c468ff7c07188d31.tar.gz
itools-31a609e61f9f400b338dc008c468ff7c07188d31.tar.bz2
itools-31a609e61f9f400b338dc008c468ff7c07188d31.zip
support grep -v
Diffstat (limited to 'it.class')
-rw-r--r--it.class9
1 files changed, 5 insertions, 4 deletions
diff --git a/it.class b/it.class
index 8e8be22..c537ae7 100644
--- a/it.class
+++ b/it.class
@@ -459,16 +459,17 @@ static function replace($replacements, $string, $p = array())
/**
* Returns only the array elements matching the given regex
- * @param $pattern Regex to match against
- * @param $array array to grep
+ * @param $pattern Regex to match against
+ * @param $array array to grep
+ * @param $p parameters for it::match or 'invert' => true to return non-matching lines
* @return New array
*/
static function grep($pattern, $array, $p = array())
{
if (!preg_match('/\\\\[wb]|[!\x80-\xff]|\[\[:/i', $pattern) && !$p)
- $result = preg_grep('!' . $pattern . '!i' . (ini_get('default_charset') == 'utf-8' ? 'u' : ''), $array); # fast path for simple patterns
+ $result = preg_grep('!' . $pattern . '!i' . (ini_get('default_charset') == 'utf-8' ? 'u' : ''), $array, $p['invert'] ? PREG_GREP_INVERT : 0); # fast path
else
- $result = preg_grep(it::convertregex($pattern, $p), $array);
+ $result = preg_grep(it::convertregex($pattern, $p), $array, $p['invert'] ? PREG_GREP_INVERT : 0);
return $result;
}