blob: 5bc8c7d3462700ae93160391b0b9019880804c22 [file] [log] [blame]
Zane Shelley5191bae2021-08-04 22:48:28 -05001#include <util/data_file.hpp>
2#include <valijson/adapters/nlohmann_json_adapter.hpp>
3#include <valijson/schema.hpp>
4#include <valijson/schema_parser.hpp>
5#include <valijson/validator.hpp>
6
7#include <regex>
8
9namespace fs = std::filesystem;
10
11namespace util
12{
13
14void findFiles(const fs::path& i_dirPath, const std::string& i_matchString,
15 std::vector<fs::path>& o_foundPaths)
16{
17 if (fs::exists(i_dirPath))
18 {
19 std::regex search{i_matchString};
20 for (const auto& file : fs::directory_iterator(i_dirPath))
21 {
Zane Shelleyee54c992021-08-08 17:46:48 -050022 std::string filename = file.path().filename().string();
23 if (std::regex_search(filename, search))
Zane Shelley5191bae2021-08-04 22:48:28 -050024 {
25 o_foundPaths.emplace_back(file.path());
26 }
27 }
28 }
29}
30
31bool validateJson(const nlohmann::json& i_schema, const nlohmann::json& i_json)
32{
33 valijson::Schema schema;
34 valijson::SchemaParser parser;
35 valijson::adapters::NlohmannJsonAdapter schemaAdapter(i_schema);
36 parser.populateSchema(schemaAdapter, schema);
37
38 valijson::Validator validator;
39 valijson::adapters::NlohmannJsonAdapter targetAdapter(i_json);
40
41 return validator.validate(schema, targetAdapter, nullptr);
42}
43
44} // namespace util