From aef20adc236f510617d9a4426977db25e7b26a3e Mon Sep 17 00:00:00 2001 From: George Hazan Date: Tue, 4 Mar 2025 15:52:52 +0300 Subject: =?UTF-8?q?fixes=20#4908=20(Telegram:=20=D0=B2=D1=85=D0=BE=D0=B4?= =?UTF-8?q?=D1=8F=D1=89=D0=B8=D0=B9=20=D1=82=D0=B5=D0=BA=D1=81=D1=82=20?= =?UTF-8?q?=D1=81=20=D0=B4=D0=B2=D0=BE=D0=B9=D0=BD=D1=8B=D0=BC=20=D1=84?= =?UTF-8?q?=D0=BE=D1=80=D0=BC=D0=B0=D1=82=D0=B8=D1=80=D0=BE=D0=B2=D0=B0?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D0=BE=D1=82=D0=BE=D0=B1=D1=80=D0=B0=D0=B6?= =?UTF-8?q?=D0=B0=D0=B5=D1=82=D1=81=D1=8F=20=D0=BD=D0=B5=D0=BA=D0=BE=D1=80?= =?UTF-8?q?=D1=80=D0=B5=D0=BA=D1=82=D0=BD=D0=BE)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- protocols/Telegram/src/utils.cpp | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) (limited to 'protocols/Telegram/src/utils.cpp') diff --git a/protocols/Telegram/src/utils.cpp b/protocols/Telegram/src/utils.cpp index 052fa9e413..839da0fcfb 100644 --- a/protocols/Telegram/src/utils.cpp +++ b/protocols/Telegram/src/utils.cpp @@ -22,7 +22,7 @@ enum class BBCODE BOLD, ITALIC, STRIKE, UNDERLINE, URL, CODE, QUOTE }; -struct +struct Bbcode { BBCODE type; const wchar_t *begin, *end; @@ -91,7 +91,13 @@ TD::object_ptr formatBbcodes(const char *pszText) CMStringA CTelegramProto::GetFormattedText(TD::object_ptr &pText) { CMStringW ret(Utf2T(pText->text_.c_str())); - unsigned offset = 0; + + struct HistItem { + HistItem(int _1, int _2, const Bbcode &_3) : start(_1), length(_2), bbcode(_3) {} + int start, length; + const Bbcode &bbcode; + }; + std::vector history; for (auto &it : pText->entities_) { int iCode; @@ -107,10 +113,19 @@ CMStringA CTelegramProto::GetFormattedText(TD::object_ptr &pT continue; } + int off1 = 0, off2 = 0; + for (auto &h : history) { + if (it->offset_ >= h.start) + off1 += h.bbcode.len1, off2 += h.bbcode.len1; + + if (it->offset_ + it->length_ > h.start + h.length) + off2 += h.bbcode.len2; + } + auto &bb = bbCodes[iCode]; - ret.Insert(offset + it->offset_ + it->length_, bb.end); - ret.Insert(offset + it->offset_, bb.begin); - offset += bb.len1 + bb.len2; + ret.Insert(off1 + it->offset_ + it->length_, bb.end); + ret.Insert(off2 + it->offset_, bb.begin); + history.push_back(HistItem(it->offset_, it->length_, bb)); } return T2Utf(ret).get(); } -- cgit v1.2.3