1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-01-16 15:29:55 +00:00

Check path for being normalized

This commit is contained in:
elsid 2024-01-16 23:53:55 +01:00
parent 199d97d32a
commit d549cfd66b
No known key found for this signature in database
GPG key ID: 4DE04C198CBA7625
2 changed files with 7 additions and 0 deletions

View file

@ -1,6 +1,7 @@
#include "manager.hpp"
#include <algorithm>
#include <cassert>
#include <stdexcept>
#include <components/files/conversion.hpp>
@ -44,6 +45,7 @@ namespace VFS
Files::IStreamPtr Manager::getNormalized(std::string_view normalizedName) const
{
assert(Path::isNormalized(normalizedName));
const auto found = mIndex.find(normalizedName);
if (found == mIndex.end())
throw std::runtime_error("Resource '" + std::string(normalizedName) + "' not found");

View file

@ -15,6 +15,11 @@ namespace VFS::Path
return c == '\\' ? '/' : Misc::StringUtils::toLower(c);
}
inline constexpr bool isNormalized(std::string_view name)
{
return std::all_of(name.begin(), name.end(), [](char v) { return v == normalize(v); });
}
inline void normalizeFilenameInPlace(std::string& name)
{
std::transform(name.begin(), name.end(), name.begin(), normalize);