mirror of
https://github.com/OpenMW/openmw.git
synced 2025-04-01 22:36:39 +00:00
Check path for being normalized
This commit is contained in:
parent
199d97d32a
commit
d549cfd66b
2 changed files with 7 additions and 0 deletions
|
@ -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…
Reference in a new issue