Add visit_primitive() helper in iterator
This commit is contained in:
parent
872127b722
commit
ce8d0f8135
|
@ -100,6 +100,11 @@ public:
|
|||
* Set ENABLE_LOGGING=true in logger.h to see logging.
|
||||
*/
|
||||
simdjson_really_inline void log_error(const char *error) const noexcept;
|
||||
|
||||
template<typename V>
|
||||
SIMDJSON_WARN_UNUSED simdjson_really_inline error_code visit_root_primitive(V &visitor, const uint8_t *value) noexcept;
|
||||
template<typename V>
|
||||
SIMDJSON_WARN_UNUSED simdjson_really_inline error_code visit_primitive(V &visitor, const uint8_t *value) noexcept;
|
||||
};
|
||||
|
||||
template<bool STREAMING, typename V>
|
||||
|
@ -272,6 +277,39 @@ simdjson_really_inline void json_iterator::log_error(const char *error) const no
|
|||
logger::log_line(*this, "", "ERROR", error);
|
||||
}
|
||||
|
||||
template<typename V>
|
||||
SIMDJSON_WARN_UNUSED simdjson_really_inline error_code json_iterator::visit_root_primitive(V &visitor, const uint8_t *value) noexcept {
|
||||
switch (*value) {
|
||||
case '"': return visitor.visit_root_string(*this, value);
|
||||
case 't': return visitor.visit_root_true_atom(*this, value);
|
||||
case 'f': return visitor.visit_root_false_atom(*this, value);
|
||||
case 'n': return visitor.visit_root_null_atom(*this, value);
|
||||
case '-':
|
||||
case '0': case '1': case '2': case '3': case '4':
|
||||
case '5': case '6': case '7': case '8': case '9':
|
||||
return visitor.visit_root_number(*this, value);
|
||||
default:
|
||||
log_error("Document starts with a non-value character");
|
||||
return TAPE_ERROR;
|
||||
}
|
||||
}
|
||||
template<typename V>
|
||||
SIMDJSON_WARN_UNUSED simdjson_really_inline error_code json_iterator::visit_primitive(V &visitor, const uint8_t *value) noexcept {
|
||||
switch (*value) {
|
||||
case '"': return visitor.visit_string(*this, value);
|
||||
case 't': return visitor.visit_true_atom(*this, value);
|
||||
case 'f': return visitor.visit_false_atom(*this, value);
|
||||
case 'n': return visitor.visit_null_atom(*this, value);
|
||||
case '-':
|
||||
case '0': case '1': case '2': case '3': case '4':
|
||||
case '5': case '6': case '7': case '8': case '9':
|
||||
return visitor.visit_number(*this, value);
|
||||
default:
|
||||
log_error("Non-value found when value was expected!");
|
||||
return TAPE_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace stage2
|
||||
} // namespace SIMDJSON_IMPLEMENTATION
|
||||
} // unnamed namespace
|
||||
|
|
|
@ -52,27 +52,29 @@ struct tape_builder {
|
|||
*/
|
||||
SIMDJSON_WARN_UNUSED simdjson_really_inline error_code visit_root_primitive(json_iterator &iter, const uint8_t *value) noexcept;
|
||||
|
||||
SIMDJSON_WARN_UNUSED simdjson_really_inline error_code visit_string(json_iterator &iter, const uint8_t *value, bool key = false) noexcept;
|
||||
SIMDJSON_WARN_UNUSED simdjson_really_inline error_code visit_number(json_iterator &iter, const uint8_t *value) noexcept;
|
||||
SIMDJSON_WARN_UNUSED simdjson_really_inline error_code visit_true_atom(json_iterator &iter, const uint8_t *value) noexcept;
|
||||
SIMDJSON_WARN_UNUSED simdjson_really_inline error_code visit_false_atom(json_iterator &iter, const uint8_t *value) noexcept;
|
||||
SIMDJSON_WARN_UNUSED simdjson_really_inline error_code visit_null_atom(json_iterator &iter, const uint8_t *value) noexcept;
|
||||
|
||||
SIMDJSON_WARN_UNUSED simdjson_really_inline error_code visit_root_string(json_iterator &iter, const uint8_t *value) noexcept;
|
||||
SIMDJSON_WARN_UNUSED simdjson_really_inline error_code visit_root_number(json_iterator &iter, const uint8_t *value) noexcept;
|
||||
SIMDJSON_WARN_UNUSED simdjson_really_inline error_code visit_root_true_atom(json_iterator &iter, const uint8_t *value) noexcept;
|
||||
SIMDJSON_WARN_UNUSED simdjson_really_inline error_code visit_root_false_atom(json_iterator &iter, const uint8_t *value) noexcept;
|
||||
SIMDJSON_WARN_UNUSED simdjson_really_inline error_code visit_root_null_atom(json_iterator &iter, const uint8_t *value) noexcept;
|
||||
|
||||
/** Called each time a new field or element in an array or object is found. */
|
||||
SIMDJSON_WARN_UNUSED simdjson_really_inline error_code increment_count(json_iterator &iter) noexcept;
|
||||
|
||||
private:
|
||||
/** Next location to write to tape */
|
||||
tape_writer tape;
|
||||
private:
|
||||
/** Next write location in the string buf for stage 2 parsing */
|
||||
uint8_t *current_string_buf_loc;
|
||||
|
||||
simdjson_really_inline tape_builder(dom::document &doc) noexcept;
|
||||
|
||||
SIMDJSON_WARN_UNUSED simdjson_really_inline error_code visit_string(json_iterator &iter, const uint8_t *value, bool key = false) noexcept;
|
||||
SIMDJSON_WARN_UNUSED simdjson_really_inline error_code visit_number(json_iterator &iter, const uint8_t *value) noexcept;
|
||||
SIMDJSON_WARN_UNUSED simdjson_really_inline error_code visit_root_number(json_iterator &iter, const uint8_t *value) noexcept;
|
||||
SIMDJSON_WARN_UNUSED simdjson_really_inline error_code visit_true_atom(json_iterator &iter, const uint8_t *value) noexcept;
|
||||
SIMDJSON_WARN_UNUSED simdjson_really_inline error_code visit_root_true_atom(json_iterator &iter, const uint8_t *value) noexcept;
|
||||
SIMDJSON_WARN_UNUSED simdjson_really_inline error_code visit_false_atom(json_iterator &iter, const uint8_t *value) noexcept;
|
||||
SIMDJSON_WARN_UNUSED simdjson_really_inline error_code visit_root_false_atom(json_iterator &iter, const uint8_t *value) noexcept;
|
||||
SIMDJSON_WARN_UNUSED simdjson_really_inline error_code visit_null_atom(json_iterator &iter, const uint8_t *value) noexcept;
|
||||
SIMDJSON_WARN_UNUSED simdjson_really_inline error_code visit_root_null_atom(json_iterator &iter, const uint8_t *value) noexcept;
|
||||
|
||||
simdjson_really_inline uint32_t next_tape_index(json_iterator &iter) const noexcept;
|
||||
simdjson_really_inline void start_container(json_iterator &iter) noexcept;
|
||||
SIMDJSON_WARN_UNUSED simdjson_really_inline error_code end_container(json_iterator &iter, internal::tape_type start, internal::tape_type end) noexcept;
|
||||
|
@ -92,34 +94,10 @@ SIMDJSON_WARN_UNUSED simdjson_really_inline error_code tape_builder::parse_docum
|
|||
}
|
||||
|
||||
SIMDJSON_WARN_UNUSED simdjson_really_inline error_code tape_builder::visit_root_primitive(json_iterator &iter, const uint8_t *value) noexcept {
|
||||
switch (*value) {
|
||||
case '"': return visit_string(iter, value);
|
||||
case 't': return visit_root_true_atom(iter, value);
|
||||
case 'f': return visit_root_false_atom(iter, value);
|
||||
case 'n': return visit_root_null_atom(iter, value);
|
||||
case '-':
|
||||
case '0': case '1': case '2': case '3': case '4':
|
||||
case '5': case '6': case '7': case '8': case '9':
|
||||
return visit_root_number(iter, value);
|
||||
default:
|
||||
iter.log_error("Document starts with a non-value character");
|
||||
return TAPE_ERROR;
|
||||
}
|
||||
return iter.visit_root_primitive(*this, value);
|
||||
}
|
||||
SIMDJSON_WARN_UNUSED simdjson_really_inline error_code tape_builder::visit_primitive(json_iterator &iter, const uint8_t *value) noexcept {
|
||||
switch (*value) {
|
||||
case '"': return visit_string(iter, value);
|
||||
case 't': return visit_true_atom(iter, value);
|
||||
case 'f': return visit_false_atom(iter, value);
|
||||
case 'n': return visit_null_atom(iter, value);
|
||||
case '-':
|
||||
case '0': case '1': case '2': case '3': case '4':
|
||||
case '5': case '6': case '7': case '8': case '9':
|
||||
return visit_number(iter, value);
|
||||
default:
|
||||
iter.log_error("Non-value found when value was expected!");
|
||||
return TAPE_ERROR;
|
||||
}
|
||||
return iter.visit_primitive(*this, value);
|
||||
}
|
||||
SIMDJSON_WARN_UNUSED simdjson_really_inline error_code tape_builder::visit_empty_object(json_iterator &iter) noexcept {
|
||||
return empty_container(iter, internal::tape_type::START_OBJECT, internal::tape_type::END_OBJECT);
|
||||
|
@ -176,6 +154,10 @@ SIMDJSON_WARN_UNUSED simdjson_really_inline error_code tape_builder::visit_strin
|
|||
return SUCCESS;
|
||||
}
|
||||
|
||||
SIMDJSON_WARN_UNUSED simdjson_really_inline error_code tape_builder::visit_root_string(json_iterator &iter, const uint8_t *value) noexcept {
|
||||
return visit_string(iter, value);
|
||||
}
|
||||
|
||||
SIMDJSON_WARN_UNUSED simdjson_really_inline error_code tape_builder::visit_number(json_iterator &iter, const uint8_t *value) noexcept {
|
||||
iter.log_value("number");
|
||||
if (!numberparsing::parse_number(value, tape)) { iter.log_error("Invalid number"); return NUMBER_ERROR; }
|
||||
|
|
Loading…
Reference in New Issue