summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKirill Volinsky <mataes2007@gmail.com>2015-04-24 09:32:54 +0000
committerKirill Volinsky <mataes2007@gmail.com>2015-04-24 09:32:54 +0000
commit5cf0f0757def7cadf17f9d66de9dd56e2031a999 (patch)
treee6609d9b24252eb24345844b747a1684f4eb7679
parent729e6fd4c3ba9c37ee5001c56ebb165f4d5cefe2 (diff)
fixed substring replacement
git-svn-id: http://svn.miranda-ng.org/main/trunk@13075 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
-rw-r--r--plugins/NewsAggregator/Src/CheckFeed.cpp39
-rw-r--r--plugins/NewsAggregator/Src/Common.h1
-rw-r--r--plugins/NewsAggregator/Src/Utils.cpp91
3 files changed, 19 insertions, 112 deletions
diff --git a/plugins/NewsAggregator/Src/CheckFeed.cpp b/plugins/NewsAggregator/Src/CheckFeed.cpp
index 08888867a9..7daad6dc2f 100644
--- a/plugins/NewsAggregator/Src/CheckFeed.cpp
+++ b/plugins/NewsAggregator/Src/CheckFeed.cpp
@@ -80,44 +80,44 @@ TCHAR* CheckFeed(TCHAR *tszURL, HWND hwndDlg)
static void XmlToMsg(MCONTACT hContact, CMString &title, CMString &link, CMString &descr, CMString &author, CMString &comments, CMString &guid, CMString &category, time_t stamp)
{
- TCHAR *message = db_get_tsa(hContact, MODULE, "MsgFormat");
+ CMString message = db_get_tsa(hContact, MODULE, "MsgFormat");
if (!message)
message = mir_tstrdup(TAGSDEFAULT);
if (title.IsEmpty())
- StrReplace(_T("#<title>#"), TranslateT("empty"), message);
+ message.Replace(_T("#<title>#"), TranslateT("empty"));
else
- StrReplace(_T("#<title>#"), title, message);
+ message.Replace(_T("#<title>#"), title);
if (link.IsEmpty())
- StrReplace(_T("#<link>#"), TranslateT("empty"), message);
+ message.Replace(_T("#<link>#"), TranslateT("empty"));
else
- StrReplace(_T("#<link>#"), link, message);
+ message.Replace(_T("#<link>#"), link);
if (descr.IsEmpty())
- StrReplace(_T("#<description>#"), TranslateT("empty"), message);
+ message.Replace(_T("#<description>#"), TranslateT("empty"));
else
- StrReplace(_T("#<description>#"), descr, message);
+ message.Replace(_T("#<description>#"), descr);
if (author.IsEmpty())
- StrReplace(_T("#<author>#"), TranslateT("empty"), message);
+ message.Replace(_T("#<author>#"), TranslateT("empty"));
else
- StrReplace(_T("#<author>#"), author, message);
+ message.Replace(_T("#<author>#"), author);
if (comments.IsEmpty())
- StrReplace(_T("#<comments>#"), TranslateT("empty"), message);
+ message.Replace(_T("#<comments>#"), TranslateT("empty"));
else
- StrReplace(_T("#<comments>#"), comments, message);
+ message.Replace(_T("#<comments>#"), comments);
if (guid.IsEmpty())
- StrReplace(_T("#<guid>#"), TranslateT("empty"), message);
+ message.Replace(_T("#<guid>#"), TranslateT("empty"));
else
- StrReplace(_T("#<guid>#"), guid, message);
+ message.Replace(_T("#<guid>#"), guid);
if (category.IsEmpty())
- StrReplace(_T("#<category>#"), TranslateT("empty"), message);
+ message.Replace(_T("#<category>#"), TranslateT("empty"));
else
- StrReplace(_T("#<category>#"), category, message);
+ message.Replace(_T("#<category>#"), category);
DBEVENTINFO olddbei = { 0 };
olddbei.cbSize = sizeof(olddbei);
@@ -151,10 +151,9 @@ static void XmlToMsg(MCONTACT hContact, CMString &title, CMString &link, CMStrin
PROTORECVEVENT recv = { 0 };
recv.flags = PREF_TCHAR;
recv.timestamp = (DWORD)stamp;
- recv.tszMessage = message;
+ recv.tszMessage = (TCHAR*)message.c_str();
ProtoChainRecvMsg(hContact, &recv);
}
- mir_free(message);
}
void CheckCurrentFeed(MCONTACT hContact)
@@ -266,9 +265,9 @@ void CheckCurrentFeed(MCONTACT hContact)
TCHAR *ext = _tcsrchr((TCHAR *)url, _T('.')) + 1;
pai.format = ProtoGetAvatarFormat(url);
- TCHAR *filename = szNick;
- StrReplace(_T("/"), _T("_"), filename);
- mir_sntprintf(pai.filename, SIZEOF(pai.filename), _T("%s\\%s.%s"), tszRoot, filename, ext);
+ CMString filename = szNick;
+ filename.Replace(_T("/"), _T("_"));
+ mir_sntprintf(pai.filename, SIZEOF(pai.filename), _T("%s\\%s.%s"), tszRoot, filename.c_str(), ext);
CreateDirectoryTreeT(tszRoot);
if (DownloadFile(url, pai.filename)) {
db_set_ts(hContact, MODULE, "ImagePath", pai.filename);
diff --git a/plugins/NewsAggregator/Src/Common.h b/plugins/NewsAggregator/Src/Common.h
index 9009e4dca2..da0659d198 100644
--- a/plugins/NewsAggregator/Src/Common.h
+++ b/plugins/NewsAggregator/Src/Common.h
@@ -135,7 +135,6 @@ void UpdateMenu(bool State);
int ImportFeedsDialog();
LPCTSTR ClearText(CMString &value, const TCHAR *message);
bool DownloadFile(LPCTSTR tszURL, LPCTSTR tszLocal);
-int StrReplace(TCHAR *lpszOld, const TCHAR *lpszNew, TCHAR *&lpszStr);
void CreateAuthString(char *auth, MCONTACT hContact, HWND hwndDlg);
INT_PTR CALLBACK AuthenticationProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam);
INT_PTR CALLBACK DlgProcImportOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam);
diff --git a/plugins/NewsAggregator/Src/Utils.cpp b/plugins/NewsAggregator/Src/Utils.cpp
index ffcb2ec955..8750bde3df 100644
--- a/plugins/NewsAggregator/Src/Utils.cpp
+++ b/plugins/NewsAggregator/Src/Utils.cpp
@@ -284,97 +284,6 @@ time_t __stdcall DateToUnixTime(const TCHAR *stamp, bool FeedType)
return (t >= 0) ? t : 0;
}
-TCHAR * _tcsistr(const TCHAR *str, const TCHAR *substr)
-{
- if (!str || !substr || (substr[0] == _T('\0')))
- return (TCHAR *)str;
-
- size_t nLen = mir_tstrlen(substr);
- while (*str)
- {
- if (_tcsnicmp(str, substr, nLen) == 0)
- break;
- str++;
- }
-
- if (*str == _T('\0'))
- str = NULL;
-
- return (TCHAR *)str;
-}
-
-int StrReplace(TCHAR *lpszOld, const TCHAR *lpszNew, TCHAR *&lpszStr)
-{
- if (!lpszStr || !lpszOld || !lpszNew)
- return 0;
-
- size_t nStrLen = mir_tstrlen(lpszStr);
- if (nStrLen == 0)
- return 0;
-
- size_t nOldLen = mir_tstrlen(lpszOld);
- if (nOldLen == 0)
- return 0;
-
- size_t nNewLen = mir_tstrlen(lpszNew);
-
- // loop once to figure out the size of the result string
- size_t nCount = 0;
- TCHAR *pszStart = (TCHAR *)lpszStr;
- TCHAR *pszEnd = (TCHAR *)lpszStr + nStrLen;
- TCHAR *pszTarget = NULL;
- TCHAR *pszResultStr = NULL;
-
- while (pszStart < pszEnd) {
- while ((pszTarget = _tcsistr(pszStart, lpszOld)) != NULL) {
- nCount++;
- pszStart = pszTarget + nOldLen;
- }
- pszStart += mir_tstrlen(pszStart);
- }
-
- // if any changes, make them now
- if (nCount > 0) {
- // allocate buffer for result string
- size_t nResultStrSize = nStrLen + (nNewLen - nOldLen) * nCount + 2;
- pszResultStr = new TCHAR[nResultStrSize];
- memset(pszResultStr, 0, (nResultStrSize * sizeof(TCHAR)));
-
- pszStart = (TCHAR *)lpszStr;
- pszEnd = (TCHAR *)lpszStr + nStrLen;
- TCHAR *cp = pszResultStr;
-
- // loop again to actually do the work
- while (pszStart < pszEnd) {
- while ((pszTarget = _tcsistr(pszStart, lpszOld)) != NULL) {
- size_t nCopyLen = (size_t)(pszTarget - pszStart);
- mir_tstrncpy(cp, &lpszStr[pszStart - lpszStr], nCopyLen);
-
- cp += nCopyLen;
-
- pszStart = pszTarget + nOldLen;
-
- mir_tstrcpy(cp, lpszNew);
-
- cp += nNewLen;
- }
- mir_tstrcpy(cp, pszStart);
- pszStart += mir_tstrlen(pszStart);
- }
-
- if (pszResultStr)
- lpszStr = mir_tstrdup(pszResultStr);
- }
-
- int nSize = 0;
- if (pszResultStr) {
- nSize = (int)mir_tstrlen(pszResultStr);
- delete[] pszResultStr;
- }
-
- return nSize;
-}
-
bool DownloadFile(LPCTSTR tszURL, LPCTSTR tszLocal)
{
NETLIBHTTPREQUEST nlhr = { 0 };