2 #include "mstch/mstch.hpp"
4 mstch::citer mstch::first_not_ws(mstch::citer begin, mstch::citer end) {
5 for (auto it = begin; it != end; ++it)
6 if (*it != ' ') return it;
10 mstch::citer mstch::first_not_ws(mstch::criter begin, mstch::criter end) {
11 for (auto rit = begin; rit != end; ++rit)
12 if (*rit != ' ') return --(rit.base());
13 return --(end.base());
16 mstch::criter mstch::reverse(mstch::citer it) {
17 return std::reverse_iterator<mstch::citer>(it);
20 std::string mstch::html_escape(const std::string& str) {
21 if (mstch::config::escape)
22 return mstch::config::escape(str);
25 citer start = str.begin();
27 auto add_escape = [&out, &start](const std::string& escaped, citer& it) {
28 out += std::string{start, it} + escaped;
32 for (auto it = str.begin(); it != str.end(); ++it)
34 case '&': add_escape("&", it); break;
35 case '\'': add_escape("'", it); break;
36 case '"': add_escape(""", it); break;
37 case '<': add_escape("<", it); break;
38 case '>': add_escape(">", it); break;
39 case '/': add_escape("/", it); break;
43 return out + std::string{start, str.end()};