From 77f8ef3aa3dc989bbe24b0bdb870c558d068aebb Mon Sep 17 00:00:00 2001 From: Michael Liebmann Date: Wed, 26 Feb 2014 10:02:32 +0100 Subject: [PATCH] src/system/helpers.cpp: Add htmlEntityDecode() for decode html string Origin commit data ------------------ Commit: https://github.com/neutrino-images/ni-neutrino/commit/0028ad0d9b117d453d218f2a359b675deb1c5e18 Author: Michael Liebmann Date: 2014-02-26 (Wed, 26 Feb 2014) --- src/system/helpers.cpp | 22 ++++++++++++++++++++++ src/system/helpers.h | 1 + 2 files changed, 23 insertions(+) diff --git a/src/system/helpers.cpp b/src/system/helpers.cpp index 5b51e0601..2ab1512cd 100644 --- a/src/system/helpers.cpp +++ b/src/system/helpers.cpp @@ -417,6 +417,28 @@ std::string& str_replace(const std::string &search, const std::string &replace, return text; } +std::string& htmlEntityDecode(std::string& text) +{ + struct decode_table { + const char* code; + const char* htmlCode; + }; + decode_table dt[] = + { + {" ", " "}, + {"&", "&"}, + {"<", "<"}, + {">", ">"}, + {"\"", """}, + {"'", "'"}, + {NULL, NULL} + }; + for (int i = 0; dt[i].code != NULL; i++) + text = str_replace(dt[i].htmlCode, dt[i].code, text); + + return text; +} + CFileHelpers::CFileHelpers() { FileBufSize = 0xFFFF; diff --git a/src/system/helpers.h b/src/system/helpers.h index 74b9e0208..480c43f03 100644 --- a/src/system/helpers.h +++ b/src/system/helpers.h @@ -55,6 +55,7 @@ std::string getNowTimeStr(const char* format); std::string trim(std::string &str, const std::string &trimChars = " \n\r\t"); time_t toEpoch(std::string &date); std::string& str_replace(const std::string &search, const std::string &replace, std::string &text); +std::string& htmlEntityDecode(std::string& text); class CFileHelpers {