Rename pj -> doc, fix a few other idioms

This commit is contained in:
John Keiser 2020-03-27 09:22:46 -07:00
parent e3efbcddc1
commit 90a7503181
5 changed files with 16 additions and 34 deletions

View File

@ -33,19 +33,15 @@ static void parse_and_validate(const std::string src, T expected) {
std::cout << "src: " << src << ", ";
const padded_string pstr{src};
simdjson::document::parser parser;
auto [pj, error] = parser.parse(pstr);
if(error) {
printf("could not parse\n");
abort();
}
bool result;
if constexpr (std::is_same<int64_t, T>::value) {
int64_t actual = pj.root().as_object()["key"].as_int64_t();
auto [actual, error] = parser.parse(pstr).as_object()["key"].as_int64_t();
if (error) { std::cerr << error << std::endl; abort(); }
result = (expected == actual);
} else {
uint64_t actual = pj.root().as_object()["key"].as_uint64_t();
auto [actual, error] = parser.parse(pstr).as_object()["key"].as_uint64_t();
if (error) { std::cerr << error << std::endl; abort(); }
result = (expected == actual);
}
std::cout << std::boolalpha << "test: " << result << std::endl;
@ -59,31 +55,20 @@ static bool parse_and_check_signed(const std::string src) {
std::cout << "src: " << src << ", expecting signed" << std::endl;
const padded_string pstr{src};
simdjson::document::parser parser;
auto [pj, error] = parser.parse(pstr);
if(error) {
printf("could not parse\n");
abort();
}
auto [v,e] = pj.root().as_object()["key"];
return v.is_integer() && v.is_number();
auto [value, error] = parser.parse(pstr).as_object()["key"];
if (error) { std::cerr << error << std::endl; abort(); }
return value.is_integer() && value.is_number();
}
static bool parse_and_check_unsigned(const std::string src) {
std::cout << "src: " << src << ", expecting signed" << std::endl;
const padded_string pstr{src};
simdjson::document::parser parser;
auto [pj, error] = parser.parse(pstr);
if(error) {
printf("could not parse\n");
abort();
}
auto [v,e] = pj.root().as_object()["key"];
return v.is_unsigned_integer() && v.is_number();
auto [value, error] = parser.parse(pstr).as_object()["key"];
if (error) { std::cerr << error << std::endl; abort(); }
return value.is_unsigned_integer() && value.is_number();
}
int main() {
using std::numeric_limits;
constexpr auto int64_max = numeric_limits<int64_t>::max();

View File

@ -70,7 +70,7 @@ bool validate(const char *dirname) {
return EXIT_FAILURE;
}
simdjson::document::parser parser;
auto [pj, errorcode] = parser.parse(p);
auto [doc, errorcode] = parser.parse(p);
++how_many;
printf("%s\n", errorcode == simdjson::error_code::SUCCESS ? "ok" : "invalid");
if (contains("EXCLUDE", name)) {

View File

@ -179,7 +179,7 @@ bool validate(const char *dirname) {
invalid_count = 0;
total_count += float_count + int_count + invalid_count;
simdjson::document::parser parser;
auto [pj, err] = parser.parse(p);
auto [doc, err] = parser.parse(p);
bool isok = (err == simdjson::error_code::SUCCESS);
if (int_count + float_count + invalid_count > 0) {
printf("File %40s %s --- integers: %10zu floats: %10zu invalid: %10zu "

View File

@ -8,12 +8,9 @@ int main() {
const char *filename = JSON_TEST_PATH;
padded_string p = get_corpus(filename);
document::parser parser;
auto [pj, errorcode] = parser.parse(p);
if(errorcode != error_code::SUCCESS) {
std::cerr << error_message(errorcode) << std::endl;
return EXIT_FAILURE;
}
if(!pj.is_valid()) {
auto [doc, error] = parser.parse(p);
if(error) {
std::cerr << error << std::endl;
return EXIT_FAILURE;
}
return EXIT_SUCCESS;

View File

@ -348,7 +348,7 @@ bool validate(const char *dirname) {
total_string_length = 0;
empty_string = 0;
simdjson::document::parser parser;
auto [pj, err] = parser.parse(p);
auto [doc, err] = parser.parse(p);
bool isok = (err == simdjson::error_code::SUCCESS);
free(big_buffer);
if (good_string > 0) {