From ad948b3606088a79cd66a873f01d26d01978f3bf Mon Sep 17 00:00:00 2001 From: MonkeybreadSoftware Date: Sun, 24 Sep 2023 10:31:20 +0200 Subject: [PATCH 1/5] Update json_visitor.hpp Avoid the warning from clang: out-of-line definition of constexpr static data member is redundant in C++17 and is deprecated --- include/jsoncons/json_visitor.hpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/include/jsoncons/json_visitor.hpp b/include/jsoncons/json_visitor.hpp index 693bd05b62..012909e56b 100644 --- a/include/jsoncons/json_visitor.hpp +++ b/include/jsoncons/json_visitor.hpp @@ -1515,6 +1515,9 @@ namespace jsoncons { } }; +#if __cplusplus >= 201703L +// not needed for C++17 +#else template constexpr C basic_json_diagnostics_visitor::visit_begin_array_name[]; template constexpr C basic_json_diagnostics_visitor::visit_end_array_name[]; template constexpr C basic_json_diagnostics_visitor::visit_begin_object_name[]; @@ -1528,6 +1531,7 @@ namespace jsoncons { template constexpr C basic_json_diagnostics_visitor::visit_int64_name[]; template constexpr C basic_json_diagnostics_visitor::visit_half_name[]; template constexpr C basic_json_diagnostics_visitor::visit_double_name[]; +#endif // C++17 check using json_visitor = basic_json_visitor; using wjson_visitor = basic_json_visitor; From 8f635ac7264b9c691c326dcbf0fd3947cf8aff49 Mon Sep 17 00:00:00 2001 From: MonkeybreadSoftware Date: Sun, 24 Sep 2023 10:32:25 +0200 Subject: [PATCH 2/5] Update source.hpp Avoid the warning from clang: out-of-line definition of constexpr static data member is redundant in C++17 and is deprecated --- include/jsoncons/source.hpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/include/jsoncons/source.hpp b/include/jsoncons/source.hpp index bae4385c5b..3ce0519616 100644 --- a/include/jsoncons/source.hpp +++ b/include/jsoncons/source.hpp @@ -781,8 +781,12 @@ namespace jsoncons { return length - unread; } }; +#if __cplusplus >= 201703L +// not needed for C++17 +#else template constexpr std::size_t source_reader::max_buffer_length; +#endif #if !defined(JSONCONS_NO_DEPRECATED) using bin_stream_source = binary_stream_source; From e36696661061a4642454ebb9620ec4f0ba1f6523 Mon Sep 17 00:00:00 2001 From: MonkeybreadSoftware Date: Sun, 24 Sep 2023 12:55:12 +0200 Subject: [PATCH 3/5] Update jsonpath_examples.cpp The original example returns empty result. If you use &&, the result works. --- examples/src/jsonpath_examples.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/src/jsonpath_examples.cpp b/examples/src/jsonpath_examples.cpp index 3dd97f44ce..0ffedb3554 100644 --- a/examples/src/jsonpath_examples.cpp +++ b/examples/src/jsonpath_examples.cpp @@ -59,7 +59,7 @@ void json_query_examples() std::cout << "(9)\n" << pretty_print(result9) << "\n"; // Intersection of book titles with category fiction and price < 15 - json result10 = jsonpath::json_query(booklist, "$.store.book[?(@.category == 'fiction')][?(@.price < 15)].title"); + json result10 = jsonpath::json_query(booklist, "$.store.book[?(@.category == 'fiction' && @.price < 15)].title")); std::cout << "(10)\n" << pretty_print(result10) << "\n"; // Normalized path expressions From ba4f04c2cd6bff4f42e233d277ba224462690fd9 Mon Sep 17 00:00:00 2001 From: MonkeybreadSoftware Date: Sun, 24 Sep 2023 14:59:36 +0200 Subject: [PATCH 4/5] Update json_query.md Changed examples 8 and 9 to match expression in jsonpath_examples.cpp file, so they parse well. --- doc/ref/jsonpath/json_query.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/ref/jsonpath/json_query.md b/doc/ref/jsonpath/json_query.md index de02e8a399..cd86b99ddb 100644 --- a/doc/ref/jsonpath/json_query.md +++ b/doc/ref/jsonpath/json_query.md @@ -174,11 +174,11 @@ int main() std::cout << "(7)\n" << pretty_print(result7) << "\n"; // Union of a subset of book titles identified by index - json result8 = jsonpath::json_query(root_value, "$.store[book[0].title,book[1].title,book[3].title]"); + json result8 = jsonpath::json_query(root_value, "$.store[@.book[0].title,@.book[1].title,@.book[3].title]"); std::cout << "(8)\n" << pretty_print(result8) << "\n"; // Union of third book title and all book titles with price > 10 - json result9 = jsonpath::json_query(root_value, "$.store[book[3].title,book[?(@.price > 10)].title]"); + json result9 = jsonpath::json_query(root_value, "$.store[@.book[3].title,@.book[?(@.price > 10)].title]"); std::cout << "(9)\n" << pretty_print(result9) << "\n"; // Intersection of book titles with category fiction and price < 15 From 54bff682e7b0c855b412e3c097b01b434dd97058 Mon Sep 17 00:00:00 2001 From: MonkeybreadSoftware Date: Sun, 24 Sep 2023 16:32:53 +0200 Subject: [PATCH 5/5] Update basic_json.hpp Added compare for bigint/bigdec/bigfloat as double or exact text match. --- include/jsoncons/basic_json.hpp | 47 +++++++++++++++++++++++++-------- 1 file changed, 36 insertions(+), 11 deletions(-) diff --git a/include/jsoncons/basic_json.hpp b/include/jsoncons/basic_json.hpp index 24a1049e18..e94c85e83a 100644 --- a/include/jsoncons/basic_json.hpp +++ b/include/jsoncons/basic_json.hpp @@ -3088,17 +3088,42 @@ namespace jsoncons { break; case json_storage_kind::short_string_value: case json_storage_kind::long_string_value: - switch (rhs.storage_kind()) - { - case json_storage_kind::short_string_value: - return as_string_view().compare(rhs.as_string_view()); - case json_storage_kind::long_string_value: - return as_string_view().compare(rhs.as_string_view()); - case json_storage_kind::json_const_pointer: - return compare(*(rhs.cast().value())); - default: - return static_cast(storage_kind()) - static_cast((int)rhs.storage_kind()); - } + switch (tag()) + { + case semantic_tag::bigint: + case semantic_tag::bigdec: + case semantic_tag::bigfloat: + { + // same text -> equal + if (rhs.storage_kind() == json_storage_kind::short_string_value || rhs.storage_kind() == json_storage_kind::long_string_value) + { + int compareString = as_string_view().compare(rhs.as_string_view()); + if (compareString == 0) + { + return 0; + } + } + + // compare big numbers as double + auto r = as() - rhs.as(); + return r == 0 ? 0 : (r < 0.0 ? -1 : 1); + } + default: + { + // compare regular text + switch (rhs.storage_kind()) + { + case json_storage_kind::short_string_value: + return as_string_view().compare(rhs.as_string_view()); + case json_storage_kind::long_string_value: + return as_string_view().compare(rhs.as_string_view()); + case json_storage_kind::json_const_pointer: + return compare(*(rhs.cast().value())); + default: + return static_cast(storage_kind()) - static_cast((int)rhs.storage_kind()); + } + } + } break; case json_storage_kind::byte_string_value: switch (rhs.storage_kind())