From b7b42786abc7820e5718a4c664964355293ca8cd Mon Sep 17 00:00:00 2001 From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com> Date: Fri, 28 Jul 2023 14:45:04 +0200 Subject: [PATCH] Add STL version of Appendslash --- r5dev/public/tier0/utility.h | 2 ++ r5dev/tier0/utility.cpp | 11 +++++++++++ 2 files changed, 13 insertions(+) diff --git a/r5dev/public/tier0/utility.h b/r5dev/public/tier0/utility.h index 425f4750..db25e910 100644 --- a/r5dev/public/tier0/utility.h +++ b/r5dev/public/tier0/utility.h @@ -33,6 +33,8 @@ string CreateTimedFileName(); string CreateUUID(); void CreateDirectories(string svInput, string* pszOutput = nullptr, bool bWindows = false); +void AppendSlash(string& svInput, const char separator = '\\'); + string ConvertToWinPath(const string& svInput); string ConvertToUnixPath(const string& svInput); diff --git a/r5dev/tier0/utility.cpp b/r5dev/tier0/utility.cpp index eb495ba9..cf7b5698 100644 --- a/r5dev/tier0/utility.cpp +++ b/r5dev/tier0/utility.cpp @@ -409,6 +409,17 @@ void CreateDirectories(string svInput, string* pszOutput, bool bWindows) fs::create_directories(fspPathOut); } +/////////////////////////////////////////////////////////////////////////////// +// For appending a slash at the end of the string if not already present. +void AppendSlash(string& svInput, const char separator) +{ + char lchar = svInput[svInput.size() - 1]; + if (lchar != '\\' && lchar != '/') + { + svInput.push_back(separator); + } +} + /////////////////////////////////////////////////////////////////////////////// // For converting file paths to windows file paths. string ConvertToWinPath(const string& svInput)