Fixes issue 598. (#608)

* Fixes issue 598.

* Dropping old code.
This commit is contained in:
Daniel Lemire 2020-03-25 11:22:16 -04:00 committed by GitHub
parent 06d6636b97
commit 65f999b7b7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 62 deletions

View File

@ -4,55 +4,17 @@
#endif #endif
#include "simdjson.h" #include "simdjson.h"
void compute_dump(simdjson::ParsedJson::Iterator &pjh) {
if (pjh.is_object()) {
std::cout << "{";
if (pjh.down()) {
pjh.print(std::cout); // must be a string
std::cout << ":";
pjh.next();
compute_dump(pjh); // let us recurse
while (pjh.next()) {
std::cout << ",";
pjh.print(std::cout);
std::cout << ":";
pjh.next();
compute_dump(pjh); // let us recurse
}
pjh.up();
}
std::cout << "}";
} else if (pjh.is_array()) {
std::cout << "[";
if (pjh.down()) {
compute_dump(pjh); // let us recurse
while (pjh.next()) {
std::cout << ",";
compute_dump(pjh); // let us recurse
}
pjh.up();
}
std::cout << "]";
} else {
pjh.print(std::cout); // just print the lone value
}
}
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
bool rawdump = false; bool rawdump = false;
bool apidump = false;
#ifndef _MSC_VER #ifndef _MSC_VER
int c; int c;
while ((c = getopt(argc, argv, "da")) != -1) { while ((c = getopt(argc, argv, "d")) != -1) {
switch (c) { switch (c) {
case 'd': case 'd':
rawdump = true; rawdump = true;
break; break;
case 'a':
apidump = true;
break;
default: default:
abort(); abort();
} }
@ -72,33 +34,17 @@ int main(int argc, char *argv[]) {
std::cerr << "warning: ignoring everything after " << argv[optind + 1] std::cerr << "warning: ignoring everything after " << argv[optind + 1]
<< std::endl; << std::endl;
} }
auto [p, error] = simdjson::padded_string::load(filename); simdjson::document::parser parser;
if (error) { auto [doc, error] = parser.load(filename); // do the parsing, return false on error
std::cerr << "Could not load the file " << filename << std::endl; if (error != simdjson::SUCCESS) {
return EXIT_FAILURE; std::cerr << " Parsing failed. Error is '" << simdjson::error_message(error)
}
simdjson::ParsedJson pj;
int res =
simdjson::json_parse(p, pj); // do the parsing, return false on error
if (res != simdjson::SUCCESS) {
std::cerr << " Parsing failed. Error is '" << simdjson::error_message(res)
<< "'." << std::endl; << "'." << std::endl;
return EXIT_FAILURE; return EXIT_FAILURE;
} }
if (apidump) { if(rawdump) {
simdjson::ParsedJson::Iterator pjh(pj.doc); doc.dump_raw_tape(std::cout);
if (!pjh.is_ok()) {
std::cerr << " Could not iterate parsed result. " << std::endl;
return EXIT_FAILURE;
}
compute_dump(pjh);
} else { } else {
const bool is_ok = std::cout << doc;
rawdump ? pj.dump_raw_tape(std::cout) : pj.print_json(std::cout);
if (!is_ok) {
std::cerr << " Could not print out parsed result. " << std::endl;
return EXIT_FAILURE;
}
} }
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }