From 406f730621415a74029ad7d779cc1e2344697d6e Mon Sep 17 00:00:00 2001 From: Daniel Sipka Date: Sat, 11 Apr 2015 14:02:57 +0200 Subject: [PATCH] uset enum flags in visitors --- src/state/outside_section.cpp | 9 ++++++--- src/visitor/render_node.cpp | 6 +++--- src/visitor/render_node.h | 9 ++++++--- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/state/outside_section.cpp b/src/state/outside_section.cpp index 8407fcd..5cbe54c 100644 --- a/src/state/outside_section.cpp +++ b/src/state/outside_section.cpp @@ -18,10 +18,13 @@ std::string state::outside_section::render( ctx.set_state(token.content()); break; case token_type::variable: - case token_type::unescaped_variable: + case token_type::unescaped_variable: { + std::set 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(); diff --git a/src/visitor/render_node.cpp b/src/visitor/render_node.cpp index 72945a1..33924cc 100644 --- a/src/visitor/render_node.cpp +++ b/src/visitor/render_node.cpp @@ -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 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 { diff --git a/src/visitor/render_node.h b/src/visitor/render_node.h index d95874f..821c797 100644 --- a/src/visitor/render_node.h +++ b/src/visitor/render_node.h @@ -5,14 +5,17 @@ #include #include "types.h" +#include namespace mstch { namespace visitor { class render_node: public boost::static_visitor { - private: - bool html_escaped; public: - render_node(bool html_escaped); + enum class flag { escape_html }; + private: + std::set flags; + public: + render_node(std::set flags = {}); std::string operator()(const boost::blank& blank) const; std::string operator()(const int& i) const; std::string operator()(const bool& b) const;