Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
danielaparker committed Sep 25, 2023
2 parents 27700e0 + 2035db8 commit 251061a
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 14 deletions.
4 changes: 2 additions & 2 deletions doc/ref/jsonpath/json_query.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion examples/src/jsonpath_examples.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
47 changes: 36 additions & 11 deletions include/jsoncons/basic_json.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<json_const_pointer_storage>().value()));
default:
return static_cast<int>(storage_kind()) - static_cast<int>((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<double>() - rhs.as<double>();
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<json_const_pointer_storage>().value()));
default:
return static_cast<int>(storage_kind()) - static_cast<int>((int)rhs.storage_kind());
}
}
}
break;
case json_storage_kind::byte_string_value:
switch (rhs.storage_kind())
Expand Down
4 changes: 4 additions & 0 deletions include/jsoncons/json_visitor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1515,6 +1515,9 @@ namespace jsoncons {
}
};

#if __cplusplus >= 201703L
// not needed for C++17
#else
template <class C> constexpr C basic_json_diagnostics_visitor<C>::visit_begin_array_name[];
template <class C> constexpr C basic_json_diagnostics_visitor<C>::visit_end_array_name[];
template <class C> constexpr C basic_json_diagnostics_visitor<C>::visit_begin_object_name[];
Expand All @@ -1528,6 +1531,7 @@ namespace jsoncons {
template <class C> constexpr C basic_json_diagnostics_visitor<C>::visit_int64_name[];
template <class C> constexpr C basic_json_diagnostics_visitor<C>::visit_half_name[];
template <class C> constexpr C basic_json_diagnostics_visitor<C>::visit_double_name[];
#endif // C++17 check

using json_visitor = basic_json_visitor<char>;
using wjson_visitor = basic_json_visitor<wchar_t>;
Expand Down
4 changes: 4 additions & 0 deletions include/jsoncons/source.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -781,8 +781,12 @@ namespace jsoncons {
return length - unread;
}
};
#if __cplusplus >= 201703L
// not needed for C++17
#else
template <class Source>
constexpr std::size_t source_reader<Source>::max_buffer_length;
#endif

#if !defined(JSONCONS_NO_DEPRECATED)
using bin_stream_source = binary_stream_source;
Expand Down

0 comments on commit 251061a

Please sign in to comment.