Selaa lähdekoodia

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 vuotta sitten
vanhempi
commit
d867e784c7
2 muutettua tiedostoa jossa 33 lisäystä ja 0 poistoa
  1. 20
    0
      filesystem.cpp
  2. 13
    0
      filesystem.hpp

+ 20
- 0
filesystem.cpp Näytä tiedosto

@@ -50,6 +50,19 @@ namespace CodeDweller {
char const FilePath::DirectorySeparator = '/';
#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 path;
@@ -59,6 +72,13 @@ namespace CodeDweller {
if (!path.empty() &&
path.back() != 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;

+ 13
- 0
filesystem.hpp Näytä tiedosto

@@ -43,6 +43,19 @@ namespace CodeDweller {
/// Directory separator character.
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.

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

Loading…
Peruuta
Tallenna