add function html_entities_to_console to stringfunc
[libi2ncommon] / src / stringfunc.cpp
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, "&", "&");
+   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)
 {