From 64fe671850cd7148b2ff1f49e97391f3669aafed Mon Sep 17 00:00:00 2001
From: andy <a.heather@opencfd.co.uk>
Date: Tue, 2 Nov 2010 18:06:27 +0000
Subject: [PATCH] ENH: Added isAbsolute() function to fileName class

---
 src/OpenFOAM/db/IOobject/IOobject.C                  |  4 +---
 .../functionEntries/includeEntry/includeEntry.C      |  2 +-
 src/OpenFOAM/global/argList/argList.C                |  4 ++--
 src/OpenFOAM/primitives/strings/fileName/fileName.C  |  7 +++++++
 src/OpenFOAM/primitives/strings/fileName/fileName.H  | 12 +++++++++---
 5 files changed, 20 insertions(+), 9 deletions(-)

diff --git a/src/OpenFOAM/db/IOobject/IOobject.C b/src/OpenFOAM/db/IOobject/IOobject.C
index 66026048b7d..f6c5facb39a 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 d7eaffa4e82..6a4ba800ce4 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 eb1f65836d2..c31199c9936 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 ec47f43b278..13d7e33f9c7 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 8eae249c52c..f0164d56d59 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
-- 
GitLab