From 7ab7eaa4e630a0e7bdf9c5682c9852c6e2006e38 Mon Sep 17 00:00:00 2001
From: Mark Olesen <Mark.Olesen@Germany>
Date: Mon, 19 Jan 2009 13:58:06 +0100
Subject: [PATCH] stringListOps - allow 'const char*' and 'const std::string&'
 arguments

---
 src/OpenFOAM/primitives/Lists/stringListOps.H |  9 ++++-
 .../primitives/Lists/stringListOpsTemplates.C | 40 +++++++++++++------
 2 files changed, 36 insertions(+), 13 deletions(-)

diff --git a/src/OpenFOAM/primitives/Lists/stringListOps.H b/src/OpenFOAM/primitives/Lists/stringListOps.H
index ac35d2afe4b..253a249c3df 100644
--- a/src/OpenFOAM/primitives/Lists/stringListOps.H
+++ b/src/OpenFOAM/primitives/Lists/stringListOps.H
@@ -44,12 +44,19 @@ SourceFiles
 
 namespace Foam
 {
+    //- Return list indices for strings matching the regular expression
+    template<class StringType>
+    labelList findStrings
+    (
+        const char* regexpPattern,
+        const UList<StringType>&
+    );
 
     //- Return list indices for strings matching the regular expression
     template<class StringType>
     labelList findStrings
     (
-        const string& regexpPattern,
+        const std::string& regexpPattern,
         const UList<StringType>&
     );
 
diff --git a/src/OpenFOAM/primitives/Lists/stringListOpsTemplates.C b/src/OpenFOAM/primitives/Lists/stringListOpsTemplates.C
index 9ee1fa6f0a1..54f624d60a3 100644
--- a/src/OpenFOAM/primitives/Lists/stringListOpsTemplates.C
+++ b/src/OpenFOAM/primitives/Lists/stringListOpsTemplates.C
@@ -29,15 +29,35 @@ License
 
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
 
-namespace Foam
+
+template<class StringType>
+Foam::labelList Foam::findStrings
+(
+    const char* pattern,
+    const UList<StringType>& lst
+)
 {
+    regExp re(pattern);
+    labelList matched(lst.size());
+
+    label matchI = 0;
+    forAll(lst, elemI)
+    {
+        if (re.match(lst[elemI]))
+        {
+            matched[matchI++] = elemI;
+        }
+    }
+    matched.setSize(matchI);
+
+    return matched;
+}
 
-// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
 
 template<class StringType>
-labelList findStrings
+Foam::labelList Foam::findStrings
 (
-    const string& pattern,
+    const std::string& pattern,
     const UList<StringType>& lst
 )
 {
@@ -59,7 +79,7 @@ labelList findStrings
 
 
 template<class StringType>
-labelList findStrings
+Foam::labelList Foam::findStrings
 (
     const wordRe& wre,
     const UList<StringType>& lst
@@ -82,7 +102,7 @@ labelList findStrings
 
 
 template<class StringType>
-labelList findStrings
+Foam::labelList Foam::findStrings
 (
     const UList<wordRe>& wreLst,
     const UList<StringType>& lst
@@ -109,7 +129,7 @@ labelList findStrings
 
 
 template<class StringType>
-bool findStrings
+bool Foam::findStrings
 (
     const UList<wordRe>& wreLst,
     const StringType& str
@@ -122,13 +142,9 @@ bool findStrings
             return true;
         }
     }
-    
+
     return false;
 }
 
 
-// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
-
-} // End namespace Foam
-
 // ************************************************************************* //
-- 
GitLab