OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

stringListOpsTemplates.C

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software; you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM; if not, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 \*---------------------------------------------------------------------------*/
00026 
00027 #include "labelList.H"
00028 #include "regExp.H"
00029 
00030 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00031 
00032 
00033 template<class StringType>
00034 Foam::labelList Foam::findStrings
00035 (
00036     const char* pattern,
00037     const UList<StringType>& lst
00038 )
00039 {
00040     regExp re(pattern);
00041     labelList matched(lst.size());
00042 
00043     label matchI = 0;
00044     forAll(lst, elemI)
00045     {
00046         if (re.match(lst[elemI]))
00047         {
00048             matched[matchI++] = elemI;
00049         }
00050     }
00051     matched.setSize(matchI);
00052 
00053     return matched;
00054 }
00055 
00056 
00057 template<class StringType>
00058 Foam::labelList Foam::findStrings
00059 (
00060     const std::string& pattern,
00061     const UList<StringType>& lst
00062 )
00063 {
00064     regExp re(pattern);
00065     labelList matched(lst.size());
00066 
00067     label matchI = 0;
00068     forAll(lst, elemI)
00069     {
00070         if (re.match(lst[elemI]))
00071         {
00072             matched[matchI++] = elemI;
00073         }
00074     }
00075     matched.setSize(matchI);
00076 
00077     return matched;
00078 }
00079 
00080 
00081 template<class StringType>
00082 Foam::labelList Foam::findStrings
00083 (
00084     const wordRe& wre,
00085     const UList<StringType>& lst
00086 )
00087 {
00088     labelList matched(lst.size());
00089 
00090     label matchI = 0;
00091     forAll(lst, elemI)
00092     {
00093         if (wre.match(lst[elemI]))
00094         {
00095             matched[matchI++] = elemI;
00096         }
00097     }
00098     matched.setSize(matchI);
00099 
00100     return matched;
00101 }
00102 
00103 
00104 template<class StringType>
00105 Foam::labelList Foam::findStrings
00106 (
00107     const UList<wordRe>& wreLst,
00108     const UList<StringType>& lst
00109 )
00110 {
00111     labelList matched(lst.size());
00112 
00113     label matchI = 0;
00114     forAll(lst, elemI)
00115     {
00116         forAll(wreLst, reI)
00117         {
00118             if (wreLst[reI].match(lst[elemI]))
00119             {
00120                 matched[matchI++] = elemI;
00121                 break;
00122             }
00123         }
00124     }
00125     matched.setSize(matchI);
00126 
00127     return matched;
00128 }
00129 
00130 
00131 template<class StringType>
00132 bool Foam::findStrings
00133 (
00134     const UList<wordRe>& wreLst,
00135     const StringType& str
00136 )
00137 {
00138     forAll(wreLst, reI)
00139     {
00140         if (wreLst[reI].match(str))
00141         {
00142             return true;
00143         }
00144     }
00145 
00146     return false;
00147 }
00148 
00149 
00150 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd