static int parseAndSaveValueTree(const JSONCPP_STRING& input, const JSONCPP_STRING& actual, const JSONCPP_STRING& kind, const Json::Features& features, bool parseOnly, Json::Value* root) { Json::Reader reader(features); bool parsingSuccessful = reader.parse(input.data(), input.data() + input.size(), *root); if (!parsingSuccessful) { printf("Failed to parse %s file: \n%s\n", kind.c_str(), reader.getFormattedErrorMessages().c_str()); return 1; } if (!parseOnly) { FILE* factual = fopen(actual.c_str(), "wt"); if (!factual) { printf("Failed to create %s actual file.\n", kind.c_str()); return 2; } printValueTree(factual, *root); fclose(factual); } return 0; }
Json::Value getDOM(std::string const& path) { JSONCPP_STRING input = readInputTestFile(path.c_str()); if (input.empty()) { throw std::runtime_error("Empty input file"); } Json::Features mode = Json::Features::strictMode(); mode.allowComments_ = true; Json::Value root; Json::Reader reader(mode); bool parsingSuccessful = reader.parse(input.data(), input.data() + input.size(), root); if (!parsingSuccessful) { throw std::runtime_error( std::string("Failed to parse file: ") + reader.getFormattedErrorMessages()); } return root; }