1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2009-2011 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
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/>.
28 A wordRe is a word, but can also have a regular expression for matching
31 By default the constructors will generally preserve the argument as a
32 string literal and the assignment operators will use the wordRe::DETECT
33 compOption to scan the string for regular expression meta characters
34 and/or invalid word characters and react accordingly.
36 The exceptions are when constructing/assigning from another
37 Foam::wordRe (preserve the same type) or from a Foam::word (always
41 If the string contents are changed - eg, by the operator+=() or by
42 string::replace(), etc - it will be necessary to use compile() or
43 recompile() to synchronize the regular expression.
48 \*---------------------------------------------------------------------------*/
57 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
62 // Forward declaration of friend functions and operators
67 Istream& operator>>(Istream&, wordRe&);
68 Ostream& operator<<(Ostream&, const wordRe&);
71 /*---------------------------------------------------------------------------*\
72 Class wordRe Declaration
73 \*---------------------------------------------------------------------------*/
79 // Private member data
81 //- The regular expression
86 // Static data members
89 static const wordRe null;
94 //- Enumeration with compile options
95 // Note that 'REGEXP' is implicit if 'NOCASE' is specified alone.
98 LITERAL = 0, /*!< treat as a string literal */
99 DETECT = 1, /*!< treat as regular expression */
100 REGEXP = 2, /*!< detect if the string contains meta-characters */
101 NOCASE = 4, /*!< ignore case in regular expression */
102 DETECT_NOCASE = DETECT | NOCASE,
103 REGEXP_NOCASE = REGEXP | NOCASE
107 //- Is this a meta character?
108 static inline bool meta(char);
110 //- Test string for regular expression meta characters
111 static inline bool isPattern(const string&);
119 //- Construct as copy
120 inline wordRe(const wordRe&);
122 //- Construct from keyType
123 inline wordRe(const keyType&, const compOption=LITERAL);
125 //- Construct as copy of word
126 inline wordRe(const word&);
128 //- Construct as copy of character array
129 // Optionally specify how it should be treated.
130 inline wordRe(const char*, const compOption = LITERAL);
132 //- Construct as copy of string.
133 // Optionally specify how it should be treated.
134 inline wordRe(const string&, const compOption = LITERAL);
136 //- Construct as copy of std::string
137 // Optionally specify how it should be treated.
138 inline wordRe(const std::string&, const compOption = LITERAL);
140 //- Construct from Istream
141 // Words are treated as literals, strings with an auto-test
149 //- Should be treated as a match rather than a literal string?
150 inline bool isPattern() const;
155 //- Compile the regular expression
156 inline bool compile() const;
158 //- Possibly compile the regular expression, with greater control
159 inline bool compile(const compOption) const;
161 //- Recompile an existing regular expression
162 inline bool recompile() const;
164 //- Frees precompiled regular expression, making wordRe a literal.
165 // Optionally strips invalid word characters
166 inline void uncompile(const bool doStripInvalid = false) const;
171 //- Copy string, auto-test for regular expression or other options
172 inline void set(const std::string&, const compOption = DETECT);
174 //- Copy string, auto-test for regular expression or other options
175 inline void set(const char*, const compOption = DETECT);
177 //- Clear string and precompiled regular expression
183 //- Smart match as regular expression or as a string
184 // Optionally force a literal match only
188 bool literalMatch = false
194 //- Return a string with quoted meta-characters
195 inline string quotemeta() const;
197 //- Output some basic info
198 Ostream& info(Ostream&) const;
206 // Always case sensitive
207 inline const wordRe& operator=(const wordRe&);
209 //- Copy word, never a regular expression
210 inline const wordRe& operator=(const word&);
212 //- Copy keyType, auto-test for regular expression
213 // Always case sensitive
214 inline const wordRe& operator=(const keyType&);
216 //- Copy string, auto-test for regular expression
217 // Always case sensitive
218 inline const wordRe& operator=(const string&);
220 //- Copy string, auto-test for regular expression
221 // Always case sensitive
222 inline const wordRe& operator=(const std::string&);
224 //- Copy string, auto-test for regular expression
225 // Always case sensitive
226 inline const wordRe& operator=(const char*);
229 // IOstream operators
231 friend Istream& operator>>(Istream&, wordRe&);
232 friend Ostream& operator<<(Ostream&, const wordRe&);
236 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
238 } // End namespace Foam
240 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
244 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
248 // ************************************************************************* //