From 45a6b265a4b93103d79bd86120469fd24f09aeb2 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Wed, 22 Nov 2023 20:51:14 +0300 Subject: Telegram: fix for non-latin chars in messages & bbcodes --- protocols/Telegram/src/utils.cpp | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'protocols') diff --git a/protocols/Telegram/src/utils.cpp b/protocols/Telegram/src/utils.cpp index c517529219..b2a1c9c3eb 100644 --- a/protocols/Telegram/src/utils.cpp +++ b/protocols/Telegram/src/utils.cpp @@ -19,22 +19,22 @@ along with this program. If not, see . struct { - const char *begin, *end; + const wchar_t *begin, *end; unsigned len1, len2; } static bbCodes[] = { - { "[b]", "[/b]", 3, 4 }, - { "[i]", "[/i]", 3, 4 }, - { "[s]", "[/s]", 3, 4 }, - { "[u]", "[/u]", 3, 4 }, + { L"[b]", L"[/b]", 3, 4 }, + { L"[i]", L"[/i]", 3, 4 }, + { L"[s]", L"[/s]", 3, 4 }, + { L"[u]", L"[/u]", 3, 4 }, }; TD::object_ptr formatBbcodes(const char *pszText) { auto res = TD::make_object(); if (mir_strlen(pszText)) { - std::string str = pszText; + std::wstring str = Utf2T(pszText).get(); for (auto &it : bbCodes) { while (true) { size_t i1 = str.find(it.begin); @@ -66,7 +66,7 @@ TD::object_ptr formatBbcodes(const char *pszText) res->entities_.push_back(TD::make_object(TD::int32(i1), TD::int32(i2 - i1), std::move(pNew))); } } - res->text_ = str; + res->text_ = T2Utf(str.c_str()).get(); } return res; @@ -75,10 +75,10 @@ TD::object_ptr formatBbcodes(const char *pszText) static CMStringA getFormattedText(TD::object_ptr &pText) { if (pText->get_id() == TD::formattedText::ID) { - CMStringA ret(pText->text_.c_str()); + CMStringW ret(Utf2T(pText->text_.c_str())); for (auto &it : pText->entities_) { int iCode; - switch (it->get_id()) { + switch (it->type_->get_id()) { case TD::textEntityTypeBold::ID: iCode = 0; break; case TD::textEntityTypeItalic::ID: iCode = 1; break; case TD::textEntityTypeStrikethrough::ID: iCode = 2; break; @@ -90,6 +90,7 @@ static CMStringA getFormattedText(TD::object_ptr &pText) ret.Insert(it->offset_ + it->length_, bbCodes[iCode].end); ret.Insert(it->offset_, bbCodes[iCode].begin); } + return T2Utf(ret).get(); } return ""; -- cgit v1.2.3