diff --git a/src/OpenFOAM/primitives/Lists/stringListOps.H b/src/OpenFOAM/primitives/Lists/stringListOps.H index ac35d2afe4b4a4758205c6d408ba4968ec98a9fe..253a249c3df6efe6dd19948a107b631ae33283de 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 9ee1fa6f0a18bb7cdbe3e1c279e08f2da8d91956..54f624d60a3d0bf5b8ca53dffec96b6304c3bc94 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 - // ************************************************************************* //