section array render bugfix

This commit is contained in:
Daniel Sipka 2015-04-11 13:55:59 +02:00
parent 4c43b33291
commit 95ec6728af
4 changed files with 31 additions and 18 deletions

View file

@ -23,10 +23,9 @@ std::string state::in_inverted_section::render(
if(token.content() == section_name && skipped_openings == 0) {
std::ostringstream out;
auto& section_node = ctx.get_node(section_name);
if(boost::apply_visitor(visitor::is_node_empty(), section_node)) {
auto empty = mstch::object{};
out << render_context(empty, ctx).render(section_text.str());
}
if(boost::apply_visitor(visitor::is_node_empty(), section_node))
out << render_context(mstch::object{}, ctx)
.render(section_text.str());
ctx.set_state<outside_section>();
return out.str();
} else {

View file

@ -20,8 +20,9 @@ std::string state::in_section::render(
auto section_node = ctx.get_node(section_name);
std::string out("");
if (!boost::apply_visitor(visitor::is_node_empty(), section_node))
out = boost::apply_visitor(visitor::render_section(
ctx, section_text.str()), section_node);
out = boost::apply_visitor(
visitor::render_section(ctx, section_text.str()),
section_node);
ctx.set_state<outside_section>();
return out;
} else {

View file

@ -5,16 +5,19 @@ using namespace mstch;
visitor::render_section::render_section(
render_context& context,
const std::string& section):
const std::string& section,
std::set<flag> flags):
context(context),
section(section)
section(section),
flags(flags)
{
}
std::string visitor::render_section::operator()(
const boost::blank& blank) const
{
return "";
return render_context(mstch::object{{".", mstch::node{}}}, context)
.render(section);
}
std::string visitor::render_section::operator()(const int& i) const {
@ -29,14 +32,17 @@ std::string visitor::render_section::operator()(const std::string& str) const {
return render_context(mstch::object{{".", str}}, context).render(section);
}
std::string visitor::render_section::operator()(const array& arr) const {
std::ostringstream out;
for (auto& item: arr)
out << render_context(mstch::object{{".", item}}, context)
.render(section);
return out.str();
}
std::string visitor::render_section::operator()(const object& obj) const {
return render_context(obj, context).render(section);
}
std::string visitor::render_section::operator()(const array& a) const {
std::ostringstream out;
if(flags.find(flag::keep_array) != flags.end())
out << render_context(mstch::object{{".", a}}, context).render(section);
else
for (auto& item: a)
out << boost::apply_visitor(
render_section(context, section, {flag::keep_array}), item);
return out.str();
}

View file

@ -4,17 +4,24 @@
#include <boost/variant/static_visitor.hpp>
#include <boost/blank.hpp>
#include <render_context.h>
#include <set>
#include "types.h"
namespace mstch {
namespace visitor {
class render_section: public boost::static_visitor<std::string> {
public:
enum class flag { keep_array };
private:
render_context& context;
std::string section;
std::set<flag> flags;
public:
render_section(render_context& context, const std::string& section);
render_section(
render_context& context,
const std::string& section,
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;