2022-02-16 19:10:41 +03:00
|
|
|
include "internal";
|
|
|
|
include "binary";
|
|
|
|
include "decode";
|
|
|
|
|
2022-01-24 20:21:43 +03:00
|
|
|
def grep_by(f):
|
|
|
|
( ..
|
|
|
|
| select(f)?
|
|
|
|
);
|
2021-09-23 19:35:04 +03:00
|
|
|
|
|
|
|
def _value_grep_string_cond($v; $flags):
|
2021-11-03 19:19:33 +03:00
|
|
|
if type == "string" then test($v; $flags)
|
|
|
|
else false
|
|
|
|
end;
|
2021-10-17 02:26:30 +03:00
|
|
|
|
2021-09-23 19:35:04 +03:00
|
|
|
def _value_grep_other_cond($v; $flags):
|
2021-11-03 19:19:33 +03:00
|
|
|
. == $v;
|
2021-10-17 02:26:30 +03:00
|
|
|
|
2021-09-23 19:35:04 +03:00
|
|
|
def vgrep($v; $flags):
|
2022-01-24 20:21:43 +03:00
|
|
|
if $v | type == "string" then
|
|
|
|
grep_by(_is_scalar and _value_grep_string_cond($v; $flags))
|
|
|
|
else
|
|
|
|
grep_by(_is_scalar and _value_grep_other_cond($v; $flags))
|
|
|
|
end;
|
2021-09-23 19:35:04 +03:00
|
|
|
def vgrep($v): vgrep($v; "");
|
|
|
|
|
2021-10-17 02:26:30 +03:00
|
|
|
def _buf_grep_any_cond($v; $flags):
|
2021-10-20 22:16:13 +03:00
|
|
|
(isempty(tobytesrange | match($v; $flags)) | not)? // false;
|
2021-09-23 19:35:04 +03:00
|
|
|
def bgrep($v; $flags):
|
2022-01-24 20:21:43 +03:00
|
|
|
if $v | type == "string" then
|
|
|
|
grep_by(_is_scalar and _buf_grep_any_cond($v; $flags))
|
|
|
|
else
|
|
|
|
grep_by(_is_scalar and _buf_grep_any_cond($v; $flags))
|
|
|
|
end;
|
2021-09-23 19:35:04 +03:00
|
|
|
def bgrep($v): bgrep($v; "");
|
|
|
|
|
|
|
|
def grep($v; $flags):
|
2022-01-24 20:21:43 +03:00
|
|
|
if $v | type == "string" then
|
|
|
|
grep_by(_is_scalar and _buf_grep_any_cond($v; $flags) or _value_grep_string_cond($v; $flags))
|
|
|
|
else
|
|
|
|
grep_by(_is_scalar and _buf_grep_any_cond($v; $flags) or _value_grep_other_cond($v; $flags))
|
|
|
|
end;
|
2021-09-23 19:35:04 +03:00
|
|
|
def grep($v): grep($v; "");
|
|
|
|
|
|
|
|
def fgrep($v; $flags):
|
2022-01-24 20:21:43 +03:00
|
|
|
grep_by(_is_decode_value and (._name | test($v; $flags))? // false);
|
2021-09-23 19:35:04 +03:00
|
|
|
def fgrep($v): fgrep($v; "");
|