diff options
author | abrasumente <345396594@qq.com> | 2022-05-01 01:08:27 +0800 |
---|---|---|
committer | abrasumente <345396594@qq.com> | 2022-05-01 01:08:27 +0800 |
commit | abc4fb25c3183b18283f2f1e0b9cb6091ef85dc9 (patch) | |
tree | a691fccb5264f1037d22b3ff166d3828ed284563 /src | |
parent | 0f117a0273271f45908485ea1eebfefd31afee4b (diff) |
Added: Case insensitive process filtering
Diffstat (limited to 'src')
-rw-r--r-- | src/btop_tools.hpp | 10 | ||||
-rw-r--r-- | src/freebsd/btop_collect.cpp | 2 | ||||
-rw-r--r-- | src/linux/btop_collect.cpp | 8 | ||||
-rw-r--r-- | src/osx/btop_collect.cpp | 4 |
4 files changed, 17 insertions, 7 deletions
diff --git a/src/btop_tools.hpp b/src/btop_tools.hpp index 63723cc..862981a 100644 --- a/src/btop_tools.hpp +++ b/src/btop_tools.hpp @@ -187,6 +187,16 @@ namespace Tools { return str.find(find_val) != string::npos; } + //* Check if string <str> contains string <find_val>, while ignoring case + inline bool s_contains_ic(const string& str, const string& find_val) { + auto it = std::search( + str.begin(), str.end(), + find_val.begin(), find_val.end(), + [](char ch1, char ch2) { return std::toupper(ch1) == std::toupper(ch2); } + ); + return it != str.end(); + } + //* Return index of <find_val> from vector <vec>, returns size of <vec> if <find_val> is not present template <typename T> inline size_t v_index(const vector<T>& vec, const T& find_val) { diff --git a/src/freebsd/btop_collect.cpp b/src/freebsd/btop_collect.cpp index 1cf7a1e..7c6c07c 100644 --- a/src/freebsd/btop_collect.cpp +++ b/src/freebsd/btop_collect.cpp @@ -1317,7 +1317,7 @@ namespace Proc { filter_found = 0; for (auto &p : current_procs) { if (not tree and not filter.empty()) { - if (not s_contains(to_string(p.pid), filter) and not s_contains(p.name, filter) and not s_contains(p.cmd, filter) and not s_contains(p.user, filter)) { + if (not s_contains_ic(to_string(p.pid), filter) and not s_contains_ic(p.name, filter) and not s_contains_ic(p.cmd, filter) and not s_contains_ic(p.user, filter)) { p.filtered = true; filter_found++; } else { diff --git a/src/linux/btop_collect.cpp b/src/linux/btop_collect.cpp index 595404d..680b2ce 100644 --- a/src/linux/btop_collect.cpp +++ b/src/linux/btop_collect.cpp @@ -1700,10 +1700,10 @@ namespace Proc { filter_found = 0; for (auto& p : current_procs) { if (not tree and not filter.empty()) { - if (not s_contains(to_string(p.pid), filter) - and not s_contains(p.name, filter) - and not s_contains(p.cmd, filter) - and not s_contains(p.user, filter)) { + if (not s_contains_ic(to_string(p.pid), filter) + and not s_contains_ic(p.name, filter) + and not s_contains_ic(p.cmd, filter) + and not s_contains_ic(p.user, filter)) { p.filtered = true; filter_found++; } diff --git a/src/osx/btop_collect.cpp b/src/osx/btop_collect.cpp index 1e427a5..c9dbcfe 100644 --- a/src/osx/btop_collect.cpp +++ b/src/osx/btop_collect.cpp @@ -1372,7 +1372,7 @@ namespace Proc { filter_found = 0; for (auto &p : current_procs) { if (not tree and not filter.empty()) { - if (not s_contains(to_string(p.pid), filter) and not s_contains(p.name, filter) and not s_contains(p.cmd, filter) and not s_contains(p.user, filter)) { + if (not s_contains_ic(to_string(p.pid), filter) and not s_contains_ic(p.name, filter) and not s_contains_ic(p.cmd, filter) and not s_contains_ic(p.user, filter)) { p.filtered = true; filter_found++; } else { @@ -1432,4 +1432,4 @@ namespace Tools { } return 0.0; } -} // namespace Tools
\ No newline at end of file +} // namespace Tools |