Add isAbsolute/isRelative predicates to SGPath.
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user