diff options
author | Robert Pösel <robyer@seznam.cz> | 2017-03-05 09:15:39 +0100 |
---|---|---|
committer | Robert Pösel <robyer@seznam.cz> | 2017-03-05 09:15:39 +0100 |
commit | cc8f9defc89f3c56088ac8de2e979938a0e85947 (patch) | |
tree | 42768529e6e51ba7855b416b0ab33a2f8409d7b9 /protocols/FacebookRM | |
parent | 3f04f6768745e5fe08cd7b681d48097536980c77 (diff) |
Facebook: Fix cutting unicode strings (fixes #711)
Diffstat (limited to 'protocols/FacebookRM')
-rw-r--r-- | protocols/FacebookRM/src/json.cpp | 3 | ||||
-rw-r--r-- | protocols/FacebookRM/src/process.cpp | 16 |
2 files changed, 3 insertions, 16 deletions
diff --git a/protocols/FacebookRM/src/json.cpp b/protocols/FacebookRM/src/json.cpp index e559f982f8..6325c2cca2 100644 --- a/protocols/FacebookRM/src/json.cpp +++ b/protocols/FacebookRM/src/json.cpp @@ -314,8 +314,7 @@ void parseAttachments(FacebookProto *proto, std::string *message_text, const JSO std::string link = share["uri"].as_string(); // shorten long descriptions - if (description.length() > MAX_LINK_DESCRIPTION_LEN) - description = description.substr(0, MAX_LINK_DESCRIPTION_LEN) + TEXT_ELLIPSIS; + description = utils::text::truncate_utf8(description, MAX_LINK_DESCRIPTION_LEN); if (link.find("//www." FACEBOOK_SERVER_DOMAIN "/l.php") != std::string::npos || link.find("//l." FACEBOOK_SERVER_DOMAIN) != std::string::npos) { // de-facebook this link 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<facebook_newsfeed *> &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<facebook_newsfeed *> &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<facebook_newsfeed *> &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) |