From: James Turner Date: Sat, 14 Aug 2010 21:51:01 +0000 (+0100) Subject: Add isAbsolute/isRelative predicates to SGPath. X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=d7bea0c4c611b8134a3c6225da85c3098e0ca2ce;p=simgear.git Add isAbsolute/isRelative predicates to SGPath. --- diff --git a/simgear/misc/sg_path.cxx b/simgear/misc/sg_path.cxx index 1711cb3c..58772cde 100644 --- a/simgear/misc/sg_path.cxx +++ b/simgear/misc/sg_path.cxx @@ -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); +} diff --git a/simgear/misc/sg_path.hxx b/simgear/misc/sg_path.hxx index 41b7d744..535eef85 100644 --- a/simgear/misc/sg_path.hxx +++ b/simgear/misc/sg_path.hxx @@ -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();