Browse Source

Implemented FilePath::isAbsolute().


git-svn-id: https://svn.microneil.com/svn/CodeDweller/branches/adeniz_1@88 d34b734f-a00e-4b39-a726-e4eeb87269ab
adeniz_1
adeniz 9 years ago
parent
commit
d867e784c7
2 changed files with 33 additions and 0 deletions
  1. 20
    0
      filesystem.cpp
  2. 13
    0
      filesystem.hpp

+ 20
- 0
filesystem.cpp View File

char const FilePath::DirectorySeparator = '/'; char const FilePath::DirectorySeparator = '/';
#endif #endif
bool FilePath::isAbsolute(std::string const &path) {
#ifdef _WIN32
return PathIsRelative(path.c_str());
#else
if (path.empty()) {
return false;
}
return ('/' == path[0]);
#endif
}
std::string FilePath::join(std::initializer_list<std::string> components) { std::string FilePath::join(std::initializer_list<std::string> components) {
std::string path; std::string path;
if (!path.empty() && if (!path.empty() &&
path.back() != FilePath::DirectorySeparator) { path.back() != FilePath::DirectorySeparator) {
path += FilePath::DirectorySeparator; path += FilePath::DirectorySeparator;
if (isAbsolute(component)) {
throw std::invalid_argument("Attempted to use absolute path \"" +
component + "\" where a relative path "
"is required.");
}
} }
path += component; path += component;

+ 13
- 0
filesystem.hpp View File

/// Directory separator character. /// Directory separator character.
static char const DirectorySeparator; static char const DirectorySeparator;



/** Check whether a path is absolute.

This method whether the specified path is absolute or not.

@param[in] path is the path to check.

@returns true if the path is an absolute path, false
otherwise.

*/
static bool isAbsolute(std::string const &path);

/** Join path components. /** Join path components.


This method joins a veriable number of std::string inputs to This method joins a veriable number of std::string inputs to

Loading…
Cancel
Save