Changed: Implement CPath::isAbsolutePath

This commit is contained in:
kervala 2016-01-13 19:46:27 +01:00
parent 179499a5c1
commit 12e16e83e2
2 changed files with 25 additions and 0 deletions

View file

@ -514,6 +514,12 @@ public:
*/
static std::string makePathAbsolute (const std::string &relativePath, const std::string &directory );
/** Return if a path is absolute or not.
* \param path - The path
* returns true if path is absolute or false if relative.
*/
static bool isAbsolutePath (const std::string &path);
/** If File in this list is added more than one in an addSearchPath, it doesn't launch a warning.
*/
static void addIgnoredDoubleFile(const std::string &ignoredFile);

View file

@ -2597,6 +2597,25 @@ std::string CPath::makePathAbsolute( const std::string &relativePath, const std:
return npath;
}
bool CPath::isAbsolutePath(const std::string &path)
{
if (path.empty()) return false;
#ifdef NL_OS_WINDOWS
// Windows root of current disk. Eg.: "\" or
// Windows network address. Eg.: \\someshare\path
if (path[0] == '\\') return true;
// Normal Windows absolute path. Eg.: C:\something
if (path.length() > 2 && isalpha(path[0]) && (path[1] == ':' ) && ((path[2] == '\\') || (path[2] == '/' ))) return true;
#endif
// Unix filesystem absolute path (works also under Windows)
if (path[0] == '/') return true;
return false;
}
bool CFile::setRWAccess(const std::string &filename)
{
#ifdef NL_OS_WINDOWS