Return errors immediately instead of using goto

This commit is contained in:
John Keiser
2020-07-28 10:20:59 -07:00
parent 86162aaddb
commit 66a68ce264
6 changed files with 89 additions and 145 deletions
+4 -5
View File
@@ -144,13 +144,12 @@ WARN_UNUSED bool implementation::validate_utf8(const char *buf, size_t len) cons
}
WARN_UNUSED error_code dom_parser_implementation::stage2(dom::document &_doc) noexcept {
error_code result = stage2::parse_structurals<false>(*this, _doc);
if (result) { return result; }
if (auto error = stage2::parse_structurals<false>(*this, _doc)) { return error; }
// If we didn't make it to the end, it's an error
if ( next_structural_index != n_structural_indexes ) {
logger::log_string("More than one JSON value at the root of the document, or extra characters at the end of the JSON!");
return error = TAPE_ERROR;
return TAPE_ERROR;
}
return SUCCESS;
@@ -161,8 +160,8 @@ WARN_UNUSED error_code dom_parser_implementation::stage2_next(dom::document &_do
}
WARN_UNUSED error_code dom_parser_implementation::parse(const uint8_t *_buf, size_t _len, dom::document &_doc) noexcept {
error_code err = stage1(_buf, _len, false);
if (err) { return err; }
auto error = stage1(_buf, _len, false);
if (error) { return error; }
return stage2(_doc);
}