From 21e6740d38bbfc6a50e914336b6c05ee12892f40 Mon Sep 17 00:00:00 2001 From: Georg Hagen Date: Fri, 6 Jun 2025 14:34:35 +0200 Subject: [PATCH] Add function to check if a file contains a string --- openVulkanoCpp/IO/FsUtils.cpp | 19 +++++++++++++++++++ openVulkanoCpp/IO/FsUtils.hpp | 2 ++ 2 files changed, 21 insertions(+) diff --git a/openVulkanoCpp/IO/FsUtils.cpp b/openVulkanoCpp/IO/FsUtils.cpp index 7a7356e..0490d82 100644 --- a/openVulkanoCpp/IO/FsUtils.cpp +++ b/openVulkanoCpp/IO/FsUtils.cpp @@ -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; + } } diff --git a/openVulkanoCpp/IO/FsUtils.hpp b/openVulkanoCpp/IO/FsUtils.hpp index c0e2137..f56f7fe 100644 --- a/openVulkanoCpp/IO/FsUtils.hpp +++ b/openVulkanoCpp/IO/FsUtils.hpp @@ -61,5 +61,7 @@ namespace OpenVulkano [[maybe_unused]] [[nodiscard]] static std::vector 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); }; }