From 70061329a11c6a76cf79dce30aae959d537b4594 Mon Sep 17 00:00:00 2001 From: elsid Date: Wed, 17 Jan 2024 23:32:15 +0100 Subject: [PATCH] Return Path::Normalized from RecursiveDirectoryIterator --- apps/niftest/niftest.cpp | 4 ++-- apps/opencs/model/world/resources.cpp | 15 +++++++-------- components/vfs/recursivedirectoryiterator.hpp | 4 ++-- 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/apps/niftest/niftest.cpp b/apps/niftest/niftest.cpp index 9352651030..ee6e84295f 100644 --- a/apps/niftest/niftest.cpp +++ b/apps/niftest/niftest.cpp @@ -113,9 +113,9 @@ void readVFS(std::unique_ptr&& archive, const std::filesystem::pat for (const auto& name : vfs.getRecursiveDirectoryIterator("")) { - if (isNIF(name)) + if (isNIF(name.value())) { - readNIF(archivePath, name, &vfs, quiet); + readNIF(archivePath, name.value(), &vfs, quiet); } } diff --git a/apps/opencs/model/world/resources.cpp b/apps/opencs/model/world/resources.cpp index 345f6008ec..9957af3d66 100644 --- a/apps/opencs/model/world/resources.cpp +++ b/apps/opencs/model/world/resources.cpp @@ -30,18 +30,18 @@ void CSMWorld::Resources::recreate(const VFS::Manager* vfs, const char* const* e for (const auto& filepath : vfs->getRecursiveDirectoryIterator("")) { - if (filepath.size() < baseSize + 1 || filepath.substr(0, baseSize) != mBaseDirectory - || (filepath[baseSize] != '/' && filepath[baseSize] != '\\')) + const std::string_view view = filepath.view(); + if (view.size() < baseSize + 1 || !view.starts_with(mBaseDirectory) || view[baseSize] != '/') continue; if (extensions) { - std::string::size_type extensionIndex = filepath.find_last_of('.'); + const auto extensionIndex = view.find_last_of('.'); - if (extensionIndex == std::string::npos) + if (extensionIndex == std::string_view::npos) continue; - std::string extension = filepath.substr(extensionIndex + 1); + std::string_view extension = view.substr(extensionIndex + 1); int i = 0; @@ -53,10 +53,9 @@ void CSMWorld::Resources::recreate(const VFS::Manager* vfs, const char* const* e continue; } - std::string file = filepath.substr(baseSize + 1); + std::string file(view.substr(baseSize + 1)); mFiles.push_back(file); - std::replace(file.begin(), file.end(), '\\', '/'); - mIndex.insert(std::make_pair(Misc::StringUtils::lowerCase(file), static_cast(mFiles.size()) - 1)); + mIndex.emplace(std::move(file), static_cast(mFiles.size()) - 1); } } diff --git a/components/vfs/recursivedirectoryiterator.hpp b/components/vfs/recursivedirectoryiterator.hpp index 39fb26e873..3410a2092b 100644 --- a/components/vfs/recursivedirectoryiterator.hpp +++ b/components/vfs/recursivedirectoryiterator.hpp @@ -16,9 +16,9 @@ namespace VFS { } - const std::string& operator*() const { return mIt->first.value(); } + const Path::Normalized& operator*() const { return mIt->first; } - const std::string* operator->() const { return &mIt->first.value(); } + const Path::Normalized* operator->() const { return &mIt->first; } RecursiveDirectoryIterator& operator++() {