rewrite html_escape without boost replace
This commit is contained in:
parent
8a32d98443
commit
7c5d88d914
@ -1,7 +1,5 @@
|
||||
#include "utils.hpp"
|
||||
|
||||
#include <boost/algorithm/string/replace.hpp>
|
||||
|
||||
mstch::citer mstch::first_not_ws(mstch::citer begin, mstch::citer end) {
|
||||
for (auto it = begin; it != end; ++it)
|
||||
if (*it != ' ') return it;
|
||||
@ -14,12 +12,22 @@ mstch::citer mstch::first_not_ws(mstch::criter begin, mstch::criter end) {
|
||||
return --(end.base());
|
||||
}
|
||||
|
||||
std::string mstch::html_escape(std::string str) {
|
||||
boost::replace_all(str, "&", "&");
|
||||
boost::replace_all(str, "'", "'");
|
||||
boost::replace_all(str, "\"", """);
|
||||
boost::replace_all(str, "<", "<");
|
||||
boost::replace_all(str, ">", ">");
|
||||
boost::replace_all(str, "/", "/");
|
||||
return str;
|
||||
std::string mstch::html_escape(const std::string& str) {
|
||||
std::string out;
|
||||
citer start = str.begin();
|
||||
auto add_escape = [&out, &start](const std::string& escaped, citer& it) {
|
||||
out += std::string{start, it} + escaped;
|
||||
start = it + 1;
|
||||
};
|
||||
for (auto it = str.begin(); it != str.end(); ++it)
|
||||
switch (*it) {
|
||||
case '&': add_escape("&", it); break;
|
||||
case '\'': add_escape("'", it); break;
|
||||
case '"': add_escape(""", it); break;
|
||||
case '<': add_escape("<", it); break;
|
||||
case '>': add_escape(">", it); break;
|
||||
case '/': add_escape("/", it); break;
|
||||
default: break;
|
||||
}
|
||||
return out + std::string{start, str.end()};
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ using criter = std::string::const_reverse_iterator;
|
||||
|
||||
citer first_not_ws(citer begin, citer end);
|
||||
citer first_not_ws(criter begin, criter end);
|
||||
std::string html_escape(std::string str);
|
||||
std::string html_escape(const std::string& str);
|
||||
|
||||
template<class... Args>
|
||||
auto visit(Args&&... args) -> decltype(boost::apply_visitor(
|
||||
|
Loading…
x
Reference in New Issue
Block a user