mirror of
https://onedev.site.tesses.net/tesses-framework
synced 2026-02-09 00:05:46 +00:00
Add htmlp
This commit is contained in:
@@ -156,6 +156,7 @@ struct CaseInsensitiveLess {
|
|||||||
static std::string UrlPathDecode(std::string v);
|
static std::string UrlPathDecode(std::string v);
|
||||||
static std::string UrlPathEncode(std::string v, bool ignoreSpace=false);
|
static std::string UrlPathEncode(std::string v, bool ignoreSpace=false);
|
||||||
static std::string HtmlEncode(std::string v);
|
static std::string HtmlEncode(std::string v);
|
||||||
|
static std::string HtmlP(std::string text);
|
||||||
static std::string HtmlDecodeOnlyEntityNumber(std::string v);
|
static std::string HtmlDecodeOnlyEntityNumber(std::string v);
|
||||||
static std::vector<std::string> SplitString(std::string text, std::string delimiter,std::size_t maxCnt = std::string::npos);
|
static std::vector<std::string> 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);
|
static std::string Replace(std::string str, std::string find, std::string replace);
|
||||||
|
|||||||
@@ -582,6 +582,62 @@ namespace Tesses::Framework::Http {
|
|||||||
}
|
}
|
||||||
return buff;
|
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 += "<a href=\"" + HttpUtils::HtmlEncode(builder) + "\">" + HttpUtils::HtmlEncode(builder) + "</a>";
|
||||||
|
}
|
||||||
|
else if(builder.find("mailto:") == 0)
|
||||||
|
{
|
||||||
|
newText += "<a href=\"" + HttpUtils::HtmlEncode(builder) + "\">" + HttpUtils::HtmlEncode(builder.substr(7)) + "</a>";
|
||||||
|
}
|
||||||
|
else if(builder.find("tel:") == 0)
|
||||||
|
{
|
||||||
|
newText += "<a href=\"" + HttpUtils::HtmlEncode(builder) + "\">" + HttpUtils::HtmlEncode(builder.substr(4)) + "</a>";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
newText += HttpUtils::HtmlEncode(builder);
|
||||||
|
}
|
||||||
|
builder = "";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
for(auto item : text)
|
||||||
|
{
|
||||||
|
switch(item)
|
||||||
|
{
|
||||||
|
case ' ':
|
||||||
|
flush();
|
||||||
|
newText += " ";
|
||||||
|
break;
|
||||||
|
case '\n':
|
||||||
|
flush();
|
||||||
|
newText += "<br>";
|
||||||
|
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 HttpUtils::HtmlEncode(std::string html)
|
||||||
{
|
{
|
||||||
std::string myHtml = {};
|
std::string myHtml = {};
|
||||||
|
|||||||
Reference in New Issue
Block a user