15191bae9SZane Shelley #include <util/data_file.hpp>
25191bae9SZane Shelley #include <valijson/adapters/nlohmann_json_adapter.hpp>
35191bae9SZane Shelley #include <valijson/schema.hpp>
45191bae9SZane Shelley #include <valijson/schema_parser.hpp>
55191bae9SZane Shelley #include <valijson/validator.hpp>
65191bae9SZane Shelley 
75191bae9SZane Shelley #include <regex>
85191bae9SZane Shelley 
95191bae9SZane Shelley namespace fs = std::filesystem;
105191bae9SZane Shelley 
115191bae9SZane Shelley namespace util
125191bae9SZane Shelley {
135191bae9SZane Shelley 
findFiles(const fs::path & i_dirPath,const std::string & i_matchString,std::vector<fs::path> & o_foundPaths)145191bae9SZane Shelley void findFiles(const fs::path& i_dirPath, const std::string& i_matchString,
155191bae9SZane Shelley                std::vector<fs::path>& o_foundPaths)
165191bae9SZane Shelley {
175191bae9SZane Shelley     if (fs::exists(i_dirPath))
185191bae9SZane Shelley     {
195191bae9SZane Shelley         std::regex search{i_matchString};
205191bae9SZane Shelley         for (const auto& file : fs::directory_iterator(i_dirPath))
215191bae9SZane Shelley         {
22*ee54c99fSZane Shelley             std::string filename = file.path().filename().string();
23*ee54c99fSZane Shelley             if (std::regex_search(filename, search))
245191bae9SZane Shelley             {
255191bae9SZane Shelley                 o_foundPaths.emplace_back(file.path());
265191bae9SZane Shelley             }
275191bae9SZane Shelley         }
285191bae9SZane Shelley     }
295191bae9SZane Shelley }
305191bae9SZane Shelley 
validateJson(const nlohmann::json & i_schema,const nlohmann::json & i_json)315191bae9SZane Shelley bool validateJson(const nlohmann::json& i_schema, const nlohmann::json& i_json)
325191bae9SZane Shelley {
335191bae9SZane Shelley     valijson::Schema schema;
345191bae9SZane Shelley     valijson::SchemaParser parser;
355191bae9SZane Shelley     valijson::adapters::NlohmannJsonAdapter schemaAdapter(i_schema);
365191bae9SZane Shelley     parser.populateSchema(schemaAdapter, schema);
375191bae9SZane Shelley 
385191bae9SZane Shelley     valijson::Validator validator;
395191bae9SZane Shelley     valijson::adapters::NlohmannJsonAdapter targetAdapter(i_json);
405191bae9SZane Shelley 
415191bae9SZane Shelley     return validator.validate(schema, targetAdapter, nullptr);
425191bae9SZane Shelley }
435191bae9SZane Shelley 
445191bae9SZane Shelley } // namespace util
45