diff options
author | George Hazan <george.hazan@gmail.com> | 2014-01-20 11:00:47 +0000 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2014-01-20 11:00:47 +0000 |
commit | e6bbc380e84a748242748ba3177e8def969a76cc (patch) | |
tree | d6f34521de127de14736135578a00cafe4441ea4 /plugins | |
parent | 14aac802f833a9a26a4a1f995c642e1ace3e0442 (diff) |
fix for highlighting in tabSRMM
git-svn-id: http://svn.miranda-ng.org/main/trunk@7783 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/TabSRMM/src/chat/muchighlight.cpp | 119 | ||||
-rw-r--r-- | plugins/TabSRMM/src/chat/muchighlight.h | 2 |
2 files changed, 33 insertions, 88 deletions
diff --git a/plugins/TabSRMM/src/chat/muchighlight.cpp b/plugins/TabSRMM/src/chat/muchighlight.cpp index ca3fac39f9..e0fd2a90c7 100644 --- a/plugins/TabSRMM/src/chat/muchighlight.cpp +++ b/plugins/TabSRMM/src/chat/muchighlight.cpp @@ -121,132 +121,77 @@ void CMUCHighlight::tokenize(TCHAR *tszString, TCHAR**& patterns, UINT& nr) int CMUCHighlight::match(const GCEVENT *pgce, const SESSION_INFO *psi, DWORD dwFlags)
{
- int result = 0, nResult = 0;
+ int result = 0, nResult = 0;
if (pgce == 0 || m_Valid == false)
return 0;
__try {
if ((m_dwFlags & MATCH_TEXT) && (dwFlags & MATCH_TEXT) && (m_fHighlightMe || m_iTextPatterns > 0) && psi != 0) {
- #ifdef __HLT_PERFSTATS
- int words = 0;
- M.startTimer();
- #endif
- TCHAR *tszCleaned = pci->RemoveFormatting(pgce->ptszText);
- TCHAR *p = tszCleaned;
- TCHAR *p1;
- UINT i = 0;
-
- TCHAR *tszMe = ((psi && psi->pMe) ? mir_tstrdup(psi->pMe->pszNick) : 0);
- if (tszMe) {
- _wsetlocale(LC_ALL, L"");
- wcslwr(tszMe);
- }
+ TCHAR *p = NEWTSTR_ALLOCA(pci->RemoveFormatting(pgce->ptszText));
+ CharLower(p);
+
+ TCHAR *tszMe = ((psi && psi->pMe) ? NEWTSTR_ALLOCA(psi->pMe->pszNick) : 0);
+ if (tszMe)
+ CharLower(tszMe);
if (m_fHighlightMe && tszMe) {
result = wcsstr(p, tszMe) ? MATCH_TEXT : 0;
if (0 == m_iTextPatterns)
goto skip_textpatterns;
}
- while(p && !result) {
- while(*p && (*p == ' ' || *p == ',' || *p == '.' || *p == ':' || *p == ';' || *p == '?' || *p == '!'))
- p++;
- if (*p) {
- p1 = p;
- while(*p1 && *p1 != ' ' && *p1 != ',' && *p1 != '.' && *p1 != ':' && *p1 != ';' && *p1 != '?' && *p1 != '!')
- p1++;
+ while (p && !result) {
+ while (*p && (*p == ' ' || *p == ',' || *p == '.' || *p == ':' || *p == ';' || *p == '?' || *p == '!'))
+ p++;
- if (*p1)
- *p1 = 0;
- else
- p1 = 0;
+ if (*p == 0)
+ break;
- for (i=0; i < m_iTextPatterns && !result; i++)
- result = wildmatch(m_TextPatterns[i], p) ? MATCH_TEXT : 0;
+ TCHAR *p1 = p;
+ while (*p1 && *p1 != ' ' && *p1 != ',' && *p1 != '.' && *p1 != ':' && *p1 != ';' && *p1 != '?' && *p1 != '!')
+ p1++;
- if (p1) {
- *p1 = ' ';
- p = p1 + 1;
- }
- else
- p = 0;
- #ifdef __HLT_PERFSTATS
- words++;
- #endif
- }
+ if (*p1)
+ *p1 = 0;
else
- break;
- }
-skip_textpatterns:
+ p1 = 0;
+
+ for (UINT i = 0; i < m_iTextPatterns && !result; i++)
+ result = wildcmpt(m_TextPatterns[i], p) ? MATCH_TEXT : 0;
- #ifdef __HLT_PERFSTATS
- M.stopTimer(0);
- if (psi && psi->dat) {
- mir_sntprintf(psi->dat->szStatusBar, 100, _T("PERF text match: %d ticks = %f msec (%d words, %d patterns)"), (int)M.getTicks(), M.getMsec(), words, m_iTextPatterns);
- if (psi->dat->pContainer->hwndStatus)
- ::SendMessage(psi->dat->pContainer->hwndStatus, SB_SETTEXT, 0, (LPARAM)psi->dat->szStatusBar);
+ if (p1) {
+ *p1 = ' ';
+ p = p1 + 1;
+ }
+ else p = 0;
}
- #endif
- mir_free(tszMe);
}
+skip_textpatterns:
+
/*
* optinally, match the nickname against the list of nicks to highlight
*/
if ((m_dwFlags & MATCH_NICKNAME) && (dwFlags & MATCH_NICKNAME) && pgce->ptszNick && m_iNickPatterns > 0) {
for (UINT i = 0; i < m_iNickPatterns && !nResult; i++) {
if (pgce->ptszNick)
- nResult = wildmatch(m_NickPatterns[i], pgce->ptszNick) ? MATCH_NICKNAME : 0;
+ nResult = wildcmpt(m_NickPatterns[i], pgce->ptszNick) ? MATCH_NICKNAME : 0;
if ((m_dwFlags & MATCH_UIN) && pgce->ptszUserInfo)
- nResult = wildmatch(m_NickPatterns[i], pgce->ptszUserInfo) ? MATCH_NICKNAME : 0;
+ nResult = wildcmpt(m_NickPatterns[i], pgce->ptszUserInfo) ? MATCH_NICKNAME : 0;
}
}
return(result | nResult);
}
- __except(CGlobals::Ex_ShowDialog(GetExceptionInformation(), __FILE__, __LINE__, L"MUC_HIGHLIGHT_EXCEPTION", false)) {
+ __except (CGlobals::Ex_ShowDialog(GetExceptionInformation(), __FILE__, __LINE__, L"MUC_HIGHLIGHT_EXCEPTION", false))
+ {
m_Valid = false;
return 0;
}
return 0;
}
-int CMUCHighlight::wildmatch(const TCHAR *pattern, const TCHAR *tszString) {
-
- const TCHAR *cp = 0, *mp = 0;
-
- while ((*tszString) && (*pattern != '*')) {
- if ((*pattern != *tszString) && (*pattern != '?')) {
- return 0;
- }
- pattern++;
- tszString++;
- }
-
- while (*tszString) {
- if (*pattern == '*') {
- if (!*++pattern)
- return 1;
- mp = pattern;
- cp = tszString + 1;
- }
- else if ((*pattern == *tszString) || (*pattern == '?')) {
- pattern++;
- tszString++;
- }
- else {
- pattern = mp;
- tszString = cp++;
- }
- }
-
- while (*pattern == '*')
- pattern++;
-
- return(!*pattern);
-}
-
/**
* Dialog procedure to handle global highlight settings
*
diff --git a/plugins/TabSRMM/src/chat/muchighlight.h b/plugins/TabSRMM/src/chat/muchighlight.h index a752e5c0b0..f86e722175 100644 --- a/plugins/TabSRMM/src/chat/muchighlight.h +++ b/plugins/TabSRMM/src/chat/muchighlight.h @@ -67,7 +67,7 @@ public: private:
void tokenize(TCHAR *tszString, TCHAR**& patterns, UINT& nr);
- int wildmatch (const TCHAR *pattern, const TCHAR *tszString);
+
DWORD m_dwFlags;
bool m_fInitialized;
TCHAR** m_NickPatterns;
|