diff --git a/Sources/Plasma/CoreLib/plString.cpp b/Sources/Plasma/CoreLib/plString.cpp index 833cd11b..54719892 100644 --- a/Sources/Plasma/CoreLib/plString.cpp +++ b/Sources/Plasma/CoreLib/plString.cpp @@ -946,3 +946,23 @@ plFileName plFileName::StripFileExt() const return *this; } + +plFileName plFileName::Join(const plFileName &base, const plFileName &path) +{ + if (base.IsEmpty()) + return path; + if (path.IsEmpty()) + return base; + + char last = base.CharAt(base.GetSize() - 1); + char first = path.CharAt(0); + if (last != '/' && last != '\\') { + if (first != '/' && first != '\\') + return plString::Format("%s" PATH_SEPARATOR_STR "%s", base.c_str(), path.c_str()); + return base + path; + } else if (first != '/' && first != '\\') { + return base + path; + } + // Both have a slash, but we only need one + return base + path.Substr(1); +} diff --git a/Sources/Plasma/CoreLib/plString.h b/Sources/Plasma/CoreLib/plString.h index 85b20710..8d8d8d08 100644 --- a/Sources/Plasma/CoreLib/plString.h +++ b/Sources/Plasma/CoreLib/plString.h @@ -657,6 +657,18 @@ private: size_t ustrlen(const UniChar *ustr, size_t max = plString::kSizeAuto); +#if HS_BUILD_FOR_WIN32 +# define PATH_SEPARATOR '\\' +# define WPATH_SEPARATOR L'\\' +# define PATH_SEPARATOR_STR "\\" +# define WPATH_SEPARATOR_STR L"\\" +#else +# define PATH_SEPARATOR '/' +# define WPATH_SEPARATOR L'/' +# define PATH_SEPARATOR_STR "/" +# define WPATH_SEPARATOR_STR L"/" +#endif + /* plFileName - custom extension of plString for manipulating filenames */ class plFileName : public plString { @@ -672,6 +684,17 @@ public: plFileName StripFileName() const; plFileName StripFileExt() const; + + static plFileName Join(const plFileName &base, const plFileName &path); + + // VS doesn't do variadic templates, and we don't want to use const char * + static plFileName Join(const plFileName &base, const plFileName &path, + const plFileName& path2) + { return Join(Join(base, path), path2); } + + static plFileName Join(const plFileName &base, const plFileName &path, + const plFileName& path2, const plFileName &path3) + { return Join(Join(Join(base, path), path2), path3); } }; #endif //plString_Defined diff --git a/Sources/Plasma/PubUtilLib/plFile/hsFiles.h b/Sources/Plasma/PubUtilLib/plFile/hsFiles.h index d9c2ed32..2217e734 100644 --- a/Sources/Plasma/PubUtilLib/plFile/hsFiles.h +++ b/Sources/Plasma/PubUtilLib/plFile/hsFiles.h @@ -54,19 +54,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #endif -#if HS_BUILD_FOR_WIN32 -# define PATH_SEPARATOR '\\' -# define WPATH_SEPARATOR L'\\' -# define PATH_SEPARATOR_STR "\\" -# define WPATH_SEPARATOR_STR L"\\" -#elif HS_BUILD_FOR_UNIX -# define PATH_SEPARATOR '/' -# define WPATH_SEPARATOR L'/' -# define PATH_SEPARATOR_STR "/" -# define WPATH_SEPARATOR_STR L"/" -#endif - - /////////////////////////////////////////////////////////////////////// class hsFile {