1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | foam-extend: Open Source CFD
4 \\ / O peration | Version: 3.2
5 \\ / A nd | Web: http://www.foam-extend.org
6 \\/ M anipulation | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
9 This file is part of foam-extend.
11 foam-extend 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 3 of the License, or (at your
14 option) any later version.
16 foam-extend is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 // * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * * //
28 inline bool Foam::wordRe::meta(char c)
30 return regExp::meta(c);
34 inline bool Foam::wordRe::isPattern(const string& str)
36 return string::meta<regExp>(str);
40 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
42 inline Foam::wordRe::wordRe()
49 inline Foam::wordRe::wordRe(const wordRe& str)
61 inline Foam::wordRe::wordRe(const word& str)
68 inline Foam::wordRe::wordRe(const char* str, const compOption opt)
77 inline Foam::wordRe::wordRe(const string& str, const compOption opt)
86 inline Foam::wordRe::wordRe(const std::string& str, const compOption opt)
95 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
97 inline bool Foam::wordRe::isPattern() const
103 inline bool Foam::wordRe::compile(const compOption opt) const
105 bool doCompile = false;
107 if (opt & wordRe::REGEXP)
111 else if (opt & wordRe::DETECT)
113 if (string::meta<regExp>(*this) || !string::valid<word>(*this))
118 else if (opt & wordRe::NOCASE)
126 re_.set(*this, (opt & wordRe::NOCASE));
137 inline bool Foam::wordRe::compile() const
144 inline bool Foam::wordRe::recompile() const
155 inline void Foam::wordRe::uncompile(const bool doStripInvalid) const
159 // skip stripping unless debug is active to avoid costly operations
160 if (word::debug && doStripInvalid)
162 string::stripInvalid<word>
164 const_cast<word&>(static_cast<const word&>(*this))
171 inline void Foam::wordRe::clear()
178 inline bool Foam::wordRe::match(const string& str, bool literalMatch) const
180 if (literalMatch || !re_.exists())
183 return (*this == str);
188 return re_.match(str);
193 inline Foam::string Foam::wordRe::quotemeta() const
195 return string::quotemeta<regExp>(*this);
199 inline void Foam::wordRe::set(const std::string& str, const compOption opt)
201 string::operator=(str);
206 inline void Foam::wordRe::set(const char* str, const compOption opt)
208 string::operator=(str);
213 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
215 inline const Foam::wordRe& Foam::wordRe::operator=(const wordRe& str)
217 string::operator=(str);
231 inline const Foam::wordRe& Foam::wordRe::operator=(const word& str)
233 word::operator=(str);
239 inline const Foam::wordRe& Foam::wordRe::operator=(const string& str)
241 string::operator=(str);
242 compile(DETECT); // auto-detect regex
247 inline const Foam::wordRe& Foam::wordRe::operator=(const std::string& str)
249 string::operator=(str);
250 compile(DETECT); // auto-detect regex
255 inline const Foam::wordRe& Foam::wordRe::operator=(const char* str)
257 string::operator=(str);
258 compile(DETECT); // auto-detect regex
263 // ************************************************************************* //