From 554f813d5f21854966b4c36557712e08f34f5c4b Mon Sep 17 00:00:00 2001 From: Gerd von Egidy Date: Thu, 5 Feb 2015 15:34:12 +0100 Subject: [PATCH] add function html_entities_to_console to stringfunc --- src/stringfunc.cpp | 24 ++++++++++++++++++++++++ src/stringfunc.hxx | 1 + 2 files changed, 25 insertions(+), 0 deletions(-) diff --git a/src/stringfunc.cpp b/src/stringfunc.cpp index 8f0464a..6bfd860 100644 --- a/src/stringfunc.cpp +++ b/src/stringfunc.cpp @@ -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, "<", "<"); + replace_all (str, ">", ">"); + replace_all (str, """, "\""); + replace_all (str, "'", "'"); + replace_all (str, "/", "/"); + + // Umlauts + replace_all (str, "ä", "ae"); + replace_all (str, "ö", "oe"); + replace_all (str, "ü", "ue"); + replace_all (str, "Ä", "Ae"); + replace_all (str, "Ö", "Oe"); + replace_all (str, "Ü", "Ue"); + + // Misc + replace_all (str, "ß", "ss"); + + return str; +} bool replace_all(string &base, const char *ist, const char *soll) { diff --git a/src/stringfunc.hxx b/src/stringfunc.hxx index 8b7afab..673ee7c 100644 --- a/src/stringfunc.hxx +++ b/src/stringfunc.hxx @@ -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); -- 1.7.1