Skip to content

Commit

Permalink
make_update_expression
Browse files Browse the repository at this point in the history
  • Loading branch information
danielaparker committed Oct 27, 2023
1 parent e5507eb commit 00e9889
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
21 changes: 20 additions & 1 deletion include/jsoncons_ext/jsonpath/jsonpath_expression.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2653,7 +2653,7 @@ namespace detail {
}

template <class Json>
auto make_expression_for_update(const typename Json::string_view_type& path,
auto make_update_expression(const typename Json::string_view_type& path,
const jsoncons::jsonpath::custom_functions<Json>& funcs = jsoncons::jsonpath::custom_functions<Json>())
{
using jsonpath_traits_type = jsoncons::jsonpath::detail::jsonpath_traits<Json, Json&>;
Expand All @@ -2669,6 +2669,25 @@ namespace detail {
return jsoncons::jsonpath::jsonpath_expression<value_type,reference>(jsoncons::combine_allocators(), std::move(static_resources), std::move(expr));
}

template <class Json, class TempAllocator>
auto make_update_expression(const allocator_set<typename Json::allocator_type,TempAllocator>& alloc_set,
const typename Json::string_view_type& path,
const jsoncons::jsonpath::custom_functions<Json>& funcs, std::error_code& ec)
{
using jsonpath_traits_type = jsoncons::jsonpath::detail::jsonpath_traits<Json, Json&>;

using value_type = typename jsonpath_traits_type::value_type;
using reference = typename jsonpath_traits_type::reference;
using evaluator_type = typename jsonpath_traits_type::evaluator_type;

auto static_resources = jsoncons::make_unique<jsoncons::jsonpath::detail::static_resources<value_type,reference>>(funcs,
alloc_set.get_allocator());
evaluator_type evaluator{alloc_set.get_allocator()};
auto expr = evaluator.compile(*static_resources, path, ec);

return jsoncons::jsonpath::jsonpath_expression<value_type,reference>(alloc_set, std::move(static_resources), std::move(expr));
}

} // namespace jsonpath
} // namespace jsoncons

Expand Down
4 changes: 2 additions & 2 deletions test/jsonpath/src/jsonpath_make_expression_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ TEST_CASE("jsonpath make_expression test")

const json doc = json::parse(input);

auto expr = jsoncons::jsonpath::make_expression_for_update<json>("$.books[*]");
auto expr = jsoncons::jsonpath::make_update_expression<json>("$.books[*]");

auto callback = [&](const std::string& /*path*/, const json& book)
{
Expand All @@ -80,7 +80,7 @@ TEST_CASE("jsonpath make_expression test")

json doc = json::parse(input);

auto expr = jsoncons::jsonpath::make_expression_for_update<json>("$.books[*]");
auto expr = jsoncons::jsonpath::make_update_expression<json>("$.books[*]");

auto callback1 = [&](const std::string& /*path*/, const json& book)
{
Expand Down

0 comments on commit 00e9889

Please sign in to comment.