Add isAbsolute/isRelative predicates to SGPath.

This commit is contained in:
James Turner
2010-08-14 22:51:01 +01:00
parent 764a3c29e9
commit d7bea0c4c6
2 changed files with 29 additions and 0 deletions

View File

@@ -331,3 +331,21 @@ string_list sgPathSplit( const string &search_path ) {
return result;
}
bool SGPath::isAbsolute() const
{
if (path.empty()) {
return false;
}
#ifdef _WIN32
// detect '[A-Za-z]:/'
if (path.size() > 2) {
if (isalpha(path[0]) && (path[1] == ':') && (path[2] == sgDirPathSep)) {
return true;
}
}
#endif
return (path[0] == sgDirPathSep);
}

View File

@@ -147,6 +147,17 @@ public:
bool isFile() const;
bool isDir() const;
/**
* Opposite sense to isAbsolute
*/
bool isRelative() const { return !isAbsolute(); }
/**
* Is this an absolute path?
* I.e starts with a directory seperator, or a single character + colon
*/
bool isAbsolute() const;
private:
void fix();