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;
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))))
{
str_copy(aFilterStrTrimmed, str_utf8_skip_whitespaces(aFilterStr));
str_utf8_trim_right(aFilterStrTrimmed);
// highlight the parts that matches
const char *pFilteredStr;
int FilterLen = str_length(aFilterStr);
if(aFilterStr[0] == '"' && aFilterStr[FilterLen - 1] == '"')
int FilterLen = str_length(aFilterStrTrimmed);
if(aFilterStrTrimmed[0] == '"' && aFilterStrTrimmed[FilterLen - 1] == '"')
{
aFilterStr[FilterLen - 1] = '\0';
pFilteredStr = str_comp(pName, &aFilterStr[1]) == 0 ? pName : nullptr;
aFilterStrTrimmed[FilterLen - 1] = '\0';
pFilteredStr = str_comp(pName, &aFilterStrTrimmed[1]) == 0 ? pName : nullptr;
FilterLen -= 2;
}
else
{
const char *pFilteredStrEnd;
pFilteredStr = str_utf8_find_nocase(pName, aFilterStr, &pFilteredStrEnd);
pFilteredStr = str_utf8_find_nocase(pName, aFilterStrTrimmed, &pFilteredStrEnd);
if(pFilteredStr != nullptr && pFilteredStrEnd != nullptr)
FilterLen = pFilteredStrEnd - pFilteredStr;
}