1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright held by original author
7 -------------------------------------------------------------------------------
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
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
29 Operations on lists of strings.
32 stringListOpsTemplates.C
34 \*---------------------------------------------------------------------------*/
36 #ifndef stringListOps_H
37 #define stringListOps_H
40 #include "labelList.H"
41 #include "stringList.H"
42 #include "wordReList.H"
43 #include "wordReListMatcher.H"
45 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
49 // single-string matches:
51 //- Return true if string matches one of the regular expressions
52 inline bool findStrings
54 const wordReListMatcher& matcher,
55 const std::string& str
58 return matcher.match(str);
61 // multi-string matches:
63 //- Return list indices for matching strings
64 template<class Matcher, class StringType>
65 labelList findMatchingStrings
68 const UList<StringType>&,
69 const bool invert=false
72 //- Return list indices for strings matching the regular expression
73 // Template partial specialization of findMatchingStrings
74 template<class StringType>
78 const UList<StringType>& lst,
79 const bool invert=false
82 return findMatchingStrings(re, lst, invert);
85 //- Return list indices for strings matching the regular expression
86 // Template partial specialization of findMatchingStrings
87 template<class StringType>
90 const char* rePattern,
91 const UList<StringType>& lst,
92 const bool invert=false
97 return findStrings(rp, lst, invert);
100 //- Return list indices for strings matching the regular expression
101 // Template partial specialization of findMatchingStrings
102 template<class StringType>
103 labelList findStrings
105 const std::string& rePattern,
106 const UList<StringType>& lst,
107 const bool invert=false
110 regExp rp(rePattern);
111 return findMatchingStrings(rp, lst, invert);
114 //- Return list indices for strings matching the regular expression
115 // Template partial specialization of findMatchingStrings
116 template<class StringType>
117 labelList findStrings
120 const UList<StringType>& lst,
121 const bool invert=false
124 return findMatchingStrings(wre, lst, invert);
128 //- Return list indices for strings matching one of the regular expression
129 // Template partial specialization of findMatchingStrings
130 template<class StringType>
131 labelList findStrings
133 const wordReListMatcher& matcher,
134 const UList<StringType>& lst,
135 const bool invert=false
138 return findMatchingStrings(matcher, lst, invert);
141 // subsetting multi-string matches (similar to ListOp):
143 //- Extract elements of StringList when regular expression matches
144 // optionally invert the match
145 // eg, to extract all selected elements:
146 // subsetMatchingStrings<regExp, stringList>(myRegExp, lst);
147 template<class Matcher, class StringListType>
148 StringListType subsetMatchingStrings
151 const StringListType&,
152 const bool invert=false
155 //- Extract elements of StringList when regular expression matches
156 // Template partial specialization of subsetMatchingStrings
157 template<class StringListType>
158 StringListType subsetStrings
161 const StringListType& lst,
162 const bool invert=false
165 return subsetMatchingStrings(re, lst, invert);
168 //- Extract elements of StringList when regular expression matches
169 // Template partial specialization of subsetMatchingStrings
170 template<class StringListType>
171 StringListType subsetStrings
173 const char* rePattern,
174 const StringListType& lst,
175 const bool invert=false
178 regExp rp(rePattern);
179 return subsetMatchingStrings(rp, lst, invert);
182 //- Extract elements of StringList when regular expression matches
183 // Template partial specialization of subsetMatchingStrings
184 template<class StringListType>
185 StringListType subsetStrings
187 const std::string& rePattern,
188 const StringListType& lst,
189 const bool invert=false
192 regExp rp(rePattern);
193 return subsetMatchingStrings(rp, lst, invert);
196 //- Extract elements of StringList when regular expression matches
197 // Template partial specialization of subsetMatchingStrings
198 template<class StringListType>
199 StringListType subsetStrings
202 const StringListType& lst,
203 const bool invert=false
206 return subsetMatchingStrings(wre, lst, invert);
209 //- Extract elements of StringList when regular expression matches
210 // Template partial specialization of subsetMatchingStrings
211 template<class StringListType>
212 StringListType subsetStrings
214 const wordReListMatcher& matcher,
215 const StringListType& lst,
216 const bool invert=false
219 return subsetMatchingStrings(matcher, lst, invert);
223 //- Inplace extract elements of StringList when regular expression matches
224 // optionally invert the match
225 // eg, to extract all selected elements:
226 // inplaceSubsetMatchingStrings<regExp, stringList>(myRegExp, lst);
227 template<class Matcher, class StringListType>
228 void inplaceSubsetMatchingStrings
232 const bool invert=false
235 //- Inplace extract elements of StringList when regular expression matches
236 // Template partial specialization of inplaceSubsetMatchingStrings
237 template<class StringListType>
238 void inplaceSubsetStrings
242 const bool invert=false
245 inplaceSubsetMatchingStrings(re, lst, invert);
248 //- Inplace extract elements of StringList when regular expression matches
249 // Template partial specialization of inplaceSubsetMatchingStrings
250 template<class StringListType>
251 void inplaceSubsetStrings
253 const char* rePattern,
255 const bool invert=false
258 regExp rp(rePattern);
259 inplaceSubsetMatchingStrings(rp, lst, invert);
262 //- Inplace extract elements of StringList when regular expression matches
263 // Template partial specialization of inplaceSubsetMatchingStrings
264 template<class StringListType>
265 void inplaceSubsetStrings
267 const std::string& rePattern,
269 const bool invert=false
272 regExp rp(rePattern);
273 inplaceSubsetMatchingStrings(rp, lst, invert);
276 //- Inplace extract elements of StringList when regular expression matches
277 // Template partial specialization of inplaceSubsetMatchingStrings
278 template<class StringListType>
279 void inplaceSubsetStrings
283 const bool invert=false
286 inplaceSubsetMatchingStrings(wre, lst, invert);
289 //- Inplace extract elements of StringList when regular expression matches
290 // Template partial specialization of inplaceSubsetMatchingStrings
291 template<class StringListType>
292 void inplaceSubsetStrings
294 const wordReListMatcher& matcher,
296 const bool invert=false
299 inplaceSubsetMatchingStrings(matcher, lst, invert);
305 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
308 # include "stringListOpsTemplates.C"
311 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
315 // ************************************************************************* //