From 376911f645faab557aca4be4f4c2dceccf2a2b16 Mon Sep 17 00:00:00 2001
From: elsid <elsid.mail@gmail.com>
Date: Fri, 18 Oct 2024 14:11:29 +0200
Subject: [PATCH] Reduce duplication for getting file name

---
 components/misc/resourcehelpers.cpp | 34 ++++++++++-------------------
 1 file changed, 11 insertions(+), 23 deletions(-)

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 changeExtension(std::string& path, std::string_view ext)
     {
-        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());
+        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;
     }
-
-}
-
-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)
-    {
-        path.replace(pos, path.length(), ext);
-        return true;
-    }
-    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;
     }