From cf58cd85828eda93e0f6d22c343dba4042d5a165 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Sun, 16 May 2021 12:37:34 +0300 Subject: QuickSearch: fix for pattern search --- plugins/QuickSearch/src/window_misc.cpp | 70 ++++++++++++++++++++++++++++++--- 1 file changed, 65 insertions(+), 5 deletions(-) (limited to 'plugins/QuickSearch/src/window_misc.cpp') diff --git a/plugins/QuickSearch/src/window_misc.cpp b/plugins/QuickSearch/src/window_misc.cpp index a52354b884..b166096a4d 100644 --- a/plugins/QuickSearch/src/window_misc.cpp +++ b/plugins/QuickSearch/src/window_misc.cpp @@ -20,13 +20,75 @@ along with this program. If not, see . ///////////////////////////////////////////////////////////////////////////////////////// // patterns -bool QSMainDlg::CheckPattern(CRowItem *) +bool QSMainDlg::CheckPattern(CRowItem *pRow) { - return true; + if (m_patterns.getCount() == 0) + return true; + + for (auto &p : m_patterns) + p->res = 0; + + int i = 0; + for (auto &it : g_plugin.m_columns) { + if (it->bEnabled && it->bFilter && pRow->pValues[i].text != nullptr) { + CMStringW buf(pRow->pValues[i].text); + buf.MakeLower(); + + for (auto &p : m_patterns) + if (!p->res && buf.Find(p->str) != -1) + p->res = true; + } + i++; + } + + bool result = true; + for (auto &p : m_patterns) + result = result && p->res; + return result; } -void QSMainDlg::MakePattern() +void QSMainDlg::MakePattern(const wchar_t *pwszPattern) { + m_patterns.destroy(); + if (mir_wstrlen(pwszPattern) == 0) + return; + + // m_wszPatternBuf works as a storage for patterns, we store pointers to it in m_patterns + m_wszPatternBuf = mir_wstrdup(pwszPattern); + CharLowerW(m_wszPatternBuf); + + for (wchar_t *p = m_wszPatternBuf; *p; ) { + auto *pWord = wcspbrk(p, L" \""); + if (pWord == nullptr) { + m_patterns.insert(new Pattern(p)); + return; + } + + bool isSpace = pWord[0] == ' '; + + // there's some valuable info between p and pWord + if (pWord != p) { + *pWord = 0; + m_patterns.insert(new Pattern(p)); + } + + if (isSpace) { + p = ltrimpw(pWord + 1); // skip all spaces + } + else { + auto *pEnd = wcschr(++pWord, '\"'); + + // treat the rest of line as one pattern + if (pEnd == nullptr) { + m_patterns.insert(new Pattern(pWord)); + return; + } + + *pEnd = 0; + m_patterns.insert(new Pattern(pWord)); + p = ltrimpw(pEnd + 1); + } + } } ///////////////////////////////////////////////////////////////////////////////////////// @@ -262,8 +324,6 @@ void QSMainDlg::FillGrid() { m_grid.SetDraw(false); - MakePattern(); - for (auto &it: m_rows) ProcessLine(it); -- cgit v1.2.3