From cc8f9defc89f3c56088ac8de2e979938a0e85947 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20P=C3=B6sel?= Date: Sun, 5 Mar 2017 09:15:39 +0100 Subject: Facebook: Fix cutting unicode strings (fixes #711) --- protocols/FacebookRM/src/process.cpp | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) (limited to 'protocols/FacebookRM/src/process.cpp') diff --git a/protocols/FacebookRM/src/process.cpp b/protocols/FacebookRM/src/process.cpp index 4bf96e0e3c..6497145c00 100644 --- a/protocols/FacebookRM/src/process.cpp +++ b/protocols/FacebookRM/src/process.cpp @@ -516,18 +516,6 @@ void FacebookProto::LoadHistory(void *pParam) // PUDeletePopup(popupHwnd); } -std::string truncateUtf8(std::string &text, size_t maxLength) { - // To not split some unicode character we need to transform it to wchar_t first, then split it, and then convert it back, because we want std::string as result - // TODO: Probably there is much simpler and nicer way - std::wstring ttext = ptrW(mir_utf8decodeW(text.c_str())); - if (ttext.length() > maxLength) { - ttext = ttext.substr(0, maxLength) + L"\x2026"; // unicode ellipsis - return std::string(_T2A(ttext.c_str(), CP_UTF8)); - } - // It's not longer, return given string - return text; -} - void parseFeeds(const std::string &text, std::vector &news, DWORD &last_post_time, bool filterAds = true) { std::string::size_type pos = 0; UINT limit = 0; @@ -629,7 +617,7 @@ void parseFeeds(const std::string &text, std::vector &news, utils::text::html_entities_decode( utils::text::remove_html(post_attachment))); - post_attachment = truncateUtf8(post_attachment, MAX_LINK_DESCRIPTION_LEN); + post_attachment = utils::text::truncate_utf8(post_attachment, MAX_LINK_DESCRIPTION_LEN); if (post_attachment.empty()) { // This is some textless attachment, so mention it @@ -642,7 +630,7 @@ void parseFeeds(const std::string &text, std::vector &news, utils::text::remove_html(post_message))); // Truncate text of newsfeed when it's too long - post_message = truncateUtf8(post_message, MAX_NEWSFEED_LEN); + post_message = utils::text::truncate_utf8(post_message, MAX_NEWSFEED_LEN); std::string content = ""; if (header_rest.length() > 2) -- cgit v1.2.3