From abc4fb25c3183b18283f2f1e0b9cb6091ef85dc9 Mon Sep 17 00:00:00 2001 From: abrasumente <345396594@qq.com> Date: Sun, 1 May 2022 01:08:27 +0800 Subject: [PATCH] Added: Case insensitive process filtering --- src/btop_tools.hpp | 10 ++++++++++ src/freebsd/btop_collect.cpp | 2 +- src/linux/btop_collect.cpp | 8 ++++---- 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 contains string , 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 from vector , returns size of if is not present template inline size_t v_index(const vector& 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