From 308e9ec25235bf816d6276ca020d58008d6c4cf3 Mon Sep 17 00:00:00 2001 From: Bobby Battista Date: Tue, 11 Aug 2026 11:19:50 -0400 Subject: [PATCH] refactor(lib): Add path separator helpers to PathUtil --- Core/Libraries/Include/Lib/PathUtil.h | 36 +++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/Core/Libraries/Include/Lib/PathUtil.h b/Core/Libraries/Include/Lib/PathUtil.h index 683f6fee130..ad3adc557ea 100644 --- a/Core/Libraries/Include/Lib/PathUtil.h +++ b/Core/Libraries/Include/Lib/PathUtil.h @@ -55,6 +55,38 @@ inline bool isAbsolutePath(const char* path) return false; } +inline char getNativePathSeparator() +{ +#ifdef _WIN32 + return '\\'; +#else + return '/'; +#endif +} + +inline Bool isAnyPathSeparator(char c) +{ + return c == '/' || c == '\\'; +} + +inline const char* getLastPathSeparator(const char* path) +{ + return maxPtr(strrchr(path, '/'), strrchr(path, '\\')); +} + +inline const wchar_t* getLastPathSeparator(const wchar_t* path) +{ + return maxPtr(wcsrchr(path, L'/'), wcsrchr(path, L'\\')); +} + +// Returns the whole path when it contains no separator +inline const char* getFileName(const char* path) +{ + const char* lastSeparator = getLastPathSeparator(path); + + return lastSeparator ? lastSeparator + 1 : path; +} + inline const char* getExtension(const char* path) { const char* lastDot = strrchr(path, '.'); @@ -64,7 +96,7 @@ inline const char* getExtension(const char* path) return nullptr; } - const char* lastSeparator = maxPtr(strrchr(path, '/'), strrchr(path, '\\')); + const char* lastSeparator = getLastPathSeparator(path); // Check if the dot is contained in the filename if (lastSeparator && lastDot < lastSeparator) @@ -84,7 +116,7 @@ inline const wchar_t* getExtension(const wchar_t* path) return nullptr; } - const wchar_t* lastSeparator = maxPtr(wcsrchr(path, L'/'), wcsrchr(path, L'\\')); + const wchar_t* lastSeparator = getLastPathSeparator(path); // Check if the dot is contained in the filename if (lastSeparator && lastDot < lastSeparator)