From 0cc825103d88bc5b9033e2b4865c40b9e9d53383 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Fri, 18 Aug 2023 14:45:06 +0300 Subject: =?UTF-8?q?fixes=20#3645=20(NewStory:=20=D0=BD=D0=B5=20=D0=BA?= =?UTF-8?q?=D0=BE=D0=BF=D0=B8=D1=80=D0=BE=D0=B2=D0=B0=D1=82=D1=8C=20=D1=82?= =?UTF-8?q?=D0=B5=D0=B3=D0=B8=20=D0=BF=D1=80=D0=B8=20=D0=BA=D0=BE=D0=BF?= =?UTF-8?q?=D0=B8=D1=80=D0=BE=D0=B2=D0=B0=D0=BD=D0=B8=D0=B8=20=D1=82=D0=B5?= =?UTF-8?q?=D0=BA=D1=81=D1=82=D0=B0)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/NewStory/src/history_control.cpp | 6 +++- plugins/NewStory/src/utils.cpp | 59 ++++++++++++++++++++++++++++++++ plugins/NewStory/src/utils.h | 2 ++ 3 files changed, 66 insertions(+), 1 deletion(-) (limited to 'plugins/NewStory') diff --git a/plugins/NewStory/src/history_control.cpp b/plugins/NewStory/src/history_control.cpp index 689ac81d71..f0fa9b24c2 100644 --- a/plugins/NewStory/src/history_control.cpp +++ b/plugins/NewStory/src/history_control.cpp @@ -770,7 +770,11 @@ LRESULT CALLBACK NewstoryListWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM res.Append(_A2T(blob.getUrl())); res.Append(L"\r\n"); } - else res.Append(ptrW(TplFormatString(p->getCopyTemplate(), p->hContact, p))); + else { + ptrW wszText(TplFormatString(p->getCopyTemplate(), p->hContact, p)); + RemoveBbcodes(wszText); + res.Append(wszText); + } } Utils_ClipboardCopy(res); diff --git a/plugins/NewStory/src/utils.cpp b/plugins/NewStory/src/utils.cpp index d1bf1e82a7..438246cf43 100644 --- a/plugins/NewStory/src/utils.cpp +++ b/plugins/NewStory/src/utils.cpp @@ -17,3 +17,62 @@ bool CheckFilter(wchar_t *buf, wchar_t *filter) return true; return false; } + +///////////////////////////////////////////////////////////////////////////////////////// + +struct +{ + wchar_t *pStart, *pEnd; + size_t cbStart, cbEnd; +} +static bbcodes[] = +{ + { L"[b]", nullptr }, + { L"[/b]", nullptr }, + { L"[i]", nullptr }, + { L"[/i]", nullptr }, + { L"[u]", nullptr }, + { L"[/u]", nullptr }, + { L"[s]", nullptr }, + { L"[/s]", nullptr }, + + { L"[color=", L"]" }, + { L"[/color]", nullptr }, + + { L"[$hicon=", L"$]" }, + + { L"[url]", L"[/url]" }, + { L"[url=", L"]", }, + { L"[img]", L"[/img]" }, + { L"[img=", L"]" }, +}; + +void RemoveBbcodes(wchar_t *pwszText) +{ + if (!pwszText) + return; + + if (bbcodes[0].cbStart == 0) + for (auto &it : bbcodes) { + it.cbStart = wcslen(it.pStart); + if (it.pEnd) + it.cbEnd = wcslen(it.pEnd); + } + + for (auto *p = wcschr(pwszText, '['); p != 0; p = wcschr(p, '[')) { + for (auto &it : bbcodes) { + if (wcsncmp(p, it.pStart, it.cbStart)) + continue; + + strdelw(p, it.cbStart); + + if (it.pEnd) + if (auto *pp = wcsstr(p, it.pEnd)) { + strdelw(p, size_t(pp - p)); + strdelw(p, it.cbEnd); + } + + break; + } + } +} diff --git a/plugins/NewStory/src/utils.h b/plugins/NewStory/src/utils.h index 07dd85da44..9e9c74b55b 100644 --- a/plugins/NewStory/src/utils.h +++ b/plugins/NewStory/src/utils.h @@ -3,3 +3,5 @@ bool CheckFilter(wchar_t *buf, wchar_t *filter); HMENU NSMenu_Build(struct ItemData *item); bool NSMenu_Process(int iCommand, struct NewstoryListData *data); + +void RemoveBbcodes(wchar_t *pwszText); -- cgit v1.2.3