From 322320f816fa6572418bffda42e1529dafee02bf Mon Sep 17 00:00:00 2001 From: Stenzek Date: Mon, 19 Jan 2026 18:29:00 +1000 Subject: [PATCH] FileSystem: Backport 3-arg Path::Combine() --- src/common/file_system.cpp | 22 ++++++++++++++++++++++ src/common/path.h | 1 + 2 files changed, 23 insertions(+) diff --git a/src/common/file_system.cpp b/src/common/file_system.cpp index 48b71312c..f7d1bfa97 100644 --- a/src/common/file_system.cpp +++ b/src/common/file_system.cpp @@ -891,6 +891,28 @@ std::string Path::Combine(std::string_view base, std::string_view next) return ret; } +std::string Path::Combine(std::string_view base, std::string_view subdir, std::string_view next) +{ + std::string ret; + ret.reserve(base.length() + subdir.length() + next.length() + 2); + + PathAppendString(ret, base); + while (!ret.empty() && ret.back() == FS_OSPATH_SEPARATOR_CHARACTER) + ret.pop_back(); + + ret += FS_OSPATH_SEPARATOR_CHARACTER; + PathAppendString(ret, subdir); + while (!ret.empty() && ret.back() == FS_OSPATH_SEPARATOR_CHARACTER) + ret.pop_back(); + + ret += FS_OSPATH_SEPARATOR_CHARACTER; + PathAppendString(ret, next); + while (!ret.empty() && ret.back() == FS_OSPATH_SEPARATOR_CHARACTER) + ret.pop_back(); + + return ret; +} + std::FILE* FileSystem::OpenCFile(const char* path, const char* mode, Error* error) { #ifdef _WIN32 diff --git a/src/common/path.h b/src/common/path.h index cf781476c..b1d6af00c 100644 --- a/src/common/path.h +++ b/src/common/path.h @@ -27,6 +27,7 @@ std::string BuildRelativePath(std::string_view filename, std::string_view new_fi /// Joins path components together, producing a new path. std::string Combine(std::string_view base, std::string_view next); +std::string Combine(std::string_view base, std::string_view subdir, std::string_view next); /// Removes all .. and . components from a path. std::string Canonicalize(std::string_view path);