Created
August 30, 2021 16:13
-
-
Save RauliL/54f7c8b5cf20c12b248159442e48b609 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <initializer_list> | |
#include <string> | |
std::string JoinPath(const std::initializer_list<std::string>& parts) | |
{ | |
#if defined(_WIN32) | |
static const char separator = '\\'; | |
#else | |
static const char separator = '/'; | |
#endif | |
std::string result; | |
for (const auto& part : parts) | |
{ | |
if (!result.empty() && result[result.length() - 1] != separator) | |
{ | |
result.append(1, separator); | |
} | |
result.append(part); | |
} | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment