diff --git a/src/OpenFOAM/primitives/Lists/stringListOps.H b/src/OpenFOAM/primitives/Lists/stringListOps.H index ac35d2afe4..253a249c3d 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 + labelList findStrings + ( + const char* regexpPattern, + const UList& + ); //- Return list indices for strings matching the regular expression template labelList findStrings ( - const string& regexpPattern, + const std::string& regexpPattern, const UList& ); diff --git a/src/OpenFOAM/primitives/Lists/stringListOpsTemplates.C b/src/OpenFOAM/primitives/Lists/stringListOpsTemplates.C index 9ee1fa6f0a..54f624d60a 100644 --- a/src/OpenFOAM/primitives/Lists/stringListOpsTemplates.C +++ b/src/OpenFOAM/primitives/Lists/stringListOpsTemplates.C @@ -29,15 +29,11 @@ License // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // -namespace Foam -{ - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // template -labelList findStrings +Foam::labelList Foam::findStrings ( - const string& pattern, + const char* pattern, const UList& lst ) { @@ -59,7 +55,31 @@ labelList findStrings template -labelList findStrings +Foam::labelList Foam::findStrings +( + const std::string& pattern, + const UList& 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 +Foam::labelList Foam::findStrings ( const wordRe& wre, const UList& lst @@ -82,7 +102,7 @@ labelList findStrings template -labelList findStrings +Foam::labelList Foam::findStrings ( const UList& wreLst, const UList& lst @@ -109,7 +129,7 @@ labelList findStrings template -bool findStrings +bool Foam::findStrings ( const UList& wreLst, const StringType& str @@ -122,13 +142,9 @@ bool findStrings return true; } } - + return false; } -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -} // End namespace Foam - // ************************************************************************* //