2020-06-13 05:57:45 +08:00
|
|
|
#include <iostream>
|
|
|
|
#include "simdjson.h"
|
|
|
|
#include "simdjson.cpp"
|
2020-07-25 18:02:19 +08:00
|
|
|
|
2020-06-13 05:57:45 +08:00
|
|
|
int main(int argc, char *argv[]) {
|
|
|
|
if(argc < 2) {
|
|
|
|
std::cerr << "Please specify at least one file name. " << std::endl;
|
2020-06-24 10:07:40 +08:00
|
|
|
return EXIT_FAILURE;
|
2020-06-13 05:57:45 +08:00
|
|
|
}
|
|
|
|
const char * filename = argv[1];
|
|
|
|
simdjson::dom::parser parser;
|
2020-08-19 06:25:36 +08:00
|
|
|
simdjson::dom::element elem;
|
2020-06-21 13:03:57 +08:00
|
|
|
auto error = parser.load(filename).get(elem); // do the parsing
|
2020-06-13 05:57:45 +08:00
|
|
|
if (error) {
|
|
|
|
std::cout << "parse failed" << std::endl;
|
|
|
|
std::cout << "error code: " << error << std::endl;
|
|
|
|
std::cout << error << std::endl;
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
} else {
|
2020-08-19 06:25:36 +08:00
|
|
|
std::cout << "parse valid: " << elem << std::endl;
|
2020-06-13 05:57:45 +08:00
|
|
|
}
|
|
|
|
if(argc == 2) {
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
// parse_many
|
|
|
|
const char * filename2 = argv[2];
|
2020-06-21 13:03:57 +08:00
|
|
|
simdjson::dom::document_stream stream;
|
|
|
|
error = parser.load_many(filename2).get(stream);
|
|
|
|
if (!error) {
|
|
|
|
for (auto result : stream) {
|
|
|
|
error = result.error();
|
|
|
|
}
|
2020-06-13 05:57:45 +08:00
|
|
|
}
|
|
|
|
if (error) {
|
|
|
|
std::cout << "parse_many failed" << std::endl;
|
|
|
|
std::cout << "error code: " << error << std::endl;
|
|
|
|
std::cout << error << std::endl;
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
} else {
|
|
|
|
std::cout << "parse_many valid" << std::endl;
|
|
|
|
}
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|
2020-06-26 08:07:17 +08:00
|
|
|
|