summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2023-08-18 14:45:06 +0300
committerGeorge Hazan <george.hazan@gmail.com>2023-08-18 14:45:06 +0300
commit0cc825103d88bc5b9033e2b4865c40b9e9d53383 (patch)
tree30c91964404c7a3ed923959b8531bf8c29f6cae7
parentd92bc4c8184313d4963bce815b8c50c33684d07d (diff)
fixes #3645 (NewStory: не копировать теги при копировании текста)
-rw-r--r--plugins/NewStory/src/history_control.cpp6
-rw-r--r--plugins/NewStory/src/utils.cpp59
-rw-r--r--plugins/NewStory/src/utils.h2
3 files changed, 66 insertions, 1 deletions
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);