| 45 | namespace donut::json |
| 46 | { |
| 47 | bool LoadFromFile(IFileSystem& fs, const std::filesystem::path& jsonFileName, Json::Value& documentRoot) |
| 48 | { |
| 49 | std::shared_ptr<IBlob> data = fs.readFile(jsonFileName); |
| 50 | if (!data) |
| 51 | { |
| 52 | log::error("Couldn't read file %s", jsonFileName.generic_string().c_str()); |
| 53 | return false; |
| 54 | } |
| 55 | |
| 56 | Json::CharReaderBuilder builder; |
| 57 | builder["collectComments"] = false; |
| 58 | Json::CharReader* reader = builder.newCharReader(); |
| 59 | |
| 60 | const char* dataPtr = static_cast<const char*>(data->data()); |
| 61 | std::string errors; |
| 62 | bool success = reader->parse(dataPtr, dataPtr + data->size(), &documentRoot, &errors); |
| 63 | |
| 64 | if (!success) |
| 65 | { |
| 66 | log::error("Couldn't parse JSON file %s:\n%s", jsonFileName.generic_string().c_str(), errors.c_str()); |
| 67 | } |
| 68 | |
| 69 | delete reader; |
| 70 | |
| 71 | return success; |
| 72 | } |
| 73 | |
| 74 | template<> |
| 75 | std::string Read<std::string>(const Json::Value& node, const std::string& defaultValue) |
no test coverage detected