From d5849fcb979c1d553643bc3b4d4b7f2f12cee03b Mon Sep 17 00:00:00 2001 From: George Hazan Date: Sun, 24 Mar 2024 20:28:54 +0300 Subject: =?UTF-8?q?fixes=20#4298=20(NewStory:=20=D0=B6=D1=83=D1=80=D0=BD?= =?UTF-8?q?=D0=B0=D0=BB=20=D1=81=D1=87=D0=B8=D1=82=D0=B0=D0=B5=D1=82=20?= =?UTF-8?q?=D1=81=D0=BB=D0=BE=D0=B2=D0=BE=20=D0=BF=D0=BE=D1=81=D0=BB=D0=B5?= =?UTF-8?q?=20=D0=BF=D0=B5=D1=80=D0=B5=D0=B2=D0=BE=D0=B4=D0=B0=20=D1=81?= =?UTF-8?q?=D1=82=D1=80=D0=BE=D0=BA=D0=B8=20=D0=BF=D1=80=D0=BE=D0=B4=D0=BE?= =?UTF-8?q?=D0=BB=D0=B6=D0=B5=D0=BD=D0=B8=D0=B5=D0=BC=20=D1=81=D1=81=D1=8B?= =?UTF-8?q?=D0=BB=D0=BA=D0=B8)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/NewStory/src/templates.cpp | 22 +++++++++++++++------- plugins/NewStory/src/utils.cpp | 10 ++++------ 2 files changed, 19 insertions(+), 13 deletions(-) (limited to 'plugins/NewStory/src') diff --git a/plugins/NewStory/src/templates.cpp b/plugins/NewStory/src/templates.cpp index a6b18f4ed6..471b7d1dfd 100644 --- a/plugins/NewStory/src/templates.cpp +++ b/plugins/NewStory/src/templates.cpp @@ -113,6 +113,15 @@ static void AppendString(CMStringW &buf, const wchar_t *p) buf.AppendFormat(L"<%ss>", pEnd); p++; } + else if (!wcsncmp(p, L"url]", 4)) { + p += 4; + + if (auto *p2 = wcsstr(p, L"[/url]")) { + CMStringW wszUrl(p, int(p2 - p)); + buf.AppendFormat(L"%s", wszUrl.c_str(), wszUrl.c_str()); + p = p2 + 5; + } + } else { buf.AppendChar('['); if (*pEnd == '/') @@ -152,9 +161,9 @@ CMStringW ItemData::formatHtml(const wchar_t *pwszStr) spRes = (SMADD_BATCHPARSERES *)CallService(MS_SMILEYADD_BATCHPARSE, 0, (LPARAM)&sp); } - CMStringW szBody; - AppendString(szBody, wszOrigText); + CMStringW szBody(wszOrigText); UrlAutodetect(szBody); + AppendString(str, szBody); if (spRes) { int iOffset = 0; for (int i = 0; i < (int)sp.numSmileys; i++) { @@ -163,24 +172,23 @@ CMStringW ItemData::formatHtml(const wchar_t *pwszStr) continue; CMStringW wszFound(wszOrigText.Mid(smiley.startChar, smiley.size)); - int idx = szBody.Find(wszFound, iOffset); + int idx = str.Find(wszFound, iOffset); if (idx == -1) continue; - szBody.Delete(idx, smiley.size); + str.Delete(idx, smiley.size); CMStringW wszNew(FORMAT, L"\"%s\"", smiley.filepath, wszFound.c_str(), wszFound.c_str()); - szBody.Insert(idx, wszNew); + str.Insert(idx, wszNew); iOffset = idx + wszNew.GetLength(); } CallService(MS_SMILEYADD_BATCHFREE, 0, (LPARAM)spRes); } - str += szBody; str.Append(L""); - // Netlib_LogfW(0, str); + Netlib_LogfW(0, str); return str; } diff --git a/plugins/NewStory/src/utils.cpp b/plugins/NewStory/src/utils.cpp index f9bb3cd252..f227578fd4 100644 --- a/plugins/NewStory/src/utils.cpp +++ b/plugins/NewStory/src/utils.cpp @@ -146,13 +146,11 @@ static int DetectUrl(const wchar_t *text) void UrlAutodetect(CMStringW &str) { for (auto *p = str.c_str(); *p; p++) - if (int len = DetectUrl(p)) { + if (int len = DetectUrl(p)) { int pos = p - str.c_str(); CMStringW url = str.Mid(pos, len); - str.Delete(pos, len); - - CMStringW newText(FORMAT, L"%s", url.c_str(), url.c_str()); - str.Insert(pos, newText); - p = str.c_str() + pos + newText.GetLength(); + str.Insert(pos + len, L"[/url]"); + str.Insert(pos, L"[url]"); + p = str.c_str() + pos + len + 11; } } -- cgit v1.2.3