Skip to content

Commit

Permalink
Add support for boost::string_view
Browse files Browse the repository at this point in the history
  • Loading branch information
King_DuckZ committed Jun 6, 2017
1 parent 333869e commit 45122d1
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
3 changes: 2 additions & 1 deletion include/mstch/mstch.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include <boost/optional.hpp>
#include <boost/variant.hpp>
#include <boost/utility/string_view.hpp>

namespace mstch {

Expand Down Expand Up @@ -99,7 +100,7 @@ using node = boost::make_recursive_variant<
internal::lambda_t<boost::recursive_variant_>,
std::shared_ptr<internal::object_t<boost::recursive_variant_>>,
std::map<const std::string, boost::recursive_variant_>,
std::vector<boost::recursive_variant_>>::type;
std::vector<boost::recursive_variant_>, boost::string_view>::type;
using object = internal::object_t<node>;
using lambda = internal::lambda_t<node>;
using map = std::map<const std::string, node>;
Expand Down
6 changes: 5 additions & 1 deletion src/visitor/is_node_empty.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ class is_node_empty: public boost::static_visitor<bool> {
}

bool operator()(const std::string& value) const {
return value == "";
return value.empty();
}

bool operator()(const boost::string_view& value) const {
return value.empty();
}

bool operator()(const array& array) const {
Expand Down
4 changes: 4 additions & 0 deletions src/visitor/render_node.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ class render_node: public boost::static_visitor<std::string> {
return value ? "true" : "false";
}

std::string operator()(const boost::string_view& value) const {
return std::string(value);
}

std::string operator()(const lambda& value) const {
template_type interpreted{value([this](const mstch::node& n) {
return visit(render_node(m_ctx), n);
Expand Down

0 comments on commit 45122d1

Please sign in to comment.