Reduce duplication for getting file name

pull/3236/head
elsid 2 months ago
parent 3e804042c4
commit 376911f645
No known key found for this signature in database
GPG Key ID: 4DE04C198CBA7625

@ -16,20 +16,6 @@
namespace 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) bool changeExtension(std::string& path, std::string_view ext)
{ {
std::string::size_type pos = path.rfind('.'); std::string::size_type pos = path.rfind('.');
@ -40,6 +26,7 @@ bool changeExtension(std::string& path, std::string_view ext)
} }
return false; return false;
} }
}
bool Misc::ResourceHelpers::changeExtensionToDds(std::string& path) 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 // fall back to a resource in the top level directory if it exists
std::string fallback{ topLevelDirectories.front() }; std::string fallback{ topLevelDirectories.front() };
fallback += '\\'; fallback += '\\';
fallback += getBasename(correctedPath); fallback += Misc::getFileName(correctedPath);
if (vfs->exists(fallback)) if (vfs->exists(fallback))
return fallback; return fallback;
@ -114,7 +102,7 @@ std::string Misc::ResourceHelpers::correctResourcePath(
{ {
fallback = topLevelDirectories.front(); fallback = topLevelDirectories.front();
fallback += '\\'; fallback += '\\';
fallback += getBasename(origExt); fallback += Misc::getFileName(origExt);
if (vfs->exists(fallback)) if (vfs->exists(fallback))
return fallback; return fallback;
} }

Loading…
Cancel
Save