xmake.lua 2.5 KB

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