xmake.lua 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package("jsoncons")
  2. set_homepage("https://danielaparker.github.io/jsoncons/")
  3. set_description("A C++, header-only library for constructing JSON and JSON-like data formats, with JSON Pointer, JSON Patch, JSONPath, JMESPath, CSV, MessagePack, CBOR, BSON, UBJSON")
  4. set_urls("https://github.com/danielaparker/jsoncons/archive/$(version).zip",
  5. "https://github.com/danielaparker/jsoncons.git")
  6. add_versions("v0.158.0", "7ad7cc0e9c74df495dd16b818758ec2e2a5b7fef8f1852841087fd5e8bb6a6cb")
  7. on_install(function (package)
  8. os.cp("include", package:installdir())
  9. end)
  10. on_test(function (package)
  11. assert(package:check_cxxsnippets({test = [[
  12. #include <iostream>
  13. #include <string>
  14. using namespace jsoncons;
  15. std::string data = R"(
  16. {
  17. "application": "hiking",
  18. "reputons":
  19. [
  20. {
  21. "rater": "HikingAsylum",
  22. "assertion": "advanced",
  23. "rated": "Marilyn C",
  24. "rating": 0.90,
  25. "generated": 1514862245
  26. }
  27. ]
  28. }
  29. )";
  30. void test() {
  31. json j = json::parse(data);
  32. std::cout << "(1) " << std::boolalpha << j.contains("reputons") << "\n\n";
  33. const json &v = j["reputons"];
  34. for (const auto &item : v.array_range()) {
  35. // Access rated as string and rating as double
  36. std::cout << item["rated"].as<std::string>() << ", "
  37. << item["rating"].as<double>() << "\n";
  38. }
  39. std::cout << "\n";
  40. std::cout << "(3)\n";
  41. json result = jsonpath::json_query(j, "$..rated");
  42. std::cout << pretty_print(result) << "\n\n";
  43. std::cout << "(4)\n" << pretty_print(j) << "\n\n";
  44. }
  45. ]]}, {configs = {languages = "c++11"}, includes = {"jsoncons/json.hpp", "jsoncons_ext/jsonpath/jsonpath.hpp"}}))
  46. end)