Test-stringList.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
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
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
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.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 Description
25 
26 \*---------------------------------------------------------------------------*/
27 
28 #include "stringListOps.H"
29 #include "IStringStream.H"
30 #include "IOstreams.H"
31 
32 using namespace Foam;
33 
34 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
35 // Main program:
36 
37 int main(int argc, char *argv[])
38 {
39  stringList strLst
40  (
42  (
43  "("
44  "\"hello\""
45  "\"heello\""
46  "\"heeello\""
47  "\"bye\""
48  "\"bbye\""
49  "\"bbbye\""
50  "\"okey\""
51  "\"okkey\""
52  "\"okkkey\""
53  ")"
54  )()
55  );
56 
57  wordReList reLst(IStringStream("( okey \"[hy]e+.*\" )")());
58 
59  Info<< "stringList " << strLst << nl;
60 
61  labelList matches = findStrings(".*ee.*", strLst);
62 
63  Info<< "matches found for regexp .*ee.* :" << nl << matches << nl;
64  forAll(matches, i)
65  {
66  Info<< " -> " << strLst[matches[i]] << nl;
67  }
68  Info<< endl;
69 
70  matches = findStrings(reLst, strLst);
71 
72  Info<< "matches found for " << reLst << nl << matches << nl;
73  forAll(matches, i)
74  {
75  Info<< " -> " << strLst[matches[i]] << nl;
76  }
77  Info<< endl;
78 
79  stringList subLst = subsetStrings(".*ee.*", strLst);
80  Info<< "subset stringList: " << subLst << nl;
81 
82  subLst = subsetStrings(reLst, strLst);
83  Info<< "subset stringList: " << subLst << nl;
84 
85  inplaceSubsetStrings(reLst, strLst);
86  Info<< "subsetted stringList: " << strLst << nl;
87 
88  inplaceSubsetStrings(".*l.*", strLst);
89  Info<< "subsetted stringList: " << strLst << nl;
90 
91  Info<< "\nEnd\n" << endl;
92 
93  return 0;
94 }
95 
96 
97 // ************************************************************************* //
IOstreams.H
Useful combination of include files which define Sin, Sout and Serr and the use of IO streams general...
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
IStringStream.H
main
int main(int argc, char *argv[])
Definition: Test-stringList.C:37
Foam::subsetStrings
StringListType subsetStrings(const regExp &re, const StringListType &lst, const bool invert=false)
Extract elements of StringList when regular expression matches.
Definition: stringListOps.H:157
Foam::nl
static const char nl
Definition: Ostream.H:260
Foam::Info
messageStream Info
Foam::inplaceSubsetStrings
void inplaceSubsetStrings(const regExp &re, StringListType &lst, const bool invert=false)
Inplace extract elements of StringList when regular expression matches.
Definition: stringListOps.H:237
Foam::IStringStream
Input from memory buffer stream.
Definition: IStringStream.H:49
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::findStrings
bool findStrings(const wordReListMatcher &matcher, const std::string &str)
Return true if string matches one of the regular expressions.
Definition: stringListOps.H:52
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
stringListOps.H
Operations on lists of strings.