1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2004-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 class for handling character strings derived from std::string.
30 Strings may contain any characters and therefore are delimited by quotes
31 for IO : "any list of characters".
33 Used as a base class for word and fileName.
36 Foam::findEtcFile() for information about the site/user OpenFOAM
37 configuration directory
43 \*---------------------------------------------------------------------------*/
55 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
60 // Forward declaration of classes
64 // Forward declaration of friend functions and operators
66 Istream& operator>>(Istream&, string&);
67 Ostream& operator<<(Ostream&, const string&);
68 Ostream& operator<<(Ostream&, const std::string&);
71 /*---------------------------------------------------------------------------*\
72 Class string Declaration
73 \*---------------------------------------------------------------------------*/
81 // Static data members
83 static const char* const typeName;
87 static const string null;
90 //- Hashing function class, shared by all the derived classes
97 inline unsigned operator()(const string&, unsigned seed = 0) const;
106 //- Construct from std::string
107 inline string(const std::string&);
109 //- Construct as copy of character array
110 inline string(const char*);
112 //- Construct as copy of specified number of characters
113 inline string(const char*, const size_type);
115 //- Construct from a single character
116 inline string(const char);
118 //- Construct from Istream
124 //- Count and return the number of a given character in the string
125 size_type count(const char) const;
127 //- Is this string type valid?
128 template<class String>
129 static inline bool valid(const string&);
131 //- Does this string have particular meta-characters?
132 // The meta characters can be optionally quoted.
133 template<class String>
134 static inline bool meta(const string&, const char quote='\\');
136 //- Strip invalid characters from the given string
137 template<class String>
138 static inline bool stripInvalid(string&);
140 //- Return a valid String from the given string
141 template<class String>
142 static inline String validate(const string&);
144 //- Return a String with quoted meta-characters from the given string
145 template<class String>
146 static inline string quotemeta(const string&, const char quote='\\');
148 //- True when strings match literally
149 inline bool match(const std::string&) const;
151 //- Avoid masking the normal std::string replace
152 using std::string::replace;
154 //- Replace first occurence of sub-string oldStr with newStr
158 const string& oldStr,
159 const string& newStr,
163 //- Replace all occurences of sub-string oldStr with newStr
167 const string& oldStr,
168 const string& newStr,
172 //- Expand initial tildes and all occurences of environment variables
173 // Expansion includes:
174 // -# environment variables
175 // - "$VAR", "${VAR}"
176 // -# current directory
177 // - leading "./" : the current directory
178 // -# tilde expansion
179 // - leading "~/" : home directory
180 // - leading "~user" : home directory for specified user
181 // - leading "~OpenFOAM" : site/user OpenFOAM configuration directory
183 // Any unknown entries are removed silently if allowEmpty is true
186 string& expand(const bool allowEmpty = false);
188 //- Remove repeated characters returning true if string changed
189 bool removeRepeated(const char);
191 //- Return string with repeated characters removed
192 string removeRepeated(const char) const;
194 //- Remove trailing character returning true if string changed
195 bool removeTrailing(const char);
197 //- Return string with trailing character removed
198 string removeTrailing(const char) const;
203 //- Return the sub-string from the i-th character for \a n characters
204 inline string operator()
210 //- Return the sub-string from the first character for \a n characters
211 inline string operator()
217 // IOstream Operators
219 friend Istream& operator>>(Istream&, string&);
220 friend Ostream& operator<<(Ostream&, const string&);
224 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
226 } // End namespace Foam
228 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
232 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
236 // ************************************************************************* //