Add function to check if a file contains a string
This commit is contained in:
@@ -240,4 +240,23 @@ namespace OpenVulkano
|
||||
}
|
||||
return fileName;
|
||||
}
|
||||
|
||||
bool FsUtils::FileContains(const std::filesystem::path& path, const std::string_view& searchString)
|
||||
{
|
||||
std::ifstream file(path);
|
||||
if (!file.is_open())
|
||||
{
|
||||
Logger::FILESYS->error("Could not open file: {}", path);
|
||||
return false;
|
||||
}
|
||||
std::string line;
|
||||
while (std::getline(file, line))
|
||||
{
|
||||
if (line.find(searchString) != std::string::npos)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,5 +61,7 @@ namespace OpenVulkano
|
||||
[[maybe_unused]] [[nodiscard]] static std::vector<std::filesystem::path> FilesWithExtension(const std::filesystem::path& dir, std::string ext);
|
||||
|
||||
[[nodiscard]] static std::string EnsureExtension(const std::string& filename, const std::string_view& extension);
|
||||
|
||||
[[nodiscard]] static bool FileContains(const std::filesystem::path& path, const std::string_view& searchString);
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user