Merge pull request #8641 from def-/pr-formatting

Also trim search strings in highlights
This commit is contained in:
Robert Müller 2024-07-24 16:31:02 +00:00 committed by GitHub
commit fddba0cc76
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1784,21 +1784,24 @@ bool CMenus::PrintHighlighted(const char *pName, F &&PrintFn)
{ {
const char *pStr = g_Config.m_BrFilterString; const char *pStr = g_Config.m_BrFilterString;
char aFilterStr[sizeof(g_Config.m_BrFilterString)]; char aFilterStr[sizeof(g_Config.m_BrFilterString)];
char aFilterStrTrimmed[sizeof(g_Config.m_BrFilterString)];
while((pStr = str_next_token(pStr, IServerBrowser::SEARCH_EXCLUDE_TOKEN, aFilterStr, sizeof(aFilterStr)))) while((pStr = str_next_token(pStr, IServerBrowser::SEARCH_EXCLUDE_TOKEN, aFilterStr, sizeof(aFilterStr))))
{ {
str_copy(aFilterStrTrimmed, str_utf8_skip_whitespaces(aFilterStr));
str_utf8_trim_right(aFilterStrTrimmed);
// highlight the parts that matches // highlight the parts that matches
const char *pFilteredStr; const char *pFilteredStr;
int FilterLen = str_length(aFilterStr); int FilterLen = str_length(aFilterStrTrimmed);
if(aFilterStr[0] == '"' && aFilterStr[FilterLen - 1] == '"') if(aFilterStrTrimmed[0] == '"' && aFilterStrTrimmed[FilterLen - 1] == '"')
{ {
aFilterStr[FilterLen - 1] = '\0'; aFilterStrTrimmed[FilterLen - 1] = '\0';
pFilteredStr = str_comp(pName, &aFilterStr[1]) == 0 ? pName : nullptr; pFilteredStr = str_comp(pName, &aFilterStrTrimmed[1]) == 0 ? pName : nullptr;
FilterLen -= 2; FilterLen -= 2;
} }
else else
{ {
const char *pFilteredStrEnd; const char *pFilteredStrEnd;
pFilteredStr = str_utf8_find_nocase(pName, aFilterStr, &pFilteredStrEnd); pFilteredStr = str_utf8_find_nocase(pName, aFilterStrTrimmed, &pFilteredStrEnd);
if(pFilteredStr != nullptr && pFilteredStrEnd != nullptr) if(pFilteredStr != nullptr && pFilteredStrEnd != nullptr)
FilterLen = pFilteredStrEnd - pFilteredStr; FilterLen = pFilteredStrEnd - pFilteredStr;
} }