00001 /*---------------------------------------------------------------------------*\ 00002 ========= | 00003 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox 00004 \\ / O peration | 00005 \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd. 00006 \\/ M anipulation | 00007 ------------------------------------------------------------------------------- 00008 License 00009 This file is part of OpenFOAM. 00010 00011 OpenFOAM is free software: you can redistribute it and/or modify it 00012 under the terms of the GNU General Public License as published by 00013 the Free Software Foundation, either version 3 of the License, or 00014 (at your option) any later version. 00015 00016 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT 00017 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00018 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 00019 for more details. 00020 00021 You should have received a copy of the GNU General Public License 00022 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>. 00023 00024 Class 00025 Foam::wordRe 00026 00027 Description 00028 A wordRe is a word, but can also have a regular expression for matching 00029 words. 00030 00031 By default the constructors will generally preserve the argument as 00032 string literal and the assignment operators will use the wordRe::DETECT 00033 compOption to scan the string for regular expression meta characters 00034 and/or invalid word characters and react accordingly. 00035 00036 The exceptions are when constructing/assigning from another 00037 Foam::wordRe (preserve the same type) or from a Foam::word (always 00038 literal). 00039 00040 Note 00041 If the string contents are changed - eg, by the operator+=() or by 00042 string::replace(), etc - it will be necessary to use compile() or 00043 recompile() to synchronize the regular expression. 00044 00045 SourceFiles 00046 wordRe.C 00047 wordReIO.C 00048 00049 \*---------------------------------------------------------------------------*/ 00050 00051 #ifndef wordRe_H 00052 #define wordRe_H 00053 00054 #include <OpenFOAM/word.H> 00055 #include <OSspecific/regExp.H> 00056 00057 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00058 00059 namespace Foam 00060 { 00061 00062 // Forward declaration of friend functions and operators 00063 class wordRe; 00064 00065 class Istream; 00066 class Ostream; 00067 00068 Istream& operator>>(Istream&, wordRe&); 00069 Ostream& operator<<(Ostream&, const wordRe&); 00070 00071 00072 /*---------------------------------------------------------------------------*\ 00073 Class wordRe Declaration 00074 \*---------------------------------------------------------------------------*/ 00075 00076 class wordRe 00077 : 00078 public word 00079 { 00080 // Private member data 00081 00082 //- The regular expression 00083 mutable regExp re_; 00084 00085 public: 00086 00087 // Public data types 00088 00089 //- Enumeration with compile options 00090 // Note that 'REGEXP' is implicit if 'NOCASE' is specified alone. 00091 enum compOption 00092 { 00093 LITERAL = 0, 00094 DETECT = 1, 00095 REGEXP = 2, 00096 NOCASE = 4, 00097 DETECT_NOCASE = DETECT | NOCASE, 00098 REGEXP_NOCASE = REGEXP | NOCASE 00099 }; 00100 00101 00102 //- Is this a meta character? 00103 static inline bool meta(char); 00104 00105 //- Test string for regular expression meta characters 00106 static inline bool isPattern(const string&); 00107 00108 // Constructors 00109 00110 //- Construct null 00111 inline wordRe(); 00112 00113 //- Construct as copy 00114 inline wordRe(const wordRe&); 00115 00116 //- Construct as copy of word 00117 inline wordRe(const word&); 00118 00119 //- Construct as copy of character array 00120 // Optionally specify how it should be treated. 00121 inline wordRe(const char*, const compOption=LITERAL); 00122 00123 //- Construct as copy of string. 00124 // Optionally specify how it should be treated. 00125 inline wordRe(const string&, const compOption=LITERAL); 00126 00127 //- Construct as copy of std::string 00128 // Optionally specify how it should be treated. 00129 inline wordRe(const std::string&, const compOption=LITERAL); 00130 00131 //- Construct from Istream 00132 // Words are treated as literals, strings with an auto-test 00133 wordRe(Istream&); 00134 00135 // Member functions 00136 00137 //- Access 00138 00139 //- Should be treated as a match rather than a literal string? 00140 inline bool isPattern() const; 00141 00142 //- Infrastructure 00143 00144 //- Compile the regular expression 00145 inline bool compile() const; 00146 00147 //- Possibly compile the regular expression, with greater control 00148 inline bool compile(const compOption) const; 00149 00150 //- Recompile an existing regular expression 00151 inline bool recompile() const; 00152 00153 //- Frees precompiled regular expression, making wordRe a literal. 00154 // Optionally strips invalid word characters 00155 inline void uncompile(const bool doStripInvalid=false) const; 00156 00157 //- Editing 00158 00159 //- Copy string, auto-test for regular expression or other options 00160 inline void set(const std::string&, const compOption=DETECT); 00161 00162 //- Copy string, auto-test for regular expression or other options 00163 inline void set(const char*, const compOption=DETECT); 00164 00165 //- Clear string and precompiled regular expression 00166 inline void clear(); 00167 00168 //- Searching 00169 00170 //- Smart match as regular expression or as a string 00171 // Optionally specify a literal match only 00172 inline bool match(const string&, bool literalMatch=false) const; 00173 00174 //- Miscellaneous 00175 00176 //- Return a string with quoted meta-characters 00177 inline string quotemeta() const; 00178 00179 //- Output some basic info 00180 Ostream& info(Ostream&) const; 00181 00182 00183 // Member operators 00184 00185 // Assignment 00186 00187 //- Assign copy 00188 // Always case sensitive 00189 inline const wordRe& operator=(const wordRe&); 00190 00191 //- Copy word, never a regular expression 00192 inline const wordRe& operator=(const word&); 00193 00194 //- Copy string, auto-test for regular expression 00195 // Always case sensitive 00196 inline const wordRe& operator=(const string&); 00197 00198 //- Copy string, auto-test for regular expression 00199 // Always case sensitive 00200 inline const wordRe& operator=(const std::string&); 00201 00202 //- Copy string, auto-test for regular expression 00203 // Always case sensitive 00204 inline const wordRe& operator=(const char*); 00205 00206 00207 // IOstream operators 00208 00209 friend Istream& operator>>(Istream&, wordRe&); 00210 friend Ostream& operator<<(Ostream&, const wordRe&); 00211 }; 00212 00213 00214 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00215 00216 } // End namespace Foam 00217 00218 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00219 00220 #include "wordReI.H" 00221 00222 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00223 00224 #endif 00225 00226 // ************************ vim: set sw=4 sts=4 et: ************************ //