add function html_entities_to_console to stringfunc
authorGerd von Egidy <gerd.von.egidy@intra2net.com>
Thu, 5 Feb 2015 14:34:12 +0000 (15:34 +0100)
committerGerd von Egidy <gerd.von.egidy@intra2net.com>
Thu, 5 Feb 2015 14:34:12 +0000 (15:34 +0100)
src/stringfunc.cpp
src/stringfunc.hxx

index 8f0464a..6bfd860 100644 (file)
@@ -842,6 +842,30 @@ string html_entities(std::string str)
    return str;
 } // eo html_entities(std::string)
 
+// convert HTML entities to something that can be viewed on a basic text console (restricted to ASCII-7)
+string html_entities_to_console(std::string str)
+{
+   // Normal chars
+   replace_all (str, "&amp;", "&");
+   replace_all (str, "&lt;", "<");
+   replace_all (str, "&gt;", ">");
+   replace_all (str, "&quot;", "\"");
+   replace_all (str, "&#x27;", "'");
+   replace_all (str, "&#x2F;", "/");
+
+   // Umlauts
+   replace_all (str, "&auml;", "ae");
+   replace_all (str, "&ouml;", "oe");
+   replace_all (str, "&uuml;", "ue");
+   replace_all (str, "&Auml;", "Ae");
+   replace_all (str, "&Ouml;", "Oe");
+   replace_all (str, "&Uuml;", "Ue");
+
+   // Misc
+   replace_all (str, "&szlig;", "ss");
+
+   return str;
+}
 
 bool replace_all(string &base, const char *ist, const char *soll)
 {
index 8b7afab..673ee7c 100644 (file)
@@ -239,6 +239,7 @@ std::string utf8_to_utf7imap(const std::string &utf8string);
 std::string strip_html_tags(const std::string &input);
 std::string smart_html_entities(const std::string &input);
 std::string html_entities(std::string str);
+std::string html_entities_to_console(std::string str);
 
 std::string escape(const std::string &s);