mirror of
https://github.com/simdjson/simdjson
synced 2026-06-08 17:27:07 +00:00
Style uniformization (#238)
* massive clang-format -style=LLVM * naming harmonization * adding commentary about sysinfoapi.h
This commit is contained in:
+31
-23
@@ -1,9 +1,8 @@
|
||||
#include <iostream>
|
||||
#include "simdjson/jsonioutil.h"
|
||||
#include "simdjson/jsonparser.h"
|
||||
#include <iostream>
|
||||
|
||||
|
||||
void compute_dump(simdjson::ParsedJson::iterator &pjh) {
|
||||
void compute_dump(simdjson::ParsedJson::Iterator &pjh) {
|
||||
if (pjh.is_object()) {
|
||||
std::cout << "{";
|
||||
if (pjh.down()) {
|
||||
@@ -40,9 +39,16 @@ void compute_dump(simdjson::ParsedJson::iterator &pjh) {
|
||||
int main(int argc, char *argv[]) {
|
||||
if (argc < 3) {
|
||||
std::cerr << "Usage: " << argv[0] << " <jsonfile> <jsonpath>" << std::endl;
|
||||
std::cerr << "Follows the rfc6901 standard's syntax: https://tools.ietf.org/html/rfc6901" << std::endl;
|
||||
std::cerr << " Example: " << argv[0] << " jsonexamples/small/demo.json /Image/Width /Image/Height /Image/IDs/2 " << std::endl;
|
||||
std::cerr << "Multiple <jsonpath> can be issued in the same command, but at least one is needed." << std::endl;
|
||||
std::cerr << "Follows the rfc6901 standard's syntax: "
|
||||
"https://tools.ietf.org/html/rfc6901"
|
||||
<< std::endl;
|
||||
std::cerr << " Example: " << argv[0]
|
||||
<< " jsonexamples/small/demo.json /Image/Width /Image/Height "
|
||||
"/Image/IDs/2 "
|
||||
<< std::endl;
|
||||
std::cerr << "Multiple <jsonpath> can be issued in the same command, but "
|
||||
"at least one is needed."
|
||||
<< std::endl;
|
||||
exit(1);
|
||||
}
|
||||
const char *filename = argv[1];
|
||||
@@ -54,31 +60,33 @@ int main(int argc, char *argv[]) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
simdjson::ParsedJson pj;
|
||||
bool allocok = pj.allocateCapacity(p.size(), 1024);
|
||||
bool allocok = pj.allocate_capacity(p.size(), 1024);
|
||||
if (!allocok) {
|
||||
std::cerr << "failed to allocate memory" << std::endl;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
int res = simdjson::json_parse(p, pj); // do the parsing, return false on error
|
||||
int res =
|
||||
simdjson::json_parse(p, pj); // do the parsing, return false on error
|
||||
if (res) {
|
||||
std::cerr << " Parsing failed with error " << simdjson::errorMsg(res) << std::endl;
|
||||
std::cerr << " Parsing failed with error " << simdjson::error_message(res)
|
||||
<< std::endl;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
std::cout << "[" << std::endl;
|
||||
for(int idx = 2; idx < argc; idx++) {
|
||||
const char * jsonpath = argv[idx];
|
||||
simdjson::ParsedJson::iterator it(pj);
|
||||
if(it.move_to(std::string(jsonpath))) {
|
||||
std::cout << "{\"jsonpath\": \"" << jsonpath << "\"," << std::endl;
|
||||
std::cout << "\"value\":";
|
||||
compute_dump(it);
|
||||
std::cout << "}" << std::endl;
|
||||
} else {
|
||||
std::cout << "null" << std::endl;
|
||||
}
|
||||
if(idx + 1 < argc) {
|
||||
std::cout << "," << std::endl;
|
||||
}
|
||||
for (int idx = 2; idx < argc; idx++) {
|
||||
const char *jsonpath = argv[idx];
|
||||
simdjson::ParsedJson::Iterator it(pj);
|
||||
if (it.move_to(std::string(jsonpath))) {
|
||||
std::cout << "{\"jsonpath\": \"" << jsonpath << "\"," << std::endl;
|
||||
std::cout << "\"value\":";
|
||||
compute_dump(it);
|
||||
std::cout << "}" << std::endl;
|
||||
} else {
|
||||
std::cout << "null" << std::endl;
|
||||
}
|
||||
if (idx + 1 < argc) {
|
||||
std::cout << "," << std::endl;
|
||||
}
|
||||
}
|
||||
std::cout << "]" << std::endl;
|
||||
return EXIT_SUCCESS;
|
||||
|
||||
Reference in New Issue
Block a user