initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / applications / test / wordRe / wordReTest.C
blobcad3ed688b15be72989eca6ea8213e840bd2ccc3
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 Description
27 \*---------------------------------------------------------------------------*/
29 #include "IOstreams.H"
30 #include "IOobject.H"
31 #include "IFstream.H"
32 #include "List.H"
33 #include "Tuple2.H"
34 #include "wordRe.H"
36 using namespace Foam;
38 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
39 // Main program:
41 int main(int argc, char *argv[])
43     wordRe wre;
44     std::string s1("this .* file");
45     Foam::string s2("this .* file");
46     const char * s3 = "this .* file";
48     wordRe(s1, wordRe::DETECT).info(Info) << endl;
49     wordRe(s2).info(Info) << endl;
50     wordRe(s2, wordRe::DETECT).info(Info) << endl;
51     wordRe(s3, wordRe::REGEXP).info(Info) << endl;
53     wre = "this .* file";
54     wre.info(Info) << endl;
55     wre = s1;
56     wre.info(Info) << endl;
57     wre.uncompile();
58     wre.info(Info) << endl;
60     wre = "something";
61     wre.info(Info) << " before" << endl;
62     wre.uncompile();
63     wre.info(Info) << " uncompiled" << endl;
64     wre.compile(wordRe::DETECT);
65     wre.info(Info) << " after DETECT" << endl;
66     wre.compile(wordRe::NOCASE);
67     wre.info(Info) << " after NOCASE" << endl;
68     wre.compile(wordRe::DETECT_NOCASE);
69     wre.info(Info) << " after DETECT_NOCASE" << endl;
71     wre = "something .* value";
72     wre.info(Info) << " before" << endl;
73     wre.uncompile();
74     wre.info(Info) << " uncompiled" << endl;
75     wre.compile(wordRe::DETECT);
76     wre.info(Info) << " after DETECT" << endl;
77     wre.uncompile();
78     wre.info(Info) << " uncompiled" << endl;
79     wre.recompile();
80     wre.info(Info) << " recompiled" << endl;
82     wre.set("something .* value", wordRe::LITERAL);
83     wre.info(Info) << " set as LITERAL" << endl;
85     IOobject::writeDivider(Info);
87     List<Tuple2<wordRe, string> > rawList(IFstream("testRegexps")());
88     Info<< "input list:" << rawList << endl;
89     IOobject::writeDivider(Info) << endl;
91     forAll(rawList, elemI)
92     {
93         const wordRe& wre = rawList[elemI].first();
94         const string& str = rawList[elemI].second();
96         wre.info(Info)
97             << " equals:" << (wre == str)
98             << "(" << wre.match(str, true) << ")"
99             << " match:" << wre.match(str)
100             << "  str=" << str
101             << endl;
103         wordRe wre2;
104         wre2.set(wre, wordRe::NOCASE);
106         wre2.info(Info)
107             << " match:" << wre2.match(str)
108             << "  str=" << str
109             << endl;
111     }
113     Info<< endl;
115     return 0;
119 // ************************************************************************* //