diff --git a/components/misc/resourcehelpers.cpp b/components/misc/resourcehelpers.cpp index eba3acdc7a..90cdcdb726 100644 --- a/components/misc/resourcehelpers.cpp +++ b/components/misc/resourcehelpers.cpp @@ -16,29 +16,16 @@ namespace { - - struct MatchPathSeparator - { - bool operator()(char ch) const { return ch == '\\' || ch == '/'; } - }; - - std::string getBasename(std::string const& pathname) - { - return std::string( - std::find_if(pathname.rbegin(), pathname.rend(), MatchPathSeparator()).base(), pathname.end()); - } - -} - -bool changeExtension(std::string& path, std::string_view ext) -{ - std::string::size_type pos = path.rfind('.'); - if (pos != std::string::npos && path.compare(pos, path.length() - pos, ext) != 0) + bool changeExtension(std::string& path, std::string_view ext) { - path.replace(pos, path.length(), ext); - return true; + std::string::size_type pos = path.rfind('.'); + if (pos != std::string::npos && path.compare(pos, path.length() - pos, ext) != 0) + { + path.replace(pos, path.length(), ext); + return true; + } + return false; } - return false; } bool Misc::ResourceHelpers::changeExtensionToDds(std::string& path) @@ -106,7 +93,8 @@ std::string Misc::ResourceHelpers::correctResourcePath( // fall back to a resource in the top level directory if it exists std::string fallback{ topLevelDirectories.front() }; fallback += '\\'; - fallback += getBasename(correctedPath); + fallback += Misc::getFileName(correctedPath); + if (vfs->exists(fallback)) return fallback; @@ -114,7 +102,7 @@ std::string Misc::ResourceHelpers::correctResourcePath( { fallback = topLevelDirectories.front(); fallback += '\\'; - fallback += getBasename(origExt); + fallback += Misc::getFileName(origExt); if (vfs->exists(fallback)) return fallback; }