diff --git a/include/inja/renderer.hpp b/include/inja/renderer.hpp index cd7f117..9c34025 100644 --- a/include/inja/renderer.hpp +++ b/include/inja/renderer.hpp @@ -41,19 +41,14 @@ class Renderer : public NodeVisitor { std::stack not_found_stack; bool truthy(const json* data) const { - if (data->empty()) { - return false; + if (data->is_boolean()) { + return data->get(); } else if (data->is_number()) { return (*data != 0); - } else if (data->is_string()) { - return !data->empty(); - } - - try { - return data->get(); - } catch (json::type_error &e) { - throw JsonError(e.what()); + } else if (data->is_null()) { + return false; } + return !data->empty(); } void print_json(const std::shared_ptr value) { @@ -71,7 +66,6 @@ class Renderer : public NodeVisitor { if (json_eval_stack.empty()) { throw_renderer_error("empty expression", expression_list); - } else if (json_eval_stack.size() != 1) { throw_renderer_error("malformed expression", expression_list); } diff --git a/single_include/inja/inja.hpp b/single_include/inja/inja.hpp index 9919003..30277b1 100644 --- a/single_include/inja/inja.hpp +++ b/single_include/inja/inja.hpp @@ -3345,19 +3345,14 @@ class Renderer : public NodeVisitor { std::stack not_found_stack; bool truthy(const json* data) const { - if (data->empty()) { - return false; + if (data->is_boolean()) { + return data->get(); } else if (data->is_number()) { return (*data != 0); - } else if (data->is_string()) { - return !data->empty(); - } - - try { - return data->get(); - } catch (json::type_error &e) { - throw JsonError(e.what()); + } else if (data->is_null()) { + return false; } + return !data->empty(); } void print_json(const std::shared_ptr value) { @@ -3375,7 +3370,6 @@ class Renderer : public NodeVisitor { if (json_eval_stack.empty()) { throw_renderer_error("empty expression", expression_list); - } else if (json_eval_stack.size() != 1) { throw_renderer_error("malformed expression", expression_list); }