Check path for being normalized

ini_importer_tests
elsid 12 months ago
parent 199d97d32a
commit d549cfd66b
No known key found for this signature in database
GPG Key ID: 4DE04C198CBA7625

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

@ -15,6 +15,11 @@ namespace VFS::Path
return c == '\\' ? '/' : Misc::StringUtils::toLower(c); 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) inline void normalizeFilenameInPlace(std::string& name)
{ {
std::transform(name.begin(), name.end(), name.begin(), normalize); std::transform(name.begin(), name.end(), name.begin(), normalize);

Loading…
Cancel
Save