Add EnsureExtension

This commit is contained in:
Georg Hagen
2025-05-30 20:01:17 +02:00
parent bb65670f48
commit 1d5b113a38
2 changed files with 16 additions and 0 deletions

View File

@@ -226,4 +226,18 @@ namespace OpenVulkano
return files; 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;
}
} }

View File

@@ -59,5 +59,7 @@ namespace OpenVulkano
[[nodiscard]] static std::string ToValidFileName(std::string filename); [[nodiscard]] static std::string ToValidFileName(std::string filename);
[[maybe_unused]] [[nodiscard]] static std::vector<std::filesystem::path> FilesWithExtension(const std::filesystem::path& dir, std::string ext); [[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);
}; };
} }