mirror of
https://github.com/xzeldon/htop.git
synced 2025-07-12 12:14:36 +03:00
Improve String_contains_i to allow for multiple terms
This enables: * Multiple filters in the main panel and strace etc. views * Multiple search terms The search terms are separated by "|" and are still fixed strings matched case-insensitive. Added a multi flag at request of BenBE.
This commit is contained in:
18
XUtils.c
18
XUtils.c
@ -94,8 +94,22 @@ void* xReallocArrayZero(void* ptr, size_t prevmemb, size_t newmemb, size_t size)
|
||||
return ret;
|
||||
}
|
||||
|
||||
inline bool String_contains_i(const char* s1, const char* s2) {
|
||||
return strcasestr(s1, s2) != NULL;
|
||||
inline bool String_contains_i(const char* s1, const char* s2, bool multi) {
|
||||
// we have a multi-string search term, handle as special case for performance reasons
|
||||
if (multi && strstr(s2, "|")) {
|
||||
size_t nNeedles;
|
||||
char** needles = String_split(s2, '|', &nNeedles);
|
||||
for (size_t i = 0; i < nNeedles; i++) {
|
||||
if (strcasestr(s1, needles[i]) != NULL) {
|
||||
String_freeArray(needles);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
String_freeArray(needles);
|
||||
return false;
|
||||
} else {
|
||||
return strcasestr(s1, s2) != NULL;
|
||||
}
|
||||
}
|
||||
|
||||
char* String_cat(const char* s1, const char* s2) {
|
||||
|
Reference in New Issue
Block a user