summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/m_chat.h2
-rw-r--r--plugins/Scriver/src/msgdialog.cpp1
-rw-r--r--plugins/TabSRMM/src/msgdlgother.cpp88
-rw-r--r--protocols/Discord/src/groupchat.cpp1
-rw-r--r--protocols/Facebook/src/groupchats.cpp7
-rw-r--r--protocols/Facebook/src/server.cpp1
-rw-r--r--protocols/IRCG/src/channelList.cpp3
-rw-r--r--protocols/IRCG/src/commandmonitor.cpp14
-rw-r--r--protocols/IRCG/src/input.cpp2
-rw-r--r--protocols/IRCG/src/ircproto.cpp1
-rw-r--r--protocols/IRCG/src/output.cpp3
-rw-r--r--protocols/IRCG/src/services.cpp104
-rw-r--r--protocols/IRCG/src/stdafx.h16
-rw-r--r--protocols/IRCG/src/tools.cpp75
-rw-r--r--protocols/JabberG/src/jabber_chat.cpp4
-rw-r--r--protocols/JabberG/src/jabber_groupchat.cpp1
-rw-r--r--protocols/MinecraftDynmap/src/chat.cpp6
-rw-r--r--protocols/SkypeWeb/src/skype_chatrooms.cpp7
-rw-r--r--protocols/Telegram/src/groupchat.cpp1
-rw-r--r--protocols/Twitter/src/chat.cpp2
-rw-r--r--protocols/VKontakte/src/vk_chats.cpp3
-rw-r--r--protocols/VKontakte/src/vk_feed.cpp1
-rw-r--r--protocols/WhatsApp/src/chats.cpp1
-rw-r--r--src/core/stdmsg/src/msgdialog.cpp2
-rw-r--r--src/mir_app/src/chat_tools.cpp17
-rw-r--r--src/mir_app/src/mir_app.def1
-rw-r--r--src/mir_app/src/mir_app64.def1
-rw-r--r--src/mir_app/src/srmm_base.cpp3
28 files changed, 118 insertions, 250 deletions
diff --git a/include/m_chat.h b/include/m_chat.h
index 9ce9a83f4e..14b2387f6a 100644
--- a/include/m_chat.h
+++ b/include/m_chat.h
@@ -398,8 +398,6 @@ MIR_APP_DLL(int) Chat_SetStatusbarText(SESSION_INFO *si, const wchar_t *wszText)
MIR_APP_DLL(CMStringW) Chat_GetGroup(void);
MIR_APP_DLL(void) Chat_SetGroup(const wchar_t*);
-MIR_APP_DLL(wchar_t*) Chat_UnescapeTags(wchar_t *str_in);
-
/////////////////////////////////////////////////////////////////////////////////////////
#define GC_SSE_ONLYLISTED 0x0001 // processes only listed contacts, resets all contacts otherwise
diff --git a/plugins/Scriver/src/msgdialog.cpp b/plugins/Scriver/src/msgdialog.cpp
index 8d7b10a6ba..47f8893719 100644
--- a/plugins/Scriver/src/msgdialog.cpp
+++ b/plugins/Scriver/src/msgdialog.cpp
@@ -331,7 +331,6 @@ void CMsgDialog::onClick_Ok(CCtrlButton *pButton)
CMStringW ptszText(ptrW(mir_utf8decodeW(msi.sendBuffer)));
g_chatApi.DoRtfToTags(ptszText, 0, nullptr);
ptszText.Trim();
- ptszText.Replace(L"%", L"%%");
if (m_si->pMI->bAckMsg) {
EnableWindow(m_message.GetHwnd(), FALSE);
diff --git a/plugins/TabSRMM/src/msgdlgother.cpp b/plugins/TabSRMM/src/msgdlgother.cpp
index e229888c22..edab00d7c3 100644
--- a/plugins/TabSRMM/src/msgdlgother.cpp
+++ b/plugins/TabSRMM/src/msgdlgother.cpp
@@ -260,7 +260,7 @@ BOOL CMsgDialog::DoRtfToTags(CMStringW &pszText) const
}
else idx += 5;
- bool bInsideColor = false, bInsideUl = false;
+ bool bInsideUl = false;
CMStringW res;
// iterate through all characters, if rtf control character found then take action
@@ -277,34 +277,21 @@ BOOL CMsgDialog::DoRtfToTags(CMStringW &pszText) const
}
if (!wcsncmp(p, L"\\cf", 3)) { // foreground color
- int iCol = _wtoi(p + 3);
- int iInd = RtfColorToIndex(iNumColors, pIndex, iCol);
-
- if (iCol > 0) {
- if (isChat()) {
- if (iInd >= 0) {
- if (!(res.IsEmpty() && m_pContainer->m_theme.fontColors[MSGFONTID_MESSAGEAREA] == pColors[iInd]))
- res.AppendFormat(L"%%c%u", iInd);
- }
- else if (!res.IsEmpty())
- res.Append(L"%%C");
- }
- else res.AppendFormat((iInd >= 0) ? (bInsideColor ? L"[/color][color=%s]" : L"[color=%s]") : (bInsideColor ? L"[/color]" : L""), Utils::rtf_clrs[iInd].szName);
- }
-
- bInsideColor = iInd >= 0;
+ int iInd = RtfColorToIndex(iNumColors, pIndex, _wtoi(p + 3));
+ if (iInd >= 0)
+ res.AppendFormat(L"[color=%08X]", Utils::rtf_clrs[iInd].clr);
+ else if (!res.IsEmpty())
+ res.Append(L"[/color]");
}
else if (!wcsncmp(p, L"\\highlight", 10)) { // background color
- if (isChat()) {
- int iInd = RtfColorToIndex(iNumColors, pIndex, _wtoi(p + 10));
- if (iInd >= 0) {
- // if the entry field is empty & the color passed is the back color, skip it
- if (!(res.IsEmpty() && m_pContainer->m_theme.inputbg == pColors[iInd]))
- res.AppendFormat(L"%%f%u", iInd);
- }
- else if (!res.IsEmpty())
- res.AppendFormat(L"%%F");
+ int iInd = RtfColorToIndex(iNumColors, pIndex, _wtoi(p + 10));
+ if (iInd >= 0) {
+ // if the entry field is empty & the color passed is the back color, skip it
+ if (m_pContainer->m_theme.inputbg != pColors[iInd])
+ res.AppendFormat(L"[bkcolor=%08X]", Utils::rtf_clrs[iInd].clr);
}
+ else if (!res.IsEmpty())
+ res.AppendFormat(L"[/bkcolor]");
}
else if (!wcsncmp(p, L"\\line", 5)) { // soft line break;
res.AppendChar('\n');
@@ -331,20 +318,12 @@ BOOL CMsgDialog::DoRtfToTags(CMStringW &pszText) const
res.AppendChar(0x2019);
}
else if (!wcsncmp(p, L"\\b", 2)) { //bold
- if (isChat()) {
- res.Append((p[2] != '0') ? L"%b" : L"%B");
- }
- else {
- if (!(lf.lfWeight == FW_BOLD)) // only allow bold if the font itself isn't a bold one, otherwise just strip it..
- if (m_bSendFormat)
- res.Append((p[2] != '0') ? L"[b]" : L"[/b]");
- }
+ // only allow bold if the font itself isn't a bold one, otherwise just strip it..
+ if (lf.lfWeight != FW_BOLD && m_bSendFormat)
+ res.Append((p[2] != '0') ? L"[b]" : L"[/b]");
}
else if (!wcsncmp(p, L"\\i", 2)) { // italics
- if (isChat()) {
- res.Append((p[2] != '0') ? L"%i" : L"%I");
- }
- else if (!lf.lfItalic && m_bSendFormat)
+ if (!lf.lfItalic && m_bSendFormat)
res.Append((p[2] != '0') ? L"[i]" : L"[/i]");
}
else if (!wcsncmp(p, L"\\strike", 7)) { // strike-out
@@ -352,20 +331,15 @@ BOOL CMsgDialog::DoRtfToTags(CMStringW &pszText) const
res.Append((p[7] != '0') ? L"[s]" : L"[/s]");
}
else if (!wcsncmp(p, L"\\ul", 3)) { // underlined
- if (isChat()) {
- res.Append((p[3] != '0') ? L"%u" : L"%U");
- }
- else {
- if (!lf.lfUnderline && m_bSendFormat) {
- if (p[3] == 0 || wcschr(tszRtfBreaks, p[3])) {
- res.Append(L"[u]");
- bInsideUl = true;
- }
- else if (!wcsncmp(p + 3, L"none", 4)) {
- if (bInsideUl)
- res.Append(L"[/u]");
- bInsideUl = false;
- }
+ if (!lf.lfUnderline && m_bSendFormat) {
+ if (p[3] == 0 || wcschr(tszRtfBreaks, p[3])) {
+ res.Append(L"[u]");
+ bInsideUl = true;
+ }
+ else if (!wcsncmp(p + 3, L"none", 4)) {
+ if (bInsideUl)
+ res.Append(L"[/u]");
+ bInsideUl = false;
}
}
}
@@ -402,22 +376,12 @@ BOOL CMsgDialog::DoRtfToTags(CMStringW &pszText) const
p++;
break;
- case '%': // double % for stupid chat engine
- if (isChat())
- res.Append(L"%%");
- else
- res.AppendChar(*p);
- p++;
- break;
-
default: // other text that should not be touched
res.AppendChar(*p++);
break;
}
}
- if (bInsideColor && !isChat())
- res.Append(L"[/color]");
if (bInsideUl)
res.Append(L"[/u]");
diff --git a/protocols/Discord/src/groupchat.cpp b/protocols/Discord/src/groupchat.cpp
index 60d9a52329..b9376e1404 100644
--- a/protocols/Discord/src/groupchat.cpp
+++ b/protocols/Discord/src/groupchat.cpp
@@ -370,7 +370,6 @@ int CDiscordProto::GroupchatEventHook(WPARAM, LPARAM lParam)
}
}
- Chat_UnescapeTags(wszText.GetBuffer());
SendMsg(si->hContact, (si->pDlg) ? si->pDlg->m_hQuoteEvent : 0, T2Utf(wszText));
}
break;
diff --git a/protocols/Facebook/src/groupchats.cpp b/protocols/Facebook/src/groupchats.cpp
index adf0ab06b5..b185026215 100644
--- a/protocols/Facebook/src/groupchats.cpp
+++ b/protocols/Facebook/src/groupchats.cpp
@@ -161,15 +161,12 @@ int FacebookProto::GroupchatEventHook(WPARAM, LPARAM lParam)
break;
if (m_bOnline) {
- wchar_t *wszText = NEWWSTR_ALLOCA(gch->ptszText);
- Chat_UnescapeTags(wszText);
-
- int mid = SendMsg(si->hContact, 0, T2Utf(wszText));
+ int mid = SendMsg(si->hContact, 0, T2Utf(gch->ptszText));
mir_cslock lck(m_csOwnMessages);
for (auto &msg : arOwnMessages)
if (msg->reqId == mid)
- msg->wszText = wszText;
+ msg->wszText = gch->ptszText;
}
break;
diff --git a/protocols/Facebook/src/server.cpp b/protocols/Facebook/src/server.cpp
index b45e644ce7..4a22f18132 100644
--- a/protocols/Facebook/src/server.cpp
+++ b/protocols/Facebook/src/server.cpp
@@ -969,7 +969,6 @@ bool FacebookProto::CheckOwnMessage(FacebookUser *pUser, __int64 offlineId, cons
if (pUser->bIsChat) {
CMStringW wszId(FORMAT, L"%lld", m_uid);
- tmp.wszText.Replace(L"%", L"%%");
wchar_t userId[100];
_i64tow_s(pUser->id, userId, _countof(userId), 10);
diff --git a/protocols/IRCG/src/channelList.cpp b/protocols/IRCG/src/channelList.cpp
index c2de0eaa10..3669b9e942 100644
--- a/protocols/IRCG/src/channelList.cpp
+++ b/protocols/IRCG/src/channelList.cpp
@@ -293,8 +293,9 @@ public:
wszTopic.Delete(0, iEnd);
}
+ wszTopic = DoColorCodes(wszTopic);
lvItem.iSubItem = 3;
- lvItem.pszText = DoColorCodes(wszTopic, TRUE, FALSE);
+ lvItem.pszText = wszTopic.GetBuffer();
m_list.SetItem(&lvItem);
int percent = 100;
diff --git a/protocols/IRCG/src/commandmonitor.cpp b/protocols/IRCG/src/commandmonitor.cpp
index 28350171b2..4daf29d855 100644
--- a/protocols/IRCG/src/commandmonitor.cpp
+++ b/protocols/IRCG/src/commandmonitor.cpp
@@ -221,7 +221,7 @@ int CIrcProto::AddOutgoingMessageToDB(MCONTACT hContact, const wchar_t *msg)
if (m_iStatus == ID_STATUS_OFFLINE || m_iStatus == ID_STATUS_CONNECTING)
return 0;
- CMStringW S = DoColorCodes(msg, TRUE, FALSE);
+ CMStringW S = DoColorCodes(msg);
DBEVENTINFO dbei = {};
dbei.szModule = m_szModuleName;
@@ -682,7 +682,7 @@ bool CIrcProto::OnIrc_PRIVMSG(const CIrcMessage *pmsg)
bool bIsChannel = IsChannel(pmsg->parameters[0]);
if (pmsg->m_bIncoming && !bIsChannel) {
- mess = DoColorCodes(mess, TRUE, FALSE);
+ mess = DoColorCodes(mess);
CONTACT user = { pmsg->prefix.sNick, pmsg->prefix.sUser, pmsg->prefix.sHost, false, false, false };
@@ -772,8 +772,6 @@ bool CIrcProto::IsCTCP(const CIrcMessage *pmsg)
if (IsChannel(pmsg->parameters[0])) {
if (mess.GetLength() > 1) {
mess.Delete(0, 1);
- if (!pmsg->m_bIncoming)
- mess.Replace(L"%%", L"%");
DoEvent(GC_EVENT_ACTION, pmsg->parameters[0], pmsg->m_bIncoming ? pmsg->prefix.sNick : m_info.sNick, mess, nullptr, nullptr, NULL, true, pmsg->m_bIncoming ? false : true);
}
@@ -1173,7 +1171,7 @@ bool CIrcProto::IsCTCP(const CIrcMessage *pmsg)
CONTACT user = { pmsg->prefix.sNick, pmsg->prefix.sUser, pmsg->prefix.sHost, false, false, false };
MCONTACT hContact = CList_FindContact(&user);
if (hContact)
- setWString(hContact, "MirVer", DoColorCodes(GetWordAddress(mess, 1), TRUE, FALSE));
+ setWString(hContact, "MirVer", DoColorCodes(GetWordAddress(mess, 1)));
}
// if the whois window is visible and the ctcp reply belongs to the user in it, then show the reply in the whois window
@@ -1182,7 +1180,7 @@ bool CIrcProto::IsCTCP(const CIrcMessage *pmsg)
if (mir_wstrcmpi(szTemp, pmsg->prefix.sNick) == 0) {
if (pmsg->m_bIncoming && (command == L"version" || command == L"userinfo" || command == L"time")) {
SetActiveWindow(m_whoisDlg->GetHwnd());
- m_whoisDlg->m_Reply.SetText(DoColorCodes(GetWordAddress(mess, 1), TRUE, FALSE));
+ m_whoisDlg->m_Reply.SetText(DoColorCodes(GetWordAddress(mess, 1)));
return true;
}
if (pmsg->m_bIncoming && command == L"ping") {
@@ -1194,7 +1192,7 @@ bool CIrcProto::IsCTCP(const CIrcMessage *pmsg)
else
mir_snwprintf(szTmp, TranslateT("%u seconds"), s);
- m_whoisDlg->m_Reply.SetText(DoColorCodes(szTmp, TRUE, FALSE));
+ m_whoisDlg->m_Reply.SetText(DoColorCodes(szTmp));
return true;
}
}
@@ -1742,7 +1740,7 @@ bool CIrcProto::OnIrc_ERROR(const CIrcMessage *pmsg)
if (pmsg->m_bIncoming && !m_disableErrorPopups && m_iDesiredStatus != ID_STATUS_OFFLINE) {
CMStringW S;
if (pmsg->parameters.getCount() > 0)
- S = DoColorCodes(pmsg->parameters[0], TRUE, FALSE);
+ S = DoColorCodes(pmsg->parameters[0]);
else
S = TranslateT("Unknown");
Clist_TrayNotifyW(m_szModuleName, TranslateT("IRC error"), S, NIIF_ERROR, 15000);
diff --git a/protocols/IRCG/src/input.cpp b/protocols/IRCG/src/input.cpp
index 4245d8764f..1030a67043 100644
--- a/protocols/IRCG/src/input.cpp
+++ b/protocols/IRCG/src/input.cpp
@@ -490,7 +490,6 @@ BOOL CIrcProto::DoHardcodedCommand(CMStringW text, wchar_t *window, MCONTACT hCo
return true;
CMStringW S = L"/ME " + DoIdentifiers(GetWordAddress(text, 1), window);
- S.Replace(L"%", L"%%");
Chat_SendUserMessage(m_szModuleName, S);
return true;
}
@@ -500,7 +499,6 @@ BOOL CIrcProto::DoHardcodedCommand(CMStringW text, wchar_t *window, MCONTACT hCo
return true;
CMStringW S = DoIdentifiers(GetWordAddress(text, 1), window);
- S.Replace(L"%", L"%%");
Chat_SendUserMessage(m_szModuleName, S);
return true;
}
diff --git a/protocols/IRCG/src/ircproto.cpp b/protocols/IRCG/src/ircproto.cpp
index 8d8c4bd23f..05a2001da9 100644
--- a/protocols/IRCG/src/ircproto.cpp
+++ b/protocols/IRCG/src/ircproto.cpp
@@ -516,7 +516,6 @@ HANDLE CIrcProto::SendFile(MCONTACT hContact, const wchar_t*, wchar_t** ppszFile
// need to make sure that %'s are doubled to avoid having chat interpret as color codes
CMStringW sFileCorrect = dci->sFile;
- sFileCorrect.Replace(L"%", L"%%");
// is it an reverse filetransfer (receiver acts as server)
if (dci->bReverse) {
diff --git a/protocols/IRCG/src/output.cpp b/protocols/IRCG/src/output.cpp
index be429f5571..0c43081131 100644
--- a/protocols/IRCG/src/output.cpp
+++ b/protocols/IRCG/src/output.cpp
@@ -109,9 +109,6 @@ BOOL CIrcProto::ShowMessage(const CIrcMessage* pmsg)
{
CMStringW mess = FormatOutput(pmsg);
- if (!pmsg->m_bIncoming)
- mess.Replace(L"%%", L"%");
-
int iTemp = _wtoi(pmsg->sCommand);
//To active window
diff --git a/protocols/IRCG/src/services.cpp b/protocols/IRCG/src/services.cpp
index 2fccbe141d..ab45a31c83 100644
--- a/protocols/IRCG/src/services.cpp
+++ b/protocols/IRCG/src/services.cpp
@@ -352,76 +352,64 @@ static wchar_t* DoPrintColor(wchar_t *pDest, int iFG, int iBG)
return pDest;
}
+/////////////////////////////////////////////////////////////////////////////////////////
+
static void DoChatFormatting(CMStringW &wszText)
{
int iFG = -1, iBG = -1;
wchar_t InsertThis[50];
+ CMStringW tmp;
- for (int i = 0; i < wszText.GetLength(); i++) {
- if (wszText[i] != '%')
+ for (const wchar_t *p = wszText; *p; p++) {
+ if (*p != '[') {
+ tmp.AppendChar(*p);
continue;
+ }
- switch (wszText[i + 1]) {
- case 'B':
- case 'b':
- wszText.Delete(i, 2);
- wszText.Insert(i, irc::BOLD);
- break;
- case 'I':
- case 'i':
- wszText.Delete(i, 2);
- wszText.Insert(i, irc::ITALICS);
- break;
- case 'U':
- case 'u':
- wszText.Delete(i, 2);
- wszText.Insert(i, irc::UNDERLINE);
- break;
-
- case 'c':
- wszText.Delete(i, 2);
- iFG = _wtoi(wszText.GetString() + i);
- wszText.Delete(i, (iFG < 10) ? 1 : 2);
-
- iFG = (iFG < 0 || iFG >= _countof(mapSrmm2irc)) ? -1 : mapSrmm2irc[iFG];
- wszText.Insert(i, DoPrintColor(InsertThis, iFG, iBG));
- break;
+ p++;
+ bool bEnable = true;
+ if (*p == '/') {
+ p++;
+ bEnable = false;
+ }
- case 'C':
- if (wszText[i + 2] == '%' && wszText[i + 3] == 'F') {
- wszText.Delete(i, 4);
- iBG = -1;
- }
- else wszText.Delete(i, 2);
+ if (!wcsncmp(p, L"b]", 2)) {
+ tmp.AppendChar(irc::BOLD);
+ p++;
+ }
+ else if (!wcsncmp(p, L"i]", 2)) {
+ tmp.AppendChar(irc::ITALICS);
+ p++;
+ }
+ else if (!wcsncmp(p, L"u]", 2)) {
+ tmp.AppendChar(irc::UNDERLINE);
+ p++;
+ }
+ else if (!wcsncmp(p, L"color=", 6)) {
+ if (1 != swscanf(p + 6, L"%08X", &iFG))
+ iFG = -1;
+ tmp.Append(DoPrintColor(InsertThis, iFG, iBG));
+ p = wcschr(p, ']');
+ }
+ else if (!wcsncmp(p, L"color]", 6) && !bEnable) {
iFG = -1;
- wszText.Insert(i, DoPrintColor(InsertThis, iFG, iBG));
- break;
-
- case 'f':
- wszText.Delete(i, 2);
- iBG = _wtoi(wszText.GetString() + i);
- wszText.Delete(i, (iBG < 10) ? 1 : 2);
-
- iBG = (iBG < 0 || iBG >= _countof(mapSrmm2irc)) ? -1 : mapSrmm2irc[iBG];
- wszText.Insert(i, DoPrintColor(InsertThis, iFG, iBG));
- break;
-
- case 'F':
- wszText.Delete(i, 2);
+ tmp.Append(DoPrintColor(InsertThis, iFG, iBG));
+ p += 6;
+ }
+ else if (!wcsncmp(p, L"bkcolor=", 8)) {
+ if (1 != swscanf(p + 6, L"%08X", &iBG))
+ iBG = -1;
+ tmp.Append(DoPrintColor(InsertThis, iFG, iBG));
+ p = wcschr(p, ']');
+ }
+ else if (!wcsncmp(p, L"bkcolor]", 8) && !bEnable) {
iBG = -1;
- wszText.Insert(i, DoPrintColor(InsertThis, iFG, iBG));
- break;
-
- case '%':
- wszText.Delete(i, 1);
- i++;
- break;
-
- default:
- wszText.Delete(i, 2);
- break;
+ tmp.Append(DoPrintColor(InsertThis, iFG, iBG));
+ p += 8;
}
+ else tmp.AppendChar('['); // sometimes a banana is just a banana
}
+ wszText = tmp;
}
int __cdecl CIrcProto::GCEventHook(WPARAM, LPARAM lParam)
diff --git a/protocols/IRCG/src/stdafx.h b/protocols/IRCG/src/stdafx.h
index f83906cfcd..04751ac5eb 100644
--- a/protocols/IRCG/src/stdafx.h
+++ b/protocols/IRCG/src/stdafx.h
@@ -207,14 +207,14 @@ void UninitContactMenus(void);
void InitIcons(void);
// tools.cpp
-int __stdcall WCCmp(const wchar_t* wild, const wchar_t* string);
-char* __stdcall IrcLoadFile(wchar_t * szPath);
-CMStringW __stdcall GetWord(const wchar_t* text, int index);
-const wchar_t* __stdcall GetWordAddress(const wchar_t* text, int index);
-void __stdcall RemoveLinebreaks(CMStringW& Message);
-wchar_t* __stdcall DoColorCodes(const wchar_t* text, bool bStrip, bool bReplacePercent);
-
-CMStringA __stdcall GetWord(const char* text, int index);
+int WCCmp(const wchar_t* wild, const wchar_t* string);
+char* IrcLoadFile(wchar_t * szPath);
+CMStringW GetWord(const wchar_t* text, int index);
+const wchar_t* GetWordAddress(const wchar_t* text, int index);
+void RemoveLinebreaks(CMStringW& Message);
+CMStringW DoColorCodes(const wchar_t* text, bool bStrip = true);
+
+CMStringA GetWord(const char* text, int index);
__forceinline const wchar_t* s2null(const CMStringW &str)
{
diff --git a/protocols/IRCG/src/tools.cpp b/protocols/IRCG/src/tools.cpp
index f32a001092..6e71adfc53 100644
--- a/protocols/IRCG/src/tools.cpp
+++ b/protocols/IRCG/src/tools.cpp
@@ -274,60 +274,43 @@ static const wchar_t* DoEnterNumber(const wchar_t *text, int &res)
return text;
}
-wchar_t* __stdcall DoColorCodes(const wchar_t *text, bool bStrip, bool bReplacePercent)
+CMStringW DoColorCodes(const wchar_t *text, bool bStrip)
{
- static wchar_t szTemp[4000]; szTemp[0] = 0;
- wchar_t* p = szTemp;
+ CMStringW ret;
bool bBold = false;
bool bUnderline = false;
bool bItalics = false;
- int iFG = -1, iBG = -1;
-
+ int iFG = -1, iBG = -1, numColors = 0;
+ COLORREF *pClrTable = Srmm_GetColorTable(&numColors);
+
if (!text)
- return szTemp;
+ return ret;
while (*text != 0) {
switch (*text) {
- case '%': // escape
- *p++ = '%';
- if (bReplacePercent)
- *p++ = '%';
- text++;
- break;
-
case irc::BOLD:
- if (!bStrip) {
- *p++ = '%';
- *p++ = bBold ? 'B' : 'b';
- }
bBold = !bBold;
+ if (!bStrip)
+ ret.Append(bBold ? L"[b]" : L"[/b]");
text++;
break;
case irc::RESET:
- if (!bStrip) {
- *p++ = '%';
- *p++ = 'r';
- }
bUnderline = bItalics = bBold = false;
text++;
break;
case irc::ITALICS:
- if (!bStrip) {
- *p++ = '%';
- *p++ = bItalics ? 'I' : 'i';
- }
bItalics = !bItalics;
+ if (!bStrip)
+ ret.Append(bItalics ? L"[i]" : L"[/i]");
text++;
break;
case irc::UNDERLINE:
- if (!bStrip) {
- *p++ = '%';
- *p++ = bUnderline ? 'U' : 'u';
- }
bUnderline = !bUnderline;
+ if (!bStrip)
+ ret.Append(bUnderline ? L"[u]" : L"[/u]");
text++;
break;
@@ -343,41 +326,29 @@ wchar_t* __stdcall DoColorCodes(const wchar_t *text, bool bStrip, bool bReplaceP
// create tag for chat.dll
if (!bStrip) {
- wchar_t buf[10];
if (iFG != iOldFG) {
- *p++ = '%';
if (iFG == -1)
- *p++ = 'C';
- else {
- *p++ = 'c';
- mir_snwprintf(buf, L"%02u", iFG);
- *p++ = buf[0];
- *p++ = buf[1];
- }
+ ret.Append(L"[/color]");
+ else if (iFG < numColors)
+ ret.Append(L"[color=%08X]", pClrTable[iFG]);
}
if (iBG != iOldBG) {
- *p++ = '%';
- if (iBG == -1)
- *p++ = 'F';
- else {
- *p++ = 'f';
- mir_snwprintf(buf, L"%02u", iBG);
- *p++ = buf[0];
- *p++ = buf[1];
- }
+ if (iFG == -1)
+ ret.Append(L"[/bkcolor]");
+ else if (iFG < numColors)
+ ret.Append(L"[bkcolor=%08X]", pClrTable[iFG]);
}
}
break;
default:
- *p++ = *text++;
+ ret.AppendChar(*text++);
break;
}
}
- *p = 0;
- return szTemp;
+ return ret;
}
INT_PTR CIrcProto::DoEvent(int iEvent, const wchar_t *pszWindow, const wchar_t *pszNick,
@@ -389,7 +360,7 @@ INT_PTR CIrcProto::DoEvent(int iEvent, const wchar_t *pszWindow, const wchar_t *
CMStringW sText;
if (pszText)
- sText = DoColorCodes(pszText, FALSE, TRUE);
+ sText = DoColorCodes(pszText, false);
GCEVENT gce = {};
if (pszWindow)
@@ -537,7 +508,7 @@ int CIrcProto::SetChannelSBText(CMStringW sWindow, CHANNELINFO *wi)
}
if (wi->pszTopic)
sTemp += wi->pszTopic;
- sTemp = DoColorCodes(sTemp, TRUE, FALSE);
+ sTemp = DoColorCodes(sTemp);
Chat_SetStatusbarText(Chat_Find(sWindow, m_szModuleName), sTemp);
return 0;
}
diff --git a/protocols/JabberG/src/jabber_chat.cpp b/protocols/JabberG/src/jabber_chat.cpp
index 622cad1869..b68edc5c81 100644
--- a/protocols/JabberG/src/jabber_chat.cpp
+++ b/protocols/JabberG/src/jabber_chat.cpp
@@ -224,8 +224,6 @@ void CJabberProto::GcLogShowInformation(JABBER_LIST_ITEM *item, pResourceStatus
}
if (!buf.IsEmpty()) {
- buf.Replace("%", "%%");
-
GCEVENT gce = { item->si, GC_EVENT_INFORMATION };
gce.dwFlags = GCEF_UTF8 + GCEF_ADDTOLOG;
gce.pszNick.a = gce.pszUID.a = user->m_szResourceName;
@@ -966,7 +964,6 @@ static void sttNickListHook(CJabberProto *ppro, JABBER_LIST_ITEM *item, GCHOOK*
buf.Format("%s%s%s", szMessage.get(), him->m_szResourceName.get(), p + 2);
}
else buf = szMessage;
- buf.Replace("%%", "%");
ppro->m_ThreadInfo->send(
XmlNode("message") << XATTR("to", item->jid) << XATTR("type", "groupchat")
@@ -1345,7 +1342,6 @@ int CJabberProto::JabberGcEventHook(WPARAM, LPARAM lParam)
case GC_USER_MESSAGE:
if (gch->ptszText && mir_wstrlen(gch->ptszText) > 0) {
rtrimw(gch->ptszText);
- Chat_UnescapeTags(gch->ptszText);
SendMsg(item->hContact, 0, T2Utf(gch->ptszText));
}
break;
diff --git a/protocols/JabberG/src/jabber_groupchat.cpp b/protocols/JabberG/src/jabber_groupchat.cpp
index 9f8343379f..47ee405834 100644
--- a/protocols/JabberG/src/jabber_groupchat.cpp
+++ b/protocols/JabberG/src/jabber_groupchat.cpp
@@ -1059,7 +1059,6 @@ void CJabberProto::GroupchatProcessMessage(const TiXmlElement *node)
else nick = nullptr;
CMStringA szText(msgText);
- szText.Replace("%", "%%");
szText += imgLink;
gce.dwFlags = GCEF_UTF8;
diff --git a/protocols/MinecraftDynmap/src/chat.cpp b/protocols/MinecraftDynmap/src/chat.cpp
index f0c3122634..ef3943e2c8 100644
--- a/protocols/MinecraftDynmap/src/chat.cpp
+++ b/protocols/MinecraftDynmap/src/chat.cpp
@@ -24,13 +24,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
void MinecraftDynmapProto::UpdateChat(const char *name, const char *message, const time_t timestamp, bool addtolog)
{
// replace % to %% to not interfere with chat color codes
- CMStringA szMessage(message);
- szMessage.Replace("%", "%%");
-
GCEVENT gce = {m_si, GC_EVENT_MESSAGE };
gce.dwFlags = GCEF_UTF8;
gce.time = timestamp;
- gce.pszText.a = szMessage.c_str();
+ gce.pszText.a = message;
if (name == NULL) {
gce.iType = GC_EVENT_INFORMATION;
@@ -56,7 +53,6 @@ int MinecraftDynmapProto::OnChatEvent(WPARAM, LPARAM lParam)
case GC_USER_MESSAGE:
{
CMStringA szText(ptrA(mir_utf8encodeW(hook->ptszText)));
- szText.Replace("%%", "%");
if (szText.IsEmpty())
break;
diff --git a/protocols/SkypeWeb/src/skype_chatrooms.cpp b/protocols/SkypeWeb/src/skype_chatrooms.cpp
index 4df199e3f0..0a64587ece 100644
--- a/protocols/SkypeWeb/src/skype_chatrooms.cpp
+++ b/protocols/SkypeWeb/src/skype_chatrooms.cpp
@@ -328,12 +328,9 @@ void CSkypeProto::SendChatMessage(SESSION_INFO *si, const wchar_t *tszMessage)
if (!IsOnline())
return;
- wchar_t *buf = NEWWSTR_ALLOCA(tszMessage);
- rtrimw(buf);
- Chat_UnescapeTags(buf);
-
T2Utf chat_id(si->ptszID);
- ptrA szMessage(mir_utf8encodeW(buf));
+ ptrA szMessage(mir_utf8encodeW(tszMessage));
+ rtrim(szMessage);
if (strncmp(szMessage, "/me ", 4) == 0)
PushRequest(new SendChatActionRequest(chat_id, time(0), szMessage));
diff --git a/protocols/Telegram/src/groupchat.cpp b/protocols/Telegram/src/groupchat.cpp
index fddb95809b..a591e1ae80 100644
--- a/protocols/Telegram/src/groupchat.cpp
+++ b/protocols/Telegram/src/groupchat.cpp
@@ -203,7 +203,6 @@ int CTelegramProto::GcEventHook(WPARAM, LPARAM lParam)
case GC_USER_MESSAGE:
if (gch->ptszText && mir_wstrlen(gch->ptszText) > 0) {
rtrimw(gch->ptszText);
- Chat_UnescapeTags(gch->ptszText);
if (auto *pUser = FindUser(userId)) {
TD::int53 replyId = 0;
if (auto *pDlg = gch->si->pDlg) {
diff --git a/protocols/Twitter/src/chat.cpp b/protocols/Twitter/src/chat.cpp
index 6f463c7f20..83ca3ffbd2 100644
--- a/protocols/Twitter/src/chat.cpp
+++ b/protocols/Twitter/src/chat.cpp
@@ -24,7 +24,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
void CTwitterProto::UpdateChat(const twitter_user &update)
{
CMStringA chatText = update.status.text.c_str();
- chatText.Replace("%", "%%");
GCEVENT gce = { m_si, GC_EVENT_MESSAGE };
gce.dwFlags = GCEF_UTF8 + GCEF_ADDTOLOG;
@@ -54,7 +53,6 @@ int CTwitterProto::OnChatOutgoing(WPARAM, LPARAM lParam)
debugLogW(L"**Chat - Outgoing message: %s", hook->ptszText);
{
CMStringA tweet(T2Utf(hook->ptszText).get());
- tweet.Replace("%%", "%"); // the chat plugin will turn "%" into "%%", so we have to change it back :/
char *varTweet = mir_strdup(tweet.c_str());
ForkThread(&CTwitterProto::SendTweetWorker, varTweet);
diff --git a/protocols/VKontakte/src/vk_chats.cpp b/protocols/VKontakte/src/vk_chats.cpp
index 709465dda5..68ada0350f 100644
--- a/protocols/VKontakte/src/vk_chats.cpp
+++ b/protocols/VKontakte/src/vk_chats.cpp
@@ -521,8 +521,6 @@ void CVkProto::AppendChatConversationMessage(VKUserID_t iChatId, const JSONNode&
wszBody.AppendFormat(L": %s (%s)", TranslateT("chat action not supported"), wszAction.c_str());
}
- wszBody.Replace(L"%", L"%%");
-
if (vkChatInfo->m_bHistoryRead) {
AppendChatMessage(vkChatInfo, iMessageId, iReplyMsgId, iUserId, tMsgTime, wszBody, bIsHistory, bIsAction);
}
@@ -657,7 +655,6 @@ int CVkProto::OnChatEvent(WPARAM, LPARAM lParam)
if (IsOnline() && mir_wstrlen(gch->ptszText) > 0) {
ptrW pwszBuf(mir_wstrdup(gch->ptszText));
rtrimw(pwszBuf);
- Chat_UnescapeTags(pwszBuf);
SendMsg(cc->m_si->hContact, gch->si->pDlg ? gch->si->pDlg->m_hQuoteEvent : 0, T2Utf(pwszBuf));
}
break;
diff --git a/protocols/VKontakte/src/vk_feed.cpp b/protocols/VKontakte/src/vk_feed.cpp
index c45519c54b..f1646c6a78 100644
--- a/protocols/VKontakte/src/vk_feed.cpp
+++ b/protocols/VKontakte/src/vk_feed.cpp
@@ -315,7 +315,6 @@ CMStringW CVkProto::GetVkFeedback(const JSONNode &jnFeedback, VKObjType vkFeedba
if (iUserId) {
vkUser = GetVkUserInfo(iUserId, vkUsers);
CMStringW wszText(jnFeedback["text"].as_mstring());
- wszText.Replace(L"%", L"%%");
wszRes.AppendFormat(wszFormat, SetBBCString(vkUser->m_wszUserNick, m_vkOptions.BBCForNews(), vkbbcUrl, vkUser->m_wszLink).c_str(), ClearFormatNick(wszText).c_str());
}
diff --git a/protocols/WhatsApp/src/chats.cpp b/protocols/WhatsApp/src/chats.cpp
index 031fbaf677..16d8be872d 100644
--- a/protocols/WhatsApp/src/chats.cpp
+++ b/protocols/WhatsApp/src/chats.cpp
@@ -144,7 +144,6 @@ int WhatsAppProto::GcEventHook(WPARAM, LPARAM lParam)
case GC_USER_MESSAGE:
if (gch->ptszText && mir_wstrlen(gch->ptszText) > 0) {
rtrimw(gch->ptszText);
- Chat_UnescapeTags(gch->ptszText);
SendTextMessage(pUser->szId, T2Utf(gch->ptszText));
}
break;
diff --git a/src/core/stdmsg/src/msgdialog.cpp b/src/core/stdmsg/src/msgdialog.cpp
index 3b42a20913..eedfacbb33 100644
--- a/src/core/stdmsg/src/msgdialog.cpp
+++ b/src/core/stdmsg/src/msgdialog.cpp
@@ -325,8 +325,6 @@ void CMsgDialog::onClick_Ok(CCtrlButton *pButton)
m_cmdList.insert(mir_wstrdup(ptszText));
m_cmdListInd = -1;
- ptszText.Replace(L"%", L"%%");
-
if (m_si->pMI->bAckMsg) {
m_message.Disable();
m_message.SendMsg(EM_SETREADONLY, TRUE, 0);
diff --git a/src/mir_app/src/chat_tools.cpp b/src/mir_app/src/chat_tools.cpp
index 66e8acbc6b..dd0c7d9895 100644
--- a/src/mir_app/src/chat_tools.cpp
+++ b/src/mir_app/src/chat_tools.cpp
@@ -734,8 +734,7 @@ void Chat_EventToGC(SESSION_INFO *si, MEVENT hDbEvent)
if (mir_strcmp(szProto, dbei.szModule) || !g_chatApi.DbEventIsShown(dbei) || !dbei.szUserId)
return;
- CMStringW wszText(ptrW(dbei.getText()));
- wszText.Replace(L"%", L"%%");
+ ptrW wszText(dbei.getText());
GCEVENT gce = { si, GC_EVENT_MESSAGE };
gce.dwFlags = GCEF_ADDTOLOG;
@@ -772,20 +771,6 @@ MIR_APP_DLL(void) Chat_SetGroup(const wchar_t *pwszGroupName)
/////////////////////////////////////////////////////////////////////////////////////////
-MIR_APP_DLL(wchar_t*) Chat_UnescapeTags(wchar_t *str_in)
-{
- wchar_t *s = str_in, *d = str_in;
- while (*s) {
- if (*s == '%' && s[1] == '%')
- s++;
- *d++ = *s++;
- }
- *d = 0;
- return str_in;
-}
-
-/////////////////////////////////////////////////////////////////////////////////////////
-
MIR_APP_DLL(void) Chat_AddMenuItems(HMENU hMenu, int nItems, const gc_item *Item, HPLUGIN pPlugin)
{
if (nItems > 0)
diff --git a/src/mir_app/src/mir_app.def b/src/mir_app/src/mir_app.def
index a719418dc2..08e527e0fa 100644
--- a/src/mir_app/src/mir_app.def
+++ b/src/mir_app/src/mir_app.def
@@ -291,7 +291,6 @@ Netlib_NtlmCreateResponse @383
?get_uin@AUTH_BLOB@DB@@QBEIXZ @396 NONAME
?makeBlob@AUTH_BLOB@DB@@AAEPADXZ @1046 NONAME
?size@AUTH_BLOB@DB@@QBEIXZ @398 NONAME
-Chat_UnescapeTags @399 NONAME
ProtoGetAvatarFormatByMimeType @400
ProtoGetAvatarMimeType @401
?set_uin@AUTH_BLOB@DB@@QAEXI@Z @402 NONAME
diff --git a/src/mir_app/src/mir_app64.def b/src/mir_app/src/mir_app64.def
index 75f5b0c3b2..c4850e24ff 100644
--- a/src/mir_app/src/mir_app64.def
+++ b/src/mir_app/src/mir_app64.def
@@ -291,7 +291,6 @@ Netlib_NtlmCreateResponse @383
?get_uin@AUTH_BLOB@DB@@QEBAIXZ @396 NONAME
?makeBlob@AUTH_BLOB@DB@@AEAAPEADXZ @397 NONAME
?size@AUTH_BLOB@DB@@QEBAIXZ @398 NONAME
-Chat_UnescapeTags @399 NONAME
ProtoGetAvatarFormatByMimeType @400
ProtoGetAvatarMimeType @401
?set_uin@AUTH_BLOB@DB@@QEAAXI@Z @402 NONAME
diff --git a/src/mir_app/src/srmm_base.cpp b/src/mir_app/src/srmm_base.cpp
index 0317da383b..ebac38fdb4 100644
--- a/src/mir_app/src/srmm_base.cpp
+++ b/src/mir_app/src/srmm_base.cpp
@@ -743,8 +743,7 @@ void CSrmmBaseDialog::UpdateChatLog()
DB::EventInfo dbei(hDbEvent);
if (dbei && !mir_strcmp(szProto, dbei.szModule) && g_chatApi.DbEventIsShown(dbei) && dbei.szUserId) {
Utf2T wszUserId(dbei.szUserId);
- CMStringW wszText(ptrW(dbei.getText()));
- wszText.Replace(L"%", L"%%");
+ ptrW wszText(dbei.getText());
GCEVENT gce = { m_si, GC_EVENT_MESSAGE };
gce.dwFlags = GCEF_ADDTOLOG;