2021-09-23 19:35:04 +03:00
|
|
|
def _grep($v; filter_cond; string_cond; other_cond):
|
|
|
|
if $v | type == "string" then
|
|
|
|
( ..
|
|
|
|
| select(filter_cond and string_cond)
|
|
|
|
)
|
|
|
|
else
|
|
|
|
( ..
|
|
|
|
| select(filter_cond and other_cond)
|
|
|
|
)
|
|
|
|
end;
|
|
|
|
|
|
|
|
def _value_grep_string_cond($v; $flags):
|
|
|
|
( _tovalue
|
|
|
|
| if type == "string" then test($v; $flags)
|
|
|
|
else false
|
|
|
|
end
|
|
|
|
)? // false;
|
2021-10-17 02:26:30 +03:00
|
|
|
|
2021-09-23 19:35:04 +03:00
|
|
|
def _value_grep_other_cond($v; $flags):
|
|
|
|
( _tovalue
|
|
|
|
| . == $v
|
|
|
|
)? // false;
|
2021-10-17 02:26:30 +03:00
|
|
|
|
2021-09-23 19:35:04 +03:00
|
|
|
def vgrep($v; $flags):
|
|
|
|
_grep(
|
|
|
|
$v;
|
|
|
|
_is_scalar;
|
|
|
|
_value_grep_string_cond($v; $flags);
|
|
|
|
_value_grep_other_cond($v; $flags)
|
|
|
|
);
|
2021-10-17 02:26:30 +03:00
|
|
|
|
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-09-23 19:35:04 +03:00
|
|
|
(isempty(find($v; $flags)) | not)? // false;
|
|
|
|
def bgrep($v; $flags):
|
|
|
|
_grep(
|
|
|
|
$v;
|
|
|
|
_is_scalar;
|
2021-10-17 02:26:30 +03:00
|
|
|
_buf_grep_any_cond($v; $flags);
|
|
|
|
_buf_grep_any_cond($v; $flags)
|
2021-09-23 19:35:04 +03:00
|
|
|
);
|
2021-10-17 02:26:30 +03:00
|
|
|
|
2021-09-23 19:35:04 +03:00
|
|
|
def bgrep($v): bgrep($v; "");
|
|
|
|
|
|
|
|
def grep($v; $flags):
|
|
|
|
_grep(
|
|
|
|
$v;
|
|
|
|
_is_scalar;
|
2021-10-17 02:26:30 +03:00
|
|
|
_buf_grep_any_cond($v; $flags) or _value_grep_string_cond($v; $flags);
|
|
|
|
_buf_grep_any_cond($v; $flags) or _value_grep_other_cond($v; $flags)
|
2021-09-23 19:35:04 +03:00
|
|
|
);
|
2021-10-17 02:26:30 +03:00
|
|
|
|
2021-09-23 19:35:04 +03:00
|
|
|
def grep($v): grep($v; "");
|
|
|
|
|
|
|
|
def _field_grep_string_cond($v; $flags):
|
2021-10-17 02:26:30 +03:00
|
|
|
(._name | test($v; $flags))? // false;
|
|
|
|
|
2021-09-23 19:35:04 +03:00
|
|
|
def fgrep($v; $flags):
|
|
|
|
_grep(
|
|
|
|
$v;
|
2021-10-17 02:26:30 +03:00
|
|
|
_is_decode_value;
|
2021-09-23 19:35:04 +03:00
|
|
|
_field_grep_string_cond($v; $flags);
|
|
|
|
empty
|
|
|
|
);
|
2021-10-17 02:26:30 +03:00
|
|
|
|
2021-09-23 19:35:04 +03:00
|
|
|
def fgrep($v): fgrep($v; "");
|