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
#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[]) {
bool rawdump = false;
bool apidump = false;
#ifndef _MSC_VER
int c;
while ((c = getopt(argc, argv, "da")) != -1) {
while ((c = getopt(argc, argv, "d")) != -1) {
switch (c) {
case 'd':
rawdump = true;
break;
case 'a':
apidump = true;
break;
default:
abort();
}
@ -72,33 +34,17 @@ int main(int argc, char *argv[]) {
std::cerr << "warning: ignoring everything after " << argv[optind + 1]
<< std::endl;
}
auto [p, error] = simdjson::padded_string::load(filename);
if (error) {
std::cerr << "Could not load the file " << filename << std::endl;
return EXIT_FAILURE;
}
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)
simdjson::document::parser parser;
auto [doc, error] = parser.load(filename); // do the parsing, return false on error
if (error != simdjson::SUCCESS) {
std::cerr << " Parsing failed. Error is '" << simdjson::error_message(error)
<< "'." << std::endl;
return EXIT_FAILURE;
}
if (apidump) {
simdjson::ParsedJson::Iterator pjh(pj.doc);
if (!pjh.is_ok()) {
std::cerr << " Could not iterate parsed result. " << std::endl;
return EXIT_FAILURE;
}
compute_dump(pjh);
if(rawdump) {
doc.dump_raw_tape(std::cout);
} else {
const bool is_ok =
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;
}
std::cout << doc;
}
return EXIT_SUCCESS;
}