initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / OpenFOAM / primitives / Lists / stringListOpsTemplates.C
blob54f624d60a3d0bf5b8ca53dffec96b6304c3bc94
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
11     OpenFOAM is free software; you can redistribute it and/or modify it
12     under the terms of the GNU General Public License as published by the
13     Free Software Foundation; either version 2 of the License, or (at your
14     option) any later version.
16     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
19     for more details.
21     You should have received a copy of the GNU General Public License
22     along with OpenFOAM; if not, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*---------------------------------------------------------------------------*/
27 #include "labelList.H"
28 #include "regExp.H"
30 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
33 template<class StringType>
34 Foam::labelList Foam::findStrings
36     const char* pattern,
37     const UList<StringType>& lst
40     regExp re(pattern);
41     labelList matched(lst.size());
43     label matchI = 0;
44     forAll(lst, elemI)
45     {
46         if (re.match(lst[elemI]))
47         {
48             matched[matchI++] = elemI;
49         }
50     }
51     matched.setSize(matchI);
53     return matched;
57 template<class StringType>
58 Foam::labelList Foam::findStrings
60     const std::string& pattern,
61     const UList<StringType>& lst
64     regExp re(pattern);
65     labelList matched(lst.size());
67     label matchI = 0;
68     forAll(lst, elemI)
69     {
70         if (re.match(lst[elemI]))
71         {
72             matched[matchI++] = elemI;
73         }
74     }
75     matched.setSize(matchI);
77     return matched;
81 template<class StringType>
82 Foam::labelList Foam::findStrings
84     const wordRe& wre,
85     const UList<StringType>& lst
88     labelList matched(lst.size());
90     label matchI = 0;
91     forAll(lst, elemI)
92     {
93         if (wre.match(lst[elemI]))
94         {
95             matched[matchI++] = elemI;
96         }
97     }
98     matched.setSize(matchI);
100     return matched;
104 template<class StringType>
105 Foam::labelList Foam::findStrings
107     const UList<wordRe>& wreLst,
108     const UList<StringType>& lst
111     labelList matched(lst.size());
113     label matchI = 0;
114     forAll(lst, elemI)
115     {
116         forAll(wreLst, reI)
117         {
118             if (wreLst[reI].match(lst[elemI]))
119             {
120                 matched[matchI++] = elemI;
121                 break;
122             }
123         }
124     }
125     matched.setSize(matchI);
127     return matched;
131 template<class StringType>
132 bool Foam::findStrings
134     const UList<wordRe>& wreLst,
135     const StringType& str
138     forAll(wreLst, reI)
139     {
140         if (wreLst[reI].match(str))
141         {
142             return true;
143         }
144     }
146     return false;
150 // ************************************************************************* //