1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
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 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
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()
50 inline Foam::wordRe::wordRe(const wordRe& str)
62 inline Foam::wordRe::wordRe(const word& str)
69 inline Foam::wordRe::wordRe(const char* str, const compOption opt)
78 inline Foam::wordRe::wordRe(const string& str, const compOption opt)
87 inline Foam::wordRe::wordRe(const std::string& str, const compOption opt)
96 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
98 inline bool Foam::wordRe::isPattern() const
104 inline bool Foam::wordRe::compile(const compOption opt) const
106 bool doCompile = false;
108 if (opt & wordRe::REGEXP)
112 else if (opt & wordRe::DETECT)
114 if (string::meta<regExp>(*this) || !string::valid<word>(*this))
119 else if (opt & wordRe::NOCASE)
127 re_.set(*this, (opt & wordRe::NOCASE));
138 inline bool Foam::wordRe::compile() const
145 inline bool Foam::wordRe::recompile() const
156 inline void Foam::wordRe::uncompile(const bool doStripInvalid) const
160 // skip stripping unless debug is active to avoid costly operations
161 if (word::debug && doStripInvalid)
163 string::stripInvalid<word>
165 const_cast<word&>(static_cast<const word&>(*this))
172 inline void Foam::wordRe::clear()
179 inline bool Foam::wordRe::match(const string& str, bool literalMatch) const
181 if (literalMatch || !re_.exists())
184 return (*this == str);
189 return re_.match(str);
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);
207 inline void Foam::wordRe::set(const char* str, const compOption opt)
209 string::operator=(str);
214 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
216 inline const Foam::wordRe& Foam::wordRe::operator=(const wordRe& str)
218 string::operator=(str);
232 inline const Foam::wordRe& Foam::wordRe::operator=(const word& str)
234 word::operator=(str);
240 inline const Foam::wordRe& Foam::wordRe::operator=(const string& str)
242 string::operator=(str);
243 compile(DETECT); // auto-detect regex
248 inline const Foam::wordRe& Foam::wordRe::operator=(const std::string& str)
250 string::operator=(str);
251 compile(DETECT); // auto-detect regex
256 inline const Foam::wordRe& Foam::wordRe::operator=(const char* str)
258 string::operator=(str);
259 compile(DETECT); // auto-detect regex
264 // ************************************************************************* //