diff --git a/include/jsoncons_ext/jsonpath/jsonpath_parser.hpp b/include/jsoncons_ext/jsonpath/jsonpath_parser.hpp index 1aa281f0b..f4b1ffa09 100644 --- a/include/jsoncons_ext/jsonpath/jsonpath_parser.hpp +++ b/include/jsoncons_ext/jsonpath/jsonpath_parser.hpp @@ -146,12 +146,12 @@ namespace detail { { } - std::size_t line() const + std::size_t line() const final { return line_; } - std::size_t column() const + std::size_t column() const final { return column_; } @@ -1446,20 +1446,19 @@ namespace detail { ec = jsonpath_errc::invalid_number; return path_expression_type(alloc_); } - else - { - int64_t n{0}; - auto r = jsoncons::detail::to_integer(buffer.data(), buffer.size(), n); - if (!r) - { - ec = jsonpath_errc::invalid_number; - return path_expression_type(alloc_); - } - push_token(resources, token_type(resources.new_selector(index_selector(n))), ec); - if (ec) {return path_expression_type(alloc_);} - buffer.clear(); + int64_t n{0}; + auto r = jsoncons::detail::to_integer(buffer.data(), buffer.size(), n); + if (!r) + { + ec = jsonpath_errc::invalid_number; + return path_expression_type(alloc_); } + push_token(resources, token_type(resources.new_selector(index_selector(n))), ec); + if (ec) {return path_expression_type(alloc_);} + + buffer.clear(); + push_token(resources, token_type(separator_arg), ec); if (ec) {return path_expression_type(alloc_);} buffer.clear(); @@ -1724,20 +1723,19 @@ namespace detail { ec = jsonpath_errc::invalid_number; return path_expression_type(alloc_); } - else + + int64_t n{0}; + auto r = jsoncons::detail::to_integer(buffer.data(), buffer.size(), n); + if (!r) { - int64_t n{0}; - auto r = jsoncons::detail::to_integer(buffer.data(), buffer.size(), n); - if (!r) - { - ec = jsonpath_errc::invalid_number; - return path_expression_type(alloc_); - } - push_token(resources, token_type(resources.new_selector(index_selector(n))), ec); - if (ec) {return path_expression_type(alloc_);} - - buffer.clear(); + ec = jsonpath_errc::invalid_number; + return path_expression_type(alloc_); } + push_token(resources, token_type(resources.new_selector(index_selector(n))), ec); + if (ec) {return path_expression_type(alloc_);} + + buffer.clear(); + state_stack_.pop_back(); // bracket_specifier break; } @@ -2120,7 +2118,9 @@ namespace detail { break; case '\r': if (p_+1 < end_input_ && *(p_+1) == '\n') + { ++p_; + } ++line_; column_ = 1; ++p_; diff --git a/include/jsoncons_ext/jsonpath/jsonpath_selector.hpp b/include/jsoncons_ext/jsonpath/jsonpath_selector.hpp index f01859aab..e8c5d2808 100644 --- a/include/jsoncons_ext/jsonpath/jsonpath_selector.hpp +++ b/include/jsoncons_ext/jsonpath/jsonpath_selector.hpp @@ -456,12 +456,14 @@ namespace detail { using path_generator_type = path_generator; using node_receiver_type = typename supertype::node_receiver_type; - current_node_selector() - { - } - + current_node_selector() = default; + current_node_selector(const current_node_selector&) = default; + current_node_selector(current_node_selector&&) = default; ~current_node_selector() = default; + current_node_selector& operator=(const current_node_selector&) = default; + current_node_selector& operator=(current_node_selector&&) = default; + void select(eval_context& context, reference root, const path_node_type& last, @@ -522,9 +524,14 @@ namespace detail { : ancestor_depth_(ancestor_depth) { } + parent_node_selector(const parent_node_selector&) = default; + parent_node_selector(parent_node_selector&&) = default; ~parent_node_selector() = default; + parent_node_selector& operator=(const parent_node_selector&) = default; + parent_node_selector& operator=(parent_node_selector&&) = default; + void select(eval_context& context, reference root, const path_node_type& last, @@ -624,7 +631,7 @@ namespace detail { auto slen = static_cast(current.size()); if (index_ >= 0 && index_ < slen) { - std::size_t i = static_cast(index_); + auto i = static_cast(index_); this->tail_select(context, root, path_generator_type::generate(context, last, i, options), current.at(i), receiver, options); @@ -634,7 +641,7 @@ namespace detail { int64_t index = slen + index_; if (index >= 0 && index < slen) { - std::size_t i = static_cast(index); + auto i = static_cast(index); this->tail_select(context, root, path_generator_type::generate(context, last, i, options), current.at(i), receiver, options); @@ -655,31 +662,22 @@ namespace detail { auto slen = static_cast(current.size()); if (index_ >= 0 && index_ < slen) { - std::size_t i = static_cast(index_); + auto i = static_cast(index_); return this->evaluate_tail(context, root, path_generator_type::generate(context, last, i, options), current.at(i), options, ec); } - else + int64_t index = slen + index_; + if (index >= 0 && index < slen) { - int64_t index = slen + index_; - if (index >= 0 && index < slen) - { - std::size_t i = static_cast(index); - return this->evaluate_tail(context, root, - path_generator_type::generate(context, last, i, options), - current.at(i), options, ec); - } - else - { - return context.null_value(); - } + auto i = static_cast(index); + return this->evaluate_tail(context, root, + path_generator_type::generate(context, last, i, options), + current.at(i), options, ec); } - } - else - { return context.null_value(); } + return context.null_value(); } }; @@ -1076,19 +1074,13 @@ namespace detail { std::size_t start = j.template as(); return this->evaluate_tail(context, root, last, current.at(start), options, ec); } - else if (j.is_string() && current.is_object()) + if (j.is_string() && current.is_object()) { return this->evaluate_tail(context, root, last, current.at(j.as_string_view()), options, ec); } - else - { - return context.null_value(); - } - } - else - { return context.null_value(); } + return context.null_value(); } std::string to_string(int level) const override @@ -1242,12 +1234,9 @@ namespace detail { if (!ec) { return this->evaluate_tail(context, root, last, *context.create_json(std::move(ref)), - options, ec); - } - else - { - return context.null_value(); + options, ec); } + return context.null_value(); } std::string to_string(int level) const override diff --git a/include/jsoncons_ext/jsonpath/path_node.hpp b/include/jsoncons_ext/jsonpath/path_node.hpp index d3b15a792..0db77ee38 100644 --- a/include/jsoncons_ext/jsonpath/path_node.hpp +++ b/include/jsoncons_ext/jsonpath/path_node.hpp @@ -35,19 +35,18 @@ namespace jsonpath { std::size_t size_; path_node_kind node_kind_; string_view_type name_; - std::size_t index_; + std::size_t index_{0}; public: basic_path_node() : parent_(nullptr), size_(1), - node_kind_(path_node_kind::root), - index_(0) + node_kind_(path_node_kind::root) { } basic_path_node(const basic_path_node* parent, string_view_type name) : parent_(parent), size_(parent == nullptr ? 1 : parent->size()+1), - node_kind_(path_node_kind::name), name_(name), index_(0) + node_kind_(path_node_kind::name), name_(name) { } @@ -57,23 +56,13 @@ namespace jsonpath { { } - basic_path_node(const basic_path_node& other) - : parent_(other.parent_), size_(other.size()), - node_kind_(other.node_kind_), - name_(other.name_), - index_(other.index_) - { - } + basic_path_node(const basic_path_node& other) = default; + basic_path_node(basic_path_node&& other) = default; + + ~basic_path_node() = default; - basic_path_node& operator=(const basic_path_node& other) - { - parent_ = other.parent_; - size_ = other.size(); - node_kind_ = other.node_kind_; - index_ = other.index_; - name_ = other.name_; - return *this; - } + basic_path_node& operator=(const basic_path_node& other) = default; + basic_path_node& operator=(basic_path_node&& other) = default; const basic_path_node* parent() const { return parent_;} @@ -97,7 +86,7 @@ namespace jsonpath { return index_; } - void swap(basic_path_node& node) + void swap(basic_path_node& node) noexcept { std::swap(parent_, node.parent_); std::swap(node_kind_, node.node_kind_);