diff options
author | Robert Pösel <robyer@seznam.cz> | 2015-07-27 09:05:52 +0000 |
---|---|---|
committer | Robert Pösel <robyer@seznam.cz> | 2015-07-27 09:05:52 +0000 |
commit | 8b77c1ba74a24af5ec831385fc876807aed509c0 (patch) | |
tree | 11bff428aa51b7fb36b5ebb30662a5ff4a6b7b65 | |
parent | d8987ee0292e52549abfcf8763e93cf187317581 (diff) |
Twitter: Replace few more html entities with text representation
git-svn-id: http://svn.miranda-ng.org/main/trunk@14734 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
-rw-r--r-- | protocols/Twitter/src/StringUtil.cpp | 10 | ||||
-rw-r--r-- | protocols/Twitter/src/StringUtil.h | 2 | ||||
-rw-r--r-- | protocols/Twitter/src/twitter.cpp | 14 |
3 files changed, 18 insertions, 8 deletions
diff --git a/protocols/Twitter/src/StringUtil.cpp b/protocols/Twitter/src/StringUtil.cpp index 61cb9adbd2..0ac892cd1f 100644 --- a/protocols/Twitter/src/StringUtil.cpp +++ b/protocols/Twitter/src/StringUtil.cpp @@ -86,3 +86,13 @@ std::string& replaceAll(std::string& context, const std::string& from, const std }
return context;
}
+
+std::string& htmlEntitiesDecode(std::string& context)
+{
+ replaceAll(context, "&", "&");
+ replaceAll(context, """, "\"");
+ replaceAll(context, "<", "<");
+ replaceAll(context, ">", ">");
+
+ return context;
+}
\ No newline at end of file diff --git a/protocols/Twitter/src/StringUtil.h b/protocols/Twitter/src/StringUtil.h index 643450b072..0fe42aedce 100644 --- a/protocols/Twitter/src/StringUtil.h +++ b/protocols/Twitter/src/StringUtil.h @@ -30,6 +30,8 @@ tstring GetWord(const tstring& str, unsigned index, bool getRest = false); std::string& replaceAll(std::string& context, const std::string& from, const std::string& to);
+std::string& htmlEntitiesDecode(std::string& context);
+
inline std::string WideToUTF8(const std::wstring& str)
{
return (char*)ptrA(mir_utf8encodeW(str.c_str()));
diff --git a/protocols/Twitter/src/twitter.cpp b/protocols/Twitter/src/twitter.cpp index 64eca48940..aa94f34dbb 100644 --- a/protocols/Twitter/src/twitter.cpp +++ b/protocols/Twitter/src/twitter.cpp @@ -240,19 +240,17 @@ std::vector<twitter_user> twitter::get_statuses(int count, twitter_id id) std::string retweeteesName = pUser2["screen_name"].as_string(); // the user that is being retweeted
std::string retweetText = pRetweet["text"].as_string(); // their tweet in all it's untruncated glory
- // fix "&" in the tweets :(
- for (size_t pos = 0; (pos = retweetText.find("&", pos)) != std::string::npos; pos++)
- retweetText.replace(pos, 5, "&");
+ // fix html entities in the text
+ htmlEntitiesDecode(retweetText);
u.status.text = "RT @" + retweeteesName + " " + retweetText; // mash it together in some format people will understand
}
else {
- // if it's not truncated, then the twitter API returns the native RT correctly anyway,
+ // if it's not truncated, then the twitter API returns the native RT correctly anyway,
std::string rawText = one["text"].as_string();
- // ok here i'm trying some way to fix all the "&" things that are showing up
- // i dunno why it's happening, so i'll just find and replace each occurance :/
- for (size_t pos = 0; (pos = rawText.find("&", pos)) != std::string::npos; pos++)
- rawText.replace(pos, 5, "&");
+
+ // fix html entities in the text
+ htmlEntitiesDecode(rawText);
u.status.text = rawText;
}
|