add initial Path class
This commit is contained in:
1 parent
b58c344604
commit
1f9a981e6a
3 files changed
+109
No files matched your search
@@ -0,0 +1,33 @@
|
||||
#include "Path.h"
|
||||
|
||||
std::string Path::dirname(const std::string & s)
|
||||
{
|
||||
size_t pos = s.find_last_of("/\\");
|
||||
if (pos == std::string::npos)
|
||||
{
|
||||
return ".";
|
||||
}
|
||||
if ((pos == 0u) || (pos == 2u && s[1] == ':'))
|
||||
{
|
||||
return std::string(s, 0, pos + 1u);
|
||||
}
|
||||
return std::string(s, 0, pos);
|
||||
}
|
||||
|
||||
std::string Path::join(const std::string & first, const std::string & second)
|
||||
{
|
||||
if (first == "")
|
||||
{
|
||||
return second;
|
||||
}
|
||||
if (second == "")
|
||||
{
|
||||
return first;
|
||||
}
|
||||
char last = first[first.size() - 1u];
|
||||
if ((last == '/') || (last == '\\'))
|
||||
{
|
||||
return first + second;
|
||||
}
|
||||
return first + "/" + second;
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
#ifndef PATH_H
|
||||
#define PATH_H
|
||||
|
||||
#include <string>
|
||||
|
||||
class Path
|
||||
{
|
||||
public:
|
||||
static std::string dirname(const std::string & s);
|
||||
static std::string join(const std::string & first, const std::string & second);
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in new issue
Block a user