Commit 64fe6718 authored by Andrew Heather's avatar Andrew Heather
Browse files

ENH: Added isAbsolute() function to fileName class

parent 6d70677d
......@@ -64,9 +64,7 @@ bool Foam::IOobject::IOobject::fileNameComponents
return false;
}
string::size_type first = path.find('/');
if (first == 0)
if (path.isAbsolute())
{
// called with absolute path
WarningIn("IOobject::fileNameComponents(const fileName&, ...)")
......
......@@ -72,7 +72,7 @@ Foam::fileName Foam::functionEntries::includeEntry::includeFileName
fName.expand();
// relative name
if (fName.size() && fName[0] != '/')
if (fName.size() && !fName.isAbsolute())
{
fName = fileName(is.name()).path()/fName;
}
......
......@@ -315,7 +315,7 @@ void Foam::argList::getRootCase()
casePath = cwd();
options_.erase("case");
}
else if (casePath[0] != '/' && casePath.name() == "..")
else if (!casePath.isAbsolute() && casePath.name() == "..")
{
// avoid relative cases ending in '..' - makes for very ugly names
casePath = cwd()/casePath;
......@@ -334,7 +334,7 @@ void Foam::argList::getRootCase()
// Set the case and case-name as an environment variable
if (rootPath_[0] == '/')
if (rootPath_.isAbsolute())
{
// absolute path - use as-is
setEnv("FOAM_CASE", rootPath_/globalCase_, true);
......
......@@ -54,6 +54,13 @@ Foam::fileName::Type Foam::fileName::type() const
}
bool Foam::fileName::isAbsolute() const
{
fileName fName(*this);
return fName.size() && fName.operator[](0) == '/';
}
//
// * remove repeated slashes
// /abc////def --> /abc/def
......
......@@ -138,10 +138,15 @@ public:
// eg, remove repeated slashes, etc.
fileName clean() const;
// Interogation
//- Return the file type: FILE, DIRECTORY or UNDEFINED
Type type() const;
// Interrogation
//- Return the file type: FILE, DIRECTORY or UNDEFINED
Type type() const;
//- Return true if file name is absolute
bool isAbsolute() const;
// Decomposition
......@@ -163,6 +168,7 @@ public:
//- Return a single component of the path
word component(const size_type, const char delimiter='/') const;
// Member operators
// Assignment
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment