uset enum flags in visitors
This commit is contained in:
parent
95ec6728af
commit
406f730621
@ -18,10 +18,13 @@ std::string state::outside_section::render(
|
||||
ctx.set_state<in_inverted_section>(token.content());
|
||||
break;
|
||||
case token_type::variable:
|
||||
case token_type::unescaped_variable:
|
||||
case token_type::unescaped_variable: {
|
||||
std::set<visitor::render_node::flag> flags{};
|
||||
if (token.type() == token_type::variable)
|
||||
flags.insert(visitor::render_node::flag::escape_html);
|
||||
return boost::apply_visitor(
|
||||
visitor::render_node(token.type() == token_type::variable),
|
||||
ctx.get_node(token.content()));
|
||||
visitor::render_node(flags), ctx.get_node(token.content()));
|
||||
}
|
||||
case token_type::comment: break;
|
||||
case token_type::text:
|
||||
return token.raw();
|
||||
|
@ -3,8 +3,8 @@
|
||||
|
||||
using namespace mstch;
|
||||
|
||||
visitor::render_node::render_node(bool html_escaped):
|
||||
html_escaped(html_escaped)
|
||||
visitor::render_node::render_node(std::set<flag> flags):
|
||||
flags(flags)
|
||||
{
|
||||
}
|
||||
|
||||
@ -21,7 +21,7 @@ std::string visitor::render_node::operator()(const bool& b) const {
|
||||
}
|
||||
|
||||
std::string visitor::render_node::operator()(const std::string& str) const {
|
||||
return html_escaped?html_escape(str):str;
|
||||
return (flags.find(flag::escape_html) != flags.end())?html_escape(str):str;
|
||||
}
|
||||
|
||||
std::string visitor::render_node::operator()(const array& arr) const {
|
||||
|
@ -5,14 +5,17 @@
|
||||
#include <boost/blank.hpp>
|
||||
|
||||
#include "types.h"
|
||||
#include <set>
|
||||
|
||||
namespace mstch {
|
||||
namespace visitor {
|
||||
class render_node: public boost::static_visitor<std::string> {
|
||||
private:
|
||||
bool html_escaped;
|
||||
public:
|
||||
render_node(bool html_escaped);
|
||||
enum class flag { escape_html };
|
||||
private:
|
||||
std::set<flag> flags;
|
||||
public:
|
||||
render_node(std::set<flag> flags = {});
|
||||
std::string operator()(const boost::blank& blank) const;
|
||||
std::string operator()(const int& i) const;
|
||||
std::string operator()(const bool& b) const;
|
||||
|
Loading…
Reference in New Issue
Block a user