clooneljump/src/path.cpp
King_DuckZ bcc0937726 New code, WiP.
New Path, Character and other simple classes, but a renderer is missing so now nothing gets displayed anymore.
2014-02-12 00:27:55 +01:00

49 lines
1.5 KiB
C++

#include "path.hpp"
#include <cassert>
#include <sstream>
#include <ciso646>
namespace cloonel {
namespace {
///---------------------------------------------------------------------
///---------------------------------------------------------------------
std::string GetCleanBasePath (const std::string&& parPath) {
const size_t pathlen = parPath.size();
switch (pathlen) {
case 0:
return std::string("/");
case 1:
return parPath;
default:
if (parPath[pathlen - 1] == '/')
return parPath.substr(0, pathlen - 1);
else
return parPath;
}
}
} //unnamed namespace
///-------------------------------------------------------------------------
///-------------------------------------------------------------------------
Path::Path (const char* parBasePath) :
m_basePath(GetCleanBasePath(std::string(parBasePath)))
{
}
///-------------------------------------------------------------------------
///-------------------------------------------------------------------------
std::string Path::GetFullPath (const std::string& parPath) const {
std::ostringstream oss;
oss << m_basePath << '/' << parPath;
return oss.str();
}
///-------------------------------------------------------------------------
///-------------------------------------------------------------------------
std::string Path::GetFullPath (const char* parPath) const {
assert(parPath);
std::ostringstream oss;
oss << m_basePath << '/' << parPath;
return oss.str();
}
} // namespace cloonel