1
0
mirror of https://foundry.openuru.org/gitblit/r/CWE-ou-minkata.git synced 2025-07-18 11:19:10 +00:00

Add plFileName::Join static method to join paths together correctly

This commit is contained in:
2013-01-13 13:25:54 -08:00
parent 01e25e5d8d
commit c52a1f1037
3 changed files with 43 additions and 13 deletions

View File

@ -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);
}

View File

@ -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

View File

@ -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 {