diff --git a/include/jsoncons_ext/jsonpath/jsonpath_expression.hpp b/include/jsoncons_ext/jsonpath/jsonpath_expression.hpp index 61fdd4f1f..a6fb44cef 100644 --- a/include/jsoncons_ext/jsonpath/jsonpath_expression.hpp +++ b/include/jsoncons_ext/jsonpath/jsonpath_expression.hpp @@ -2653,7 +2653,7 @@ namespace detail { } template - 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& funcs = jsoncons::jsonpath::custom_functions()) { using jsonpath_traits_type = jsoncons::jsonpath::detail::jsonpath_traits; @@ -2669,6 +2669,25 @@ namespace detail { return jsoncons::jsonpath::jsonpath_expression(jsoncons::combine_allocators(), std::move(static_resources), std::move(expr)); } + template + auto make_update_expression(const allocator_set& alloc_set, + const typename Json::string_view_type& path, + const jsoncons::jsonpath::custom_functions& funcs, std::error_code& ec) + { + using jsonpath_traits_type = jsoncons::jsonpath::detail::jsonpath_traits; + + 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>(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(alloc_set, std::move(static_resources), std::move(expr)); + } + } // namespace jsonpath } // namespace jsoncons diff --git a/test/jsonpath/src/jsonpath_make_expression_tests.cpp b/test/jsonpath/src/jsonpath_make_expression_tests.cpp index 5f8c10d67..802f4277f 100644 --- a/test/jsonpath/src/jsonpath_make_expression_tests.cpp +++ b/test/jsonpath/src/jsonpath_make_expression_tests.cpp @@ -58,7 +58,7 @@ TEST_CASE("jsonpath make_expression test") const json doc = json::parse(input); - auto expr = jsoncons::jsonpath::make_expression_for_update("$.books[*]"); + auto expr = jsoncons::jsonpath::make_update_expression("$.books[*]"); auto callback = [&](const std::string& /*path*/, const json& book) { @@ -80,7 +80,7 @@ TEST_CASE("jsonpath make_expression test") json doc = json::parse(input); - auto expr = jsoncons::jsonpath::make_expression_for_update("$.books[*]"); + auto expr = jsoncons::jsonpath::make_update_expression("$.books[*]"); auto callback1 = [&](const std::string& /*path*/, const json& book) {