From 3576b67db9fa0a3d8d5c1747cc3560504d31d125 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Wed, 5 Mar 2014 12:52:30 +0000 Subject: - adaptation for standard Windows ways of handling Unicode; - obsoleted code removed; - code cleaning git-svn-id: http://svn.miranda-ng.org/main/trunk@8407 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/HistoryStats/src/colbase_words.cpp | 187 ++++++++++++----------------- 1 file changed, 77 insertions(+), 110 deletions(-) (limited to 'plugins/HistoryStats/src/colbase_words.cpp') diff --git a/plugins/HistoryStats/src/colbase_words.cpp b/plugins/HistoryStats/src/colbase_words.cpp index 9325d2a421..74e03ef290 100644 --- a/plugins/HistoryStats/src/colbase_words.cpp +++ b/plugins/HistoryStats/src/colbase_words.cpp @@ -83,63 +83,49 @@ void ColBaseWords::addWord(WordMap* pWords, const ext::string& word, bool bOutgo void ColBaseWords::parseMsg(WordMap* pWords, const ext::string& msg, bool bOutgoing) const { // filter messages - if (m_bFilterMessages) - { + if (m_bFilterMessages) { ext::string msgLC = utils::toLowerCase(msg); upto_each_(i, m_ActiveMessageFilter.size()) { const Filter* pFilter = m_ActiveMessageFilter[i]; - switch (pFilter->getMode()) - { - case Settings::fwmMessagesMatching: - { - citer_each_(WordSet, j, pFilter->getWords()) - { - if (msgLC == *j) - { - return; - } - } + switch (pFilter->getMode()) { + case Settings::fwmMessagesMatching: + citer_each_(WordSet, j, pFilter->getWords()) + { + if (msgLC == *j) { + return; } - break; - - case Settings::fwmMessagesContaining: - { - citer_each_(WordSet, j, pFilter->getWords()) - { - if (msgLC.find(*j) != ext::string::npos) - { - return; - } - } + } + break; + + case Settings::fwmMessagesContaining: + citer_each_(WordSet, j, pFilter->getWords()) + { + if (msgLC.find(*j) != ext::string::npos) { + return; } - break; - - case Settings::fwmMessagesStartingWith: - { - citer_each_(WordSet, j, pFilter->getWords()) - { - if (msgLC.length() >= j->length() && msgLC.substr(0, j->length()) == *j) - { - return; - } - } + } + break; + + case Settings::fwmMessagesStartingWith: + citer_each_(WordSet, j, pFilter->getWords()) + { + if (msgLC.length() >= j->length() && msgLC.substr(0, j->length()) == *j) { + return; } - break; - - case Settings::fwmMessagesEndingWith: - { - citer_each_(WordSet, j, pFilter->getWords()) - { - if (msgLC.length() >= j->length() && msgLC.substr(msgLC.length() - j->length(), j->length()) == *j) - { - return; - } - } + } + break; + + case Settings::fwmMessagesEndingWith: + citer_each_(WordSet, j, pFilter->getWords()) + { + if (msgLC.length() >= j->length() && msgLC.substr(msgLC.length() - j->length(), j->length()) == *j) { + return; } - break; + } + break; } } } @@ -148,25 +134,19 @@ void ColBaseWords::parseMsg(WordMap* pWords, const ext::string& msg, bool bOutgo ext::string::size_type firstChar = 0; ext::string::size_type nextSpace; - while (firstChar < msg.length() && getCharMapper()->mapChar(msg[firstChar]) == muC(' ')) - { + while (firstChar < msg.length() && getCharMapper()->mapChar(msg[firstChar]) == ' ') ++firstChar; - } - while (firstChar < msg.length()) - { + while (firstChar < msg.length()) { nextSpace = firstChar + 1; - while (nextSpace < msg.length() && getCharMapper()->mapChar(msg[nextSpace]) != muC(' ')) - { + while (nextSpace < msg.length() && getCharMapper()->mapChar(msg[nextSpace]) != ' ') ++nextSpace; - } int wordLen = nextSpace - firstChar; - if (wordLen >= m_nMinLength && (m_nMaxLength == 0 || wordLen <= m_nMaxLength)) - { - ext::string word(wordLen, muC('_')); + if (wordLen >= m_nMinLength && (m_nMaxLength == 0 || wordLen <= m_nMaxLength)) { + ext::string word(wordLen, '_'); upto_each_(i, wordLen) { @@ -178,10 +158,8 @@ void ColBaseWords::parseMsg(WordMap* pWords, const ext::string& msg, bool bOutgo firstChar = nextSpace + 1; - while (firstChar < msg.length() && getCharMapper()->mapChar(msg[firstChar]) == muC(' ')) - { + while (firstChar < msg.length() && getCharMapper()->mapChar(msg[firstChar]) == ' ') ++firstChar; - } } } @@ -216,7 +194,7 @@ void ColBaseWords::impl_configRead(const SettingsTree& settings) upto_each_(i, nCount) { - m_FilterWords.insert(settings.readStr((con::KeyFilterWords + utils::intToString(i)).c_str(), muT(""))); + m_FilterWords.insert(settings.readStr((con::KeyFilterWords + utils::intToString(i)).c_str(), _T(""))); } } @@ -242,14 +220,14 @@ void ColBaseWords::impl_configToUI(OptionsCtrl& Opt, OptionsCtrl::Item hGroup) { OptionsCtrl::Group hTemp; - /**/hTemp = Opt.insertGroup (hGroup, i18n(muT("Extract words from"))); - /**/ m_hSource = Opt.insertRadio (hTemp, NULL, i18n(muT("Incoming messages"))); - /**/ Opt.insertRadio (hTemp, m_hSource, i18n(muT("Outgoing messages"))); - /**/ Opt.insertRadio (hTemp, m_hSource, i18n(muT("All messages"))); - /**/m_hMinLength = Opt.insertEdit (hGroup, i18n(muT("Ignore words shorter than (chars)")), muT(""), OptionsCtrl::OCF_NUMBER); - /**/m_hMaxLength = Opt.insertEdit (hGroup, i18n(muT("Ignore words longer than (chars, 0=no limit)")), muT(""), OptionsCtrl::OCF_NUMBER); - /**/m_hFilterLinks = Opt.insertCheck (hGroup, i18n(muT("Filter URLs/e-mail addresses"))); - /**/ Opt.insertButton(hGroup, i18n(muT("Filter words/messages")), i18n(muT("Define...")), 0, Settings::biFilterWords); + hTemp = Opt.insertGroup (hGroup, TranslateT("Extract words from")); + m_hSource = Opt.insertRadio (hTemp, NULL, TranslateT("Incoming messages")); + Opt.insertRadio (hTemp, m_hSource, TranslateT("Outgoing messages")); + Opt.insertRadio (hTemp, m_hSource, TranslateT("All messages")); + m_hMinLength = Opt.insertEdit(hGroup, TranslateT("Ignore words shorter than (chars)"), _T(""), OptionsCtrl::OCF_NUMBER); + m_hMaxLength = Opt.insertEdit(hGroup, TranslateT("Ignore words longer than (chars, 0=no limit)"), _T(""), OptionsCtrl::OCF_NUMBER); + m_hFilterLinks = Opt.insertCheck(hGroup, TranslateT("Filter URLs/e-mail addresses")); + Opt.insertButton(hGroup, TranslateT("Filter words/messages"), TranslateT("Define..."), 0, Settings::biFilterWords); Opt.setRadioChecked(m_hSource , m_nSource ); Opt.setEditNumber (m_hMinLength , m_nMinLength ); @@ -259,10 +237,10 @@ void ColBaseWords::impl_configToUI(OptionsCtrl& Opt, OptionsCtrl::Item hGroup) void ColBaseWords::impl_configFromUI(OptionsCtrl& Opt) { - m_nSource = Opt.getRadioChecked(m_hSource ); - m_nMinLength = Opt.getEditNumber (m_hMinLength ); - m_nMaxLength = Opt.getEditNumber (m_hMaxLength ); - m_bFilterLinks = Opt.isItemChecked (m_hFilterLinks); + m_nSource = Opt.getRadioChecked(m_hSource); + m_nMinLength = Opt.getEditNumber(m_hMinLength); + m_nMaxLength = Opt.getEditNumber(m_hMaxLength); + m_bFilterLinks = Opt.isItemChecked(m_hFilterLinks); // ensure constraints utils::ensureRange(m_nMinLength, 1, 1000, 1); @@ -271,15 +249,15 @@ void ColBaseWords::impl_configFromUI(OptionsCtrl& Opt) ext::string ColBaseWords::impl_contactDataGetUID() const { - ext::string strUID = ext::str(ext::format(muT("words-|-|-|-|")) - % m_nSource - % m_nMinLength - % m_nMaxLength - % (m_bFilterLinks ? 1 : 0)); + ext::string strUID = ext::str(ext::format(_T("words-|-|-|-|")) + % m_nSource + % m_nMinLength + % m_nMaxLength + % (m_bFilterLinks ? 1 : 0)); citer_each_(ColFilterSet, i, m_FilterWords) { - strUID += muT("-"); + strUID += _T("-"); strUID += *i; } @@ -297,25 +275,23 @@ void ColBaseWords::impl_contactDataBeginAcquire() { const Filter* pFilter = getSettings()->getFilter(*i); - if (pFilter && !pFilter->getWords().empty()) - { - switch (pFilter->getMode()) - { - case Settings::fwmMessagesMatching: - case Settings::fwmMessagesContaining: - case Settings::fwmMessagesStartingWith: - case Settings::fwmMessagesEndingWith: - m_ActiveMessageFilter.push_back(pFilter); - m_bFilterMessages = true; - break; - - case Settings::fwmWordsMatching: - case Settings::fwmWordsContaining: - case Settings::fwmWordsStartingWith: - case Settings::fwmWordsEndingWith: - m_ActiveWordFilter.push_back(pFilter); - m_bFilterWords = true; - break; + if (pFilter && !pFilter->getWords().empty()) { + switch (pFilter->getMode()) { + case Settings::fwmMessagesMatching: + case Settings::fwmMessagesContaining: + case Settings::fwmMessagesStartingWith: + case Settings::fwmMessagesEndingWith: + m_ActiveMessageFilter.push_back(pFilter); + m_bFilterMessages = true; + break; + + case Settings::fwmWordsMatching: + case Settings::fwmWordsContaining: + case Settings::fwmWordsStartingWith: + case Settings::fwmWordsEndingWith: + m_ActiveWordFilter.push_back(pFilter); + m_bFilterWords = true; + break; } } } @@ -324,16 +300,13 @@ void ColBaseWords::impl_contactDataBeginAcquire() void ColBaseWords::impl_contactDataPrepare(Contact& contact) const { WordMap* pData = new WordMap; - contact.setSlot(contactDataSlotGet(), pData); } void ColBaseWords::impl_contactDataFree(Contact& contact) const { WordMap* pData = reinterpret_cast(contact.getSlot(contactDataSlotGet())); - - if (pData) - { + if (pData) { delete pData; contact.setSlot(contactDataSlotGet(), NULL); } @@ -341,10 +314,8 @@ void ColBaseWords::impl_contactDataFree(Contact& contact) const void ColBaseWords::impl_contactDataAcquireMessage(Contact& contact, Message& msg) { - if (m_nSource == 2 || m_nSource == 1 && msg.isOutgoing() || m_nSource == 0 && !msg.isOutgoing()) - { + if (m_nSource == 2 || m_nSource == 1 && msg.isOutgoing() || m_nSource == 0 && !msg.isOutgoing()) { WordMap* pData = reinterpret_cast(contact.getSlot(contactDataSlotGet())); - parseMsg(pData, m_bFilterLinks ? msg.getWithoutLinks() : msg.getRaw(), msg.isOutgoing()); } } @@ -357,12 +328,8 @@ void ColBaseWords::impl_contactDataMerge(Contact& contact, const Contact& includ citer_each_(WordMap, j, *pIncData) { if (pData->find(j->first) != pData->end()) - { (*pData)[j->first] += j->second; - } else - { pData->insert(*j); - } } } -- cgit v1.2.3