diff --git a/src/OpenFOAM/db/IOobject/IOobject.C b/src/OpenFOAM/db/IOobject/IOobject.C index 66026048b7d87a5d08fb1bdce2edb3755c4b2cea..f6c5facb39a7236ca3b6fc454265349e40f12b39 100644 --- a/src/OpenFOAM/db/IOobject/IOobject.C +++ b/src/OpenFOAM/db/IOobject/IOobject.C @@ -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&, ...)") diff --git a/src/OpenFOAM/db/dictionary/functionEntries/includeEntry/includeEntry.C b/src/OpenFOAM/db/dictionary/functionEntries/includeEntry/includeEntry.C index d7eaffa4e828b57f103382e0398bd2490049e4f2..6a4ba800ce413c6089b4535e9a542e486434f246 100644 --- a/src/OpenFOAM/db/dictionary/functionEntries/includeEntry/includeEntry.C +++ b/src/OpenFOAM/db/dictionary/functionEntries/includeEntry/includeEntry.C @@ -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; } diff --git a/src/OpenFOAM/global/argList/argList.C b/src/OpenFOAM/global/argList/argList.C index eb1f65836d2c6f1d762a66ed42c3e3cd007cfa16..c31199c9936075cf32873f492285bdcf8ee5cdcb 100644 --- a/src/OpenFOAM/global/argList/argList.C +++ b/src/OpenFOAM/global/argList/argList.C @@ -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); diff --git a/src/OpenFOAM/primitives/strings/fileName/fileName.C b/src/OpenFOAM/primitives/strings/fileName/fileName.C index ec47f43b278ec4b0739a96a76d75abed676d465e..13d7e33f9c76e349d60c0c1c0f5f515dc17501a6 100644 --- a/src/OpenFOAM/primitives/strings/fileName/fileName.C +++ b/src/OpenFOAM/primitives/strings/fileName/fileName.C @@ -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 diff --git a/src/OpenFOAM/primitives/strings/fileName/fileName.H b/src/OpenFOAM/primitives/strings/fileName/fileName.H index 8eae249c52ceba16c67bbf61481ac52332aeb3aa..f0164d56d5905cb6828fdca6e5e957f8962678c7 100644 --- a/src/OpenFOAM/primitives/strings/fileName/fileName.H +++ b/src/OpenFOAM/primitives/strings/fileName/fileName.H @@ -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