diff --git a/openVulkanoCpp/IO/FsUtils.cpp b/openVulkanoCpp/IO/FsUtils.cpp index 2f8be50..7a7356e 100644 --- a/openVulkanoCpp/IO/FsUtils.cpp +++ b/openVulkanoCpp/IO/FsUtils.cpp @@ -226,4 +226,18 @@ namespace OpenVulkano return files; } + + std::string FsUtils::EnsureExtension(const std::string& fileName, const std::string_view& extension) + { + if (!extension.empty() && !Utils::EndsWith(fileName, extension)) + { + std::string name; + name.reserve(fileName.length() + 2 + extension.length()); + name += fileName; + if (extension[0] != '.') name += "."; + name += std::string(extension); + return name; + } + return fileName; + } } diff --git a/openVulkanoCpp/IO/FsUtils.hpp b/openVulkanoCpp/IO/FsUtils.hpp index e30756c..c0e2137 100644 --- a/openVulkanoCpp/IO/FsUtils.hpp +++ b/openVulkanoCpp/IO/FsUtils.hpp @@ -59,5 +59,7 @@ namespace OpenVulkano [[nodiscard]] static std::string ToValidFileName(std::string filename); [[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); }; }