initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / OpenFOAM / primitives / strings / wordRe / wordReI.H
blob7f242eb2c5ea7f98a936e0f257e52b5ccf923eb1
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 // * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * * //
29 inline bool Foam::wordRe::meta(char c)
31     return regExp::meta(c);
35 inline bool Foam::wordRe::isPattern(const string& str)
37     return string::meta<regExp>(str);
41 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
43 inline Foam::wordRe::wordRe()
45     word(),
46     re_()
50 inline Foam::wordRe::wordRe(const wordRe& str)
52     word(str),
53     re_()
55     if (str.isPattern())
56     {
57         compile();
58     }
62 inline Foam::wordRe::wordRe(const word& str)
64     word(str),
65     re_()
69 inline Foam::wordRe::wordRe(const char* str, const compOption opt)
71     word(str, false),
72     re_()
74     compile(opt);
78 inline Foam::wordRe::wordRe(const string& str, const compOption opt)
80     word(str, false),
81     re_()
83     compile(opt);
87 inline Foam::wordRe::wordRe(const std::string& str, const compOption opt)
89     word(str, false),
90     re_()
92     compile(opt);
96 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
98 inline bool Foam::wordRe::isPattern() const
100     return re_.exists();
104 inline bool Foam::wordRe::compile(const compOption opt) const
106     bool doCompile = false;
108     if (opt & wordRe::REGEXP)
109     {
110         doCompile = true;
111     }
112     else if (opt & wordRe::DETECT)
113     {
114         if (string::meta<regExp>(*this) || !string::valid<word>(*this))
115         {
116             doCompile = true;
117         }
118     }
119     else if (opt & wordRe::NOCASE)
120     {
121         doCompile = true;
122     }
125     if (doCompile)
126     {
127         re_.set(*this, (opt & wordRe::NOCASE));
128     }
129     else
130     {
131         re_.clear();
132     }
134     return re_.exists();
138 inline bool Foam::wordRe::compile() const
140     re_ = *this;
141     return re_.exists();
145 inline bool Foam::wordRe::recompile() const
147     if (re_.exists())
148     {
149         re_ = *this;
150     }
152     return re_.exists();
156 inline void Foam::wordRe::uncompile(const bool doStripInvalid) const
158     if (re_.clear())
159     {
160         // skip stripping unless debug is active to avoid costly operations
161         if (word::debug && doStripInvalid)
162         {
163             string::stripInvalid<word>
164             (
165                 const_cast<word&>(static_cast<const word&>(*this))
166             );
167         }
168     }
172 inline void Foam::wordRe::clear()
174     word::clear();
175     re_.clear();
179 inline bool Foam::wordRe::match(const string& str, bool literalMatch) const
181     if (literalMatch || !re_.exists())
182     {
183         // check as string
184         return (*this == str);
185     }
186     else
187     {
188         // check as regex
189         return re_.match(str);
190     }
194 inline Foam::string Foam::wordRe::quotemeta() const
196     return string::quotemeta<regExp>(*this);
200 inline void Foam::wordRe::set(const std::string& str, const compOption opt)
202     string::operator=(str);
203     compile(opt);
207 inline void Foam::wordRe::set(const char* str, const compOption opt)
209     string::operator=(str);
210     compile(opt);
214 // * * * * * * * * * * * * * * * Member Operators  * * * * * * * * * * * * * //
216 inline const Foam::wordRe& Foam::wordRe::operator=(const wordRe& str)
218     string::operator=(str);
220     if (str.isPattern())
221     {
222         compile();
223     }
224     else
225     {
226         re_.clear();
227     }
228     return *this;
232 inline const Foam::wordRe& Foam::wordRe::operator=(const word& str)
234     word::operator=(str);
235     re_.clear();
236     return *this;
240 inline const Foam::wordRe& Foam::wordRe::operator=(const string& str)
242     string::operator=(str);
243     compile(DETECT);  // auto-detect regex
244     return *this;
248 inline const Foam::wordRe& Foam::wordRe::operator=(const std::string& str)
250     string::operator=(str);
251     compile(DETECT);  // auto-detect regex
252     return *this;
256 inline const Foam::wordRe& Foam::wordRe::operator=(const char* str)
258     string::operator=(str);
259     compile(DETECT);  // auto-detect regex
260     return *this;
264 // ************************************************************************* //