From efc21270eaf7047f40e5b840aa8b942be5c097b6 Mon Sep 17 00:00:00 2001
From: Mark Olesen <Mark.Olesen@esi-group.com>
Date: Wed, 5 Jul 2017 09:15:52 +0200
Subject: [PATCH] STYLE: regExp with explicit constructor

- use separate constructor for ignore-case option (cf. wordRe treatment)

- constructors/destructor now inline.
---
 src/OSspecific/POSIX/regExp.C                 | 32 -------------
 src/OSspecific/POSIX/regExp.H                 | 28 ++++++-----
 src/OSspecific/POSIX/regExpI.H                | 48 +++++++++++++++++++
 .../starcd/STARCDsurfaceFormatCore.C          | 12 ++---
 4 files changed, 70 insertions(+), 50 deletions(-)

diff --git a/src/OSspecific/POSIX/regExp.C b/src/OSspecific/POSIX/regExp.C
index 95e70ece9d4..0f9cd7cb21c 100644
--- a/src/OSspecific/POSIX/regExp.C
+++ b/src/OSspecific/POSIX/regExp.C
@@ -77,38 +77,6 @@ bool Foam::regExp::matchGrouping
 }
 
 
-// * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
-
-Foam::regExp::regExp()
-:
-    preg_(nullptr)
-{}
-
-
-Foam::regExp::regExp(const char* pattern, bool ignoreCase)
-:
-    preg_(nullptr)
-{
-    set(pattern, ignoreCase);
-}
-
-
-Foam::regExp::regExp(const std::string& pattern, bool ignoreCase)
-:
-    preg_(nullptr)
-{
-    set(pattern.c_str(), ignoreCase);
-}
-
-
-// * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
-
-Foam::regExp::~regExp()
-{
-    clear();
-}
-
-
 // * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * * //
 
 bool Foam::regExp::set(const char* pattern, bool ignoreCase)
diff --git a/src/OSspecific/POSIX/regExp.H b/src/OSspecific/POSIX/regExp.H
index 640f6a819e1..1f82552d07f 100644
--- a/src/OSspecific/POSIX/regExp.H
+++ b/src/OSspecific/POSIX/regExp.H
@@ -77,7 +77,7 @@ class regExp
         //- Return true if it matches and sets the sub-groups matched.
         bool matchGrouping
         (
-            const std::string&,
+            const std::string& text,
             List<std::string>& groups
         ) const;
 
@@ -99,17 +99,23 @@ public:
     // Constructors
 
         //- Construct null
-        regExp();
+        inline regExp();
+
+        //- Construct from character array
+        inline explicit regExp(const char* pattern);
+
+        //- Construct from string
+        inline explicit regExp(const std::string& pattern);
 
         //- Construct from character array, optionally ignore case
-        regExp(const char* pattern, bool ignoreCase=false);
+        inline regExp(const char* pattern, bool ignoreCase);
 
         //- Construct from string, optionally ignore case
-        regExp(const std::string& pattern, bool ignoreCase=false);
+        inline regExp(const std::string& pattern, bool ignoreCase);
 
 
     //- Destructor
-    ~regExp();
+    inline ~regExp();
 
 
     // Member functions
@@ -143,20 +149,20 @@ public:
 
       // Matching/Searching
 
-        //- Find position within string.
-        //  \Return The index where it begins or string::npos if not found
+        //- Find position within the text.
+        //  \return The index where it begins or string::npos if not found
         std::string::size_type find(const std::string& text) const;
 
-        //- Return true if it matches the entire string
+        //- True if the regex matches the entire text.
         //  The begin-of-line (^) and end-of-line ($) anchors are implicit
         bool match(const std::string& text) const;
 
-        //- Return true if it matches and sets the sub-groups matched
+        //- True if the regex matches the text, set the sub-groups matched.
         //  The begin-of-line (^) and end-of-line ($) anchors are implicit
         bool match(const std::string& text, List<std::string>& groups) const;
 
-        //- Return true if the regex was found within string
-        bool search(const std::string& text) const;
+        //- Return true if the regex was found within the text
+        inline bool search(const std::string& text) const;
 
 
     // Member Operators
diff --git a/src/OSspecific/POSIX/regExpI.H b/src/OSspecific/POSIX/regExpI.H
index e33564e611a..7302e02410b 100644
--- a/src/OSspecific/POSIX/regExpI.H
+++ b/src/OSspecific/POSIX/regExpI.H
@@ -38,6 +38,54 @@ inline bool Foam::regExp::meta(const char c)
 }
 
 
+// * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
+
+inline Foam::regExp::regExp()
+:
+    preg_(nullptr)
+{}
+
+
+inline Foam::regExp::regExp(const char* pattern)
+:
+    preg_(nullptr)
+{
+    set(pattern, false);
+}
+
+
+inline Foam::regExp::regExp(const std::string& pattern)
+:
+    preg_(nullptr)
+{
+    set(pattern, false);
+}
+
+
+inline Foam::regExp::regExp(const char* pattern, bool ignoreCase)
+:
+    preg_(nullptr)
+{
+    set(pattern, ignoreCase);
+}
+
+
+inline Foam::regExp::regExp(const std::string& pattern, bool ignoreCase)
+:
+    preg_(nullptr)
+{
+    set(pattern, ignoreCase);
+}
+
+
+// * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
+
+inline Foam::regExp::~regExp()
+{
+    clear();
+}
+
+
 // * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * * //
 
 inline bool Foam::regExp::empty() const
diff --git a/src/surfMesh/surfaceFormats/starcd/STARCDsurfaceFormatCore.C b/src/surfMesh/surfaceFormats/starcd/STARCDsurfaceFormatCore.C
index b926f96802d..71b3751c8c4 100644
--- a/src/surfMesh/surfaceFormats/starcd/STARCDsurfaceFormatCore.C
+++ b/src/surfMesh/surfaceFormats/starcd/STARCDsurfaceFormatCore.C
@@ -26,7 +26,7 @@ License
 #include "STARCDsurfaceFormatCore.H"
 #include "clock.H"
 #include "regExp.H"
-#include "IStringStream.H"
+#include "IFstream.H"
 
 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
 
@@ -47,7 +47,7 @@ Foam::fileFormats::STARCDsurfaceFormatCore::readInpCellTable
         return lookup;
     }
 
-    regExp ctnameRE
+    const regExp ctnameRE
     (
         " *CTNA[^ ]*"        // keyword - min 4 chars
         "[[:space:]]+"       // space delimited
@@ -64,13 +64,11 @@ Foam::fileFormats::STARCDsurfaceFormatCore::readInpCellTable
         if (ctnameRE.match(line, groups))
         {
             const label tableId = atoi(groups[0].c_str());
+            const word tableName = word::validated(groups[1]);
 
-            // strip bad chars
-            string::stripInvalid<word>(groups[1]);
-
-            if (!groups[1].empty())
+            if (!tableName.empty())
             {
-                lookup.insert(tableId, groups[1]);
+                lookup.insert(tableId, tableName);
             }
         }
     }
-- 
GitLab