Add EnsureExtension
This commit is contained in:
@@ -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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user