From 8b77c1ba74a24af5ec831385fc876807aed509c0 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Robert=20P=C3=B6sel?= <robyer@seznam.cz>
Date: Mon, 27 Jul 2015 09:05:52 +0000
Subject: 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
---
 protocols/Twitter/src/StringUtil.cpp | 10 ++++++++++
 protocols/Twitter/src/StringUtil.h   |  2 ++
 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, "&amp;", "&");
+	replaceAll(context, "&quot;", "\"");
+	replaceAll(context, "&lt;", "<");
+	replaceAll(context, "&gt;", ">");
+
+	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 "&amp;" in the tweets :(
-			for (size_t pos = 0; (pos = retweetText.find("&amp;", 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 "&amp;" 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("&amp;", pos)) != std::string::npos; pos++)
-				rawText.replace(pos, 5, "&");
+			
+			// fix html entities in the text
+			htmlEntitiesDecode(rawText);
 
 			u.status.text = rawText;
 		}
-- 
cgit v1.2.3