diff --git a/src/template_type.cpp b/src/template_type.cpp index a7310da..05f5232 100644 --- a/src/template_type.cpp +++ b/src/template_type.cpp @@ -18,6 +18,8 @@ void template_type::process_text(citer begin, citer end) { } } +#include + void template_type::tokenize(const std::string& tmp) { std::string open{"{{"}, close{"}}"}; citer beg = tmp.begin(); @@ -41,8 +43,12 @@ void template_type::tokenize(const std::string& tmp) { if (*(beg + open_pos + open.size()) == '=' && *(beg + close_pos - 1) == '=') { - open = {beg + open_pos + open.size() + 1, beg + tmp.find(' ',open_pos)}; - close = {beg + tmp.find(' ', open_pos) + 1, beg + close_pos - 1}; + auto tok_beg = beg + open_pos + open.size() + 1; + auto tok_end = beg + close_pos - 1; + auto front_skip = first_not_ws(tok_beg, tok_end); + auto back_skip = first_not_ws(reverse(tok_end), reverse(tok_beg)); + open = {front_skip, beg + tmp.find(' ', front_skip - beg)}; + close = {beg + tmp.rfind(' ', back_skip - beg) + 1, back_skip + 1}; } } else { process_text(beg + cur_pos, tmp.end()); diff --git a/src/utils.cpp b/src/utils.cpp index 4c480e8..032f89a 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -12,6 +12,10 @@ mstch::citer mstch::first_not_ws(mstch::criter begin, mstch::criter end) { return --(end.base()); } +mstch::criter mstch::reverse(mstch::citer it) { + return std::reverse_iterator(it); +} + std::string mstch::html_escape(const std::string& str) { std::string out; citer start = str.begin(); diff --git a/src/utils.hpp b/src/utils.hpp index 9b05da8..9041a3e 100644 --- a/src/utils.hpp +++ b/src/utils.hpp @@ -11,6 +11,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(const std::string& str); +criter reverse(citer it); template auto visit(Args&&... args) -> decltype(boost::apply_visitor(