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/message.cpp | 168 ++++++++++++----------------------- 1 file changed, 55 insertions(+), 113 deletions(-) (limited to 'plugins/HistoryStats/src/message.cpp') diff --git a/plugins/HistoryStats/src/message.cpp b/plugins/HistoryStats/src/message.cpp index b72f92bfda..505d1b8e87 100644 --- a/plugins/HistoryStats/src/message.cpp +++ b/plugins/HistoryStats/src/message.cpp @@ -9,61 +9,49 @@ void Message::makeRawAvailable() { - do - { -#if defined(MU_WIDE) - if (m_Available & PtrIsNonT) - { - m_Raw = utils::fromA(ext::a::string(reinterpret_cast(m_RawSource), m_nLength)); + do { + if (m_Available & PtrIsNonT) { + m_Raw = utils::fromA(ext::a::string(reinterpret_cast(m_RawSource), m_nLength)); m_Available |= Raw; - break; } -#endif // MU_WIDE - if (m_Available & PtrIsUTF8) - { - m_Raw = utils::fromUTF8(reinterpret_cast(m_RawSource)); + if (m_Available & PtrIsUTF8) { + m_Raw = utils::fromUTF8(reinterpret_cast(m_RawSource)); m_Available |= Raw; - break; } - m_Raw.assign(reinterpret_cast(m_RawSource), m_nLength); + m_Raw.assign(reinterpret_cast(m_RawSource), m_nLength); m_Available |= Raw; - } while(false); + } + while (false); if (m_bStripRawRTF) - { stripRawRTF(); - } if (m_bStripBBCodes) - { stripBBCodes(); - } } void Message::stripRawRTF() { - if (m_Raw.substr(0, 6) == muT("{\\rtf1")) - { + if (m_Raw.substr(0, 6) == _T("{\\rtf1")) m_Raw = RTFFilter::filter(m_Raw); - } } void Message::stripBBCodes() { - static const mu_text* szSimpleBBCodes[][2] = { - { muT("[b]"), muT("[/b]") }, - { muT("[u]"), muT("[/u]") }, - { muT("[i]"), muT("[/i]") }, - { muT("[s]"), muT("[/s]") }, + static const TCHAR* szSimpleBBCodes[][2] = { + { _T("[b]"), _T("[/b]") }, + { _T("[u]"), _T("[/u]") }, + { _T("[i]"), _T("[/i]") }, + { _T("[s]"), _T("[/s]") }, }; - static const mu_text* szParamBBCodes[][2] = { - { muT("[url=") , muT("[/url]") }, - { muT("[color="), muT("[/color]") }, + static const TCHAR* szParamBBCodes[][2] = { + { _T("[url="), _T("[/url]") }, + { _T("[color="), _T("[/color]") }, }; // convert raw string to lower case @@ -72,26 +60,21 @@ void Message::stripBBCodes() // remove simple BBcodes array_each_(i, szSimpleBBCodes) { - const mu_text* szOpenTag = szSimpleBBCodes[i][0]; - const mu_text* szCloseTag = szSimpleBBCodes[i][1]; + const TCHAR* szOpenTag = szSimpleBBCodes[i][0]; + const TCHAR* szCloseTag = szSimpleBBCodes[i][1]; int lenOpen = ext::strfunc::len(szOpenTag); int lenClose = ext::strfunc::len(szCloseTag); - + ext::string::size_type posOpen = 0; ext::string::size_type posClose = 0; - while (true) - { + while (true) { if ((posOpen = strRawLC.find(szOpenTag, posOpen)) == ext::string::npos) - { break; - } if ((posClose = strRawLC.find(szCloseTag, posOpen + lenOpen)) == ext::string::npos) - { break; - } strRawLC.erase(posOpen, lenOpen); strRawLC.erase(posClose - lenOpen, lenClose); @@ -105,32 +88,25 @@ void Message::stripBBCodes() // remove BBcodes with parameters array_each_(i, szParamBBCodes) { - const mu_text* szOpenTag = szParamBBCodes[i][0]; - const mu_text* szCloseTag = szParamBBCodes[i][1]; - + const TCHAR* szOpenTag = szParamBBCodes[i][0]; + const TCHAR* szCloseTag = szParamBBCodes[i][1]; + int lenOpen = ext::strfunc::len(szOpenTag); int lenClose = ext::strfunc::len(szCloseTag); - + ext::string::size_type posOpen = 0; ext::string::size_type posOpen2 = 0; ext::string::size_type posClose = 0; - while (true) - { + while (true) { if ((posOpen = strRawLC.find(szOpenTag, posOpen)) == ext::string::npos) - { break; - } - if ((posOpen2 = strRawLC.find(muC(']'), posOpen + lenOpen)) == ext::string::npos) - { + if ((posOpen2 = strRawLC.find(']', posOpen + lenOpen)) == ext::string::npos) break; - } if ((posClose = strRawLC.find(szCloseTag, posOpen2 + 1)) == ext::string::npos) - { break; - } strRawLC.erase(posOpen, posOpen2 - posOpen + 1); strRawLC.erase(posClose - posOpen2 + posOpen - 1, lenClose); @@ -144,11 +120,11 @@ void Message::stripBBCodes() void Message::filterLinks() { - static const mu_text* szSpaces = muT(" \r\r\n"); - static const mu_text* szPrefixes = muT("([{<:\"'"); - static const mu_text* szSuffixes = muT(".,:;!?)]}>\"'"); - static const mu_text* szValidProtocol = muT("abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"); - static const mu_text* szValidHost = muT(".-abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"); + static const TCHAR* szSpaces = _T(" \r\r\n"); + static const TCHAR* szPrefixes = _T("([{<:\"'"); + static const TCHAR* szSuffixes = _T(".,:;!?)]}>\"'"); + static const TCHAR* szValidProtocol = _T("abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"); + static const TCHAR* szValidHost = _T(".-abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"); // init with raw text m_WithoutLinks = getRaw(); @@ -157,20 +133,16 @@ void Message::filterLinks() ext::string::size_type pos = -1; // detect: protocol://[user[:password]@]host[/path] - while (true) - { - if ((pos = msg.find(muT("://"), pos + 1)) == ext::string::npos) - { + while (true) { + if ((pos = msg.find(_T("://"), pos + 1)) == ext::string::npos) break; - } // find start of URL ext::string::size_type pos_proto = msg.find_last_not_of(szValidProtocol, pos - 1); (pos_proto == ext::string::npos) ? pos_proto = 0 : ++pos_proto; - if (pos_proto < pos) - { + if (pos_proto < pos) { // find end of URL ext::string::size_type pos_last = msg.find_first_of(szSpaces, pos + 3); @@ -178,35 +150,26 @@ void Message::filterLinks() // filter suffixes (punctuation, parentheses, ...) if (ext::strfunc::chr(szSuffixes, msg[pos_last])) - { --pos_last; - } // find slash: for host name validation - ext::string::size_type pos_slash = msg.find(muC('/'), pos + 3); + ext::string::size_type pos_slash = msg.find('/', pos + 3); if (pos_slash == ext::string::npos || pos_slash > pos_last) - { pos_slash = pos_last + 1; - } // find at: for host name validation - ext::string::size_type pos_at = msg.find(muC('@'), pos + 3); + ext::string::size_type pos_at = msg.find('@', pos + 3); if (pos_at == ext::string::npos || pos_at > pos_slash) - { pos_at = pos + 2; - } // check for valid host (x.x) - if (pos_slash - pos_at > 3) - { + if (pos_slash - pos_at > 3) { ext::string::size_type pos_invalid = msg.find_first_not_of(szValidHost, pos_at + 1); - if (pos_invalid == ext::string::npos || pos_invalid >= pos_slash) - { - if (std::count(msg.begin() + pos_at + 1, msg.begin() + pos_slash, muC('.')) >= 1) - { + if (pos_invalid == ext::string::npos || pos_invalid >= pos_slash) { + if (std::count(msg.begin() + pos_at + 1, msg.begin() + pos_slash, '.') >= 1) { ext::string link = msg.substr(pos_proto, pos_last - pos_proto + 1); // remove extracted link from message text @@ -219,16 +182,13 @@ void Message::filterLinks() } } } - + // detect: www.host[/path] pos = -1; - while (true) - { - if ((pos = msg.find(muT("www."), pos + 1)) == ext::string::npos) - { + while (true) { + if ((pos = msg.find(_T("www."), pos + 1)) == ext::string::npos) break; - } // find end of URL ext::string::size_type pos_last = msg.find_first_of(szSpaces, pos + 4); @@ -237,31 +197,24 @@ void Message::filterLinks() // filter suffixes (punctuation, parentheses, ...) if (ext::strfunc::chr(szSuffixes, msg[pos_last])) - { --pos_last; - } // find slash: for host name validation - ext::string::size_type pos_slash = msg.find(muC('/'), pos + 4); + ext::string::size_type pos_slash = msg.find('/', pos + 4); if (pos_slash == ext::string::npos || pos_slash > pos_last) - { pos_slash = pos_last + 1; - } // find at: for host name validation ext::string::size_type pos_at = pos + 3; // check for valid host (x.x) - if (pos_slash - pos_at > 3) - { + if (pos_slash - pos_at > 3) { ext::string::size_type pos_invalid = msg.find_first_not_of(szValidHost, pos_at + 1); - if (pos_invalid == ext::string::npos || pos_invalid >= pos_slash) - { - if (std::count(msg.begin() + pos_at + 1, msg.begin() + pos_slash, muC('.')) >= 1) - { - ext::string link = muT("http://") + msg.substr(pos, pos_last - pos + 1); + if (pos_invalid == ext::string::npos || pos_invalid >= pos_slash) { + if (std::count(msg.begin() + pos_at + 1, msg.begin() + pos_slash, '.') >= 1) { + ext::string link = _T("http://") + msg.substr(pos, pos_last - pos + 1); // remove extracted link from message text msg.erase(pos, link.length() - 7); @@ -276,15 +229,11 @@ void Message::filterLinks() // detect: user@host pos = -1; - while (true) - { - if ((pos = msg.find(muC('@'), pos + 1)) == ext::string::npos) - { + while (true) { + if ((pos = msg.find('@', pos + 1)) == ext::string::npos) break; - } - if (pos > 0 && pos < msg.length() - 1) - { + if (pos > 0 && pos < msg.length() - 1) { // find end of address ext::string::size_type pos_last = msg.find_first_not_of(szValidHost, pos + 1); @@ -292,9 +241,7 @@ void Message::filterLinks() // filter suffixes (punctuation, parentheses, ...) if (ext::strfunc::chr(szSuffixes, msg[pos_last])) - { --pos_last; - } // find start of address ext::string::size_type pos_first = msg.find_last_of(szSpaces, pos - 1); @@ -303,15 +250,11 @@ void Message::filterLinks() // filter prefixes (punctuation, parentheses, ...) if (ext::strfunc::chr(szPrefixes, msg[pos_first])) - { ++pos_first; - } // check for valid host (x.x) - if (pos_first < pos && pos_last - pos >= 3) - { - if (std::count(msg.begin() + pos + 1, msg.begin() + pos_last + 1, muC('.')) >= 1) - { + if (pos_first < pos && pos_last - pos >= 3) { + if (std::count(msg.begin() + pos + 1, msg.begin() + pos_last + 1, '.') >= 1) { ext::string link = msg.substr(pos_first, pos_last - pos_first + 1); // remove extracted link from message text @@ -319,9 +262,8 @@ void Message::filterLinks() pos = pos_last - (link.length()); // prepend "mailto:" if missing - if (link.substr(0, 7) != muT("mailto:")) - { - link.insert(0, muT("mailto:")); + if (link.substr(0, 7) != _T("mailto:")) { + link.insert(0, _T("mailto:")); } // TODO: put link in list -- cgit v1.2.3