1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
7 -------------------------------------------------------------------------------
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
13 the Free Software Foundation, either version 3 of the License, or
14 (at your 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
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/>.
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 keyType& str, const compOption opt)
80 inline Foam::wordRe::wordRe(const char* str, const compOption opt)
89 inline Foam::wordRe::wordRe(const string& str, const compOption opt)
98 inline Foam::wordRe::wordRe(const std::string& str, const compOption opt)
107 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
109 inline bool Foam::wordRe::isPattern() const
115 inline bool Foam::wordRe::compile(const compOption opt) const
117 bool doCompile = false;
119 if (opt & wordRe::REGEXP)
123 else if (opt & wordRe::DETECT)
125 if (string::meta<regExp>(*this) || !string::valid<word>(*this))
130 else if (opt & wordRe::NOCASE)
138 re_.set(*this, (opt & wordRe::NOCASE));
149 inline bool Foam::wordRe::compile() const
156 inline bool Foam::wordRe::recompile() const
167 inline void Foam::wordRe::uncompile(const bool doStripInvalid) const
171 // skip stripping unless debug is active to avoid costly operations
172 if (word::debug && doStripInvalid)
174 string::stripInvalid<word>
176 const_cast<word&>(static_cast<const word&>(*this))
183 inline void Foam::wordRe::clear()
190 inline bool Foam::wordRe::match(const std::string& str, bool literalMatch) const
192 if (literalMatch || !re_.exists())
195 return (str == *this);
200 return re_.match(str);
205 inline Foam::string Foam::wordRe::quotemeta() const
207 return string::quotemeta<regExp>(*this);
211 inline void Foam::wordRe::set(const std::string& str, const compOption opt)
213 string::operator=(str);
218 inline void Foam::wordRe::set(const char* str, const compOption opt)
220 string::operator=(str);
225 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
227 inline const Foam::wordRe& Foam::wordRe::operator=(const wordRe& str)
229 string::operator=(str);
243 inline const Foam::wordRe& Foam::wordRe::operator=(const word& str)
245 word::operator=(str);
251 inline const Foam::wordRe& Foam::wordRe::operator=(const keyType& str)
253 string::operator=(str);
262 inline const Foam::wordRe& Foam::wordRe::operator=(const string& str)
264 string::operator=(str);
265 compile(DETECT); // auto-detect regex
270 inline const Foam::wordRe& Foam::wordRe::operator=(const std::string& str)
272 string::operator=(str);
273 compile(DETECT); // auto-detect regex
278 inline const Foam::wordRe& Foam::wordRe::operator=(const char* str)
280 string::operator=(str);
281 compile(DETECT); // auto-detect regex
286 // ************************************************************************* //