diff --git a/include/TessesFramework/Http/HttpUtils.hpp b/include/TessesFramework/Http/HttpUtils.hpp index 7a13d47..b2f6f5a 100644 --- a/include/TessesFramework/Http/HttpUtils.hpp +++ b/include/TessesFramework/Http/HttpUtils.hpp @@ -156,6 +156,7 @@ struct CaseInsensitiveLess { static std::string UrlPathDecode(std::string v); static std::string UrlPathEncode(std::string v, bool ignoreSpace=false); static std::string HtmlEncode(std::string v); + static std::string HtmlP(std::string text); static std::string HtmlDecodeOnlyEntityNumber(std::string v); static std::vector SplitString(std::string text, std::string delimiter,std::size_t maxCnt = std::string::npos); static std::string Replace(std::string str, std::string find, std::string replace); diff --git a/src/Http/HttpUtils.cpp b/src/Http/HttpUtils.cpp index e2f06b8..200c38d 100644 --- a/src/Http/HttpUtils.cpp +++ b/src/Http/HttpUtils.cpp @@ -582,6 +582,62 @@ namespace Tesses::Framework::Http { } return buff; } + std::string HttpUtils::HtmlP(std::string text) + { + std::string newText = ""; + std::string builder = ""; + + auto flush = [&]()->void { + if(!builder.empty()) + { + if(builder.find("http://") == 0 || builder.find("https://") == 0 || builder.find("ftp://") == 0 || builder.find("ftps://") == 0 || builder.find("magnet:") == 0 || builder.find("btmh:") == 0) + { + newText += "" + HttpUtils::HtmlEncode(builder) + ""; + } + else if(builder.find("mailto:") == 0) + { + newText += "" + HttpUtils::HtmlEncode(builder.substr(7)) + ""; + } + else if(builder.find("tel:") == 0) + { + newText += "" + HttpUtils::HtmlEncode(builder.substr(4)) + ""; + } + else { + newText += HttpUtils::HtmlEncode(builder); + } + builder = ""; + } + }; + + + for(auto item : text) + { + switch(item) + { + case ' ': + flush(); + newText += " "; + break; + case '\n': + flush(); + newText += "
"; + break; + case '\t': + flush(); + newText += "&tab;"; + break; + case '\r': + flush(); + break; + default: + builder += item; + break; + } + } + flush(); + + return newText; + } std::string HttpUtils::HtmlEncode(std::string html) { std::string myHtml = {};