mstch/src/utils.cpp

26 lines
761 B
C++
Raw Normal View History

2015-04-12 13:35:13 +00:00
#include "utils.hpp"
2015-04-09 18:41:27 +00:00
2015-04-12 13:25:16 +00:00
#include <boost/algorithm/string/replace.hpp>
2015-04-09 18:41:27 +00:00
2015-04-15 20:32:27 +00:00
mstch::citer mstch::first_not_ws(mstch::citer begin, mstch::citer end) {
for(auto it = begin; it != end; ++it)
if(*it != ' ') return it;
return end;
}
mstch::citer mstch::first_not_ws(mstch::criter begin, mstch::criter end) {
for(auto rit = begin; rit != end; ++rit)
if(*rit != ' ') return --(rit.base());
return --(end.base());
}
2015-04-09 18:41:27 +00:00
std::string mstch::html_escape(std::string str) {
2015-04-12 13:25:16 +00:00
boost::replace_all(str, "&", "&amp;");
boost::replace_all(str, "'", "&#39;");
boost::replace_all(str, "\"", "&quot;");
boost::replace_all(str, "<", "&lt;");
boost::replace_all(str, ">", "&gt;");
boost::replace_all(str, "/", "&#x2F;");
2015-04-09 18:41:27 +00:00
return str;
}