ENH: Added isAbsolute() function to fileName class

This commit is contained in:
andy
2010-11-02 18:06:27 +00:00
parent 6d70677ddb
commit 64fe671850
5 changed files with 20 additions and 9 deletions

View File

@ -64,9 +64,7 @@ bool Foam::IOobject::IOobject::fileNameComponents
return false; return false;
} }
string::size_type first = path.find('/'); if (path.isAbsolute())
if (first == 0)
{ {
// called with absolute path // called with absolute path
WarningIn("IOobject::fileNameComponents(const fileName&, ...)") WarningIn("IOobject::fileNameComponents(const fileName&, ...)")

View File

@ -72,7 +72,7 @@ Foam::fileName Foam::functionEntries::includeEntry::includeFileName
fName.expand(); fName.expand();
// relative name // relative name
if (fName.size() && fName[0] != '/') if (fName.size() && !fName.isAbsolute())
{ {
fName = fileName(is.name()).path()/fName; fName = fileName(is.name()).path()/fName;
} }

View File

@ -315,7 +315,7 @@ void Foam::argList::getRootCase()
casePath = cwd(); casePath = cwd();
options_.erase("case"); 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 // avoid relative cases ending in '..' - makes for very ugly names
casePath = cwd()/casePath; casePath = cwd()/casePath;
@ -334,7 +334,7 @@ void Foam::argList::getRootCase()
// Set the case and case-name as an environment variable // Set the case and case-name as an environment variable
if (rootPath_[0] == '/') if (rootPath_.isAbsolute())
{ {
// absolute path - use as-is // absolute path - use as-is
setEnv("FOAM_CASE", rootPath_/globalCase_, true); setEnv("FOAM_CASE", rootPath_/globalCase_, true);

View File

@ -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 // * remove repeated slashes
// /abc////def --> /abc/def // /abc////def --> /abc/def

View File

@ -138,10 +138,15 @@ public:
// eg, remove repeated slashes, etc. // eg, remove repeated slashes, etc.
fileName clean() const; fileName clean() const;
// Interogation
//- Return the file type: FILE, DIRECTORY or UNDEFINED // Interrogation
Type type() const;
//- Return the file type: FILE, DIRECTORY or UNDEFINED
Type type() const;
//- Return true if file name is absolute
bool isAbsolute() const;
// Decomposition // Decomposition
@ -163,6 +168,7 @@ public:
//- Return a single component of the path //- Return a single component of the path
word component(const size_type, const char delimiter='/') const; word component(const size_type, const char delimiter='/') const;
// Member operators // Member operators
// Assignment // Assignment