remove try/catch from truthy

This commit is contained in:
pantor
2020-08-05 19:52:55 +02:00
parent 524edeb3c6
commit a138be46b6
2 changed files with 10 additions and 22 deletions

View File

@@ -41,19 +41,14 @@ class Renderer : public NodeVisitor {
std::stack<const JsonNode*> not_found_stack;
bool truthy(const json* data) const {
if (data->empty()) {
return false;
if (data->is_boolean()) {
return data->get<bool>();
} else if (data->is_number()) {
return (*data != 0);
} else if (data->is_string()) {
return !data->empty();
}
try {
return data->get<bool>();
} 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<json> 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);
}

View File

@@ -3345,19 +3345,14 @@ class Renderer : public NodeVisitor {
std::stack<const JsonNode*> not_found_stack;
bool truthy(const json* data) const {
if (data->empty()) {
return false;
if (data->is_boolean()) {
return data->get<bool>();
} else if (data->is_number()) {
return (*data != 0);
} else if (data->is_string()) {
return !data->empty();
}
try {
return data->get<bool>();
} 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<json> 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);
}