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
29 A class for handling character strings derived from std::string.
31 Strings may contain any characters and therefore are delimited by quotes
32 for IO : "any list of characters".
34 Used as a base class for word and fileName.
37 Foam::findEtcFile() for information about the site/user OpenFOAM
38 configuration directory
44 \*---------------------------------------------------------------------------*/
56 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
61 // Forward declaration of classes
65 // Forward declaration of friend functions and operators
67 Istream& operator>>(Istream&, string&);
68 Ostream& operator<<(Ostream&, const string&);
69 Ostream& operator<<(Ostream&, const std::string&);
72 /*---------------------------------------------------------------------------*\
73 Class string Declaration
74 \*---------------------------------------------------------------------------*/
82 // Static data members
84 static const char* const typeName;
86 static const string null;
89 //- Hashing function class, shared by all the derived classes
96 inline unsigned operator()(const string&, unsigned seed = 0) const;
105 //- Construct from std::string
106 inline string(const std::string&);
108 //- Construct as copy of character array
109 inline string(const char*);
111 //- Construct as copy of specified number of characters
112 inline string(const char*, const size_type);
114 //- Construct from a single character
115 inline string(const char);
117 //- Construct from Istream
123 //- Count and return the number of a given character in the string
124 size_type count(const char) const;
126 //- Is this string type valid?
127 template<class String>
128 static inline bool valid(const string&);
130 //- Does this string have particular meta-characters?
131 // The meta characters can be optionally quoted.
132 template<class String>
133 static inline bool meta(const string&, const char quote='\\');
135 //- Strip invalid characters from the given string
136 template<class String>
137 static inline bool stripInvalid(string&);
139 //- Return a valid String from the given string
140 template<class String>
141 static inline String validate(const string&);
143 //- Return a String with quoted meta-characters from the given string
144 template<class String>
145 static inline string quotemeta(const string&, const char quote='\\');
147 //- Avoid masking the normal std::string replace
148 using std::string::replace;
150 //- Replace first occurence of sub-string oldStr with newStr
154 const string& oldStr,
155 const string& newStr,
159 //- Replace all occurences of sub-string oldStr with newStr
163 const string& oldStr,
164 const string& newStr,
168 //- Expand initial tildes and all occurences of environment variables
169 // Expansion includes:
170 // -# environment variables
171 // - "$VAR", "${VAR}"
172 // -# current directory
173 // - leading "./" : the current directory
174 // -# tilde expansion
175 // - leading "~/" : home directory
176 // - leading "~user" : home directory for specified user
177 // - leading "~OpenFOAM" : site/user OpenFOAM configuration directory
183 //- Remove repeated characters returning true if string changed
184 bool removeRepeated(const char);
186 //- Return string with repeated characters removed
187 string removeRepeated(const char) const;
189 //- Remove trailing character returning true if string changed
190 bool removeTrailing(const char);
192 //- Return string with trailing character removed
193 string removeTrailing(const char) const;
198 //- Return the sub-string from the i-th character for @a n characters
199 inline string operator()
205 //- Return the sub-string from the first character for @a n characters
206 inline string operator()
212 // IOstream Operators
214 friend Istream& operator>>(Istream&, string&);
215 friend Ostream& operator<<(Ostream&, const string&);
219 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
221 } // End namespace Foam
223 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
227 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
231 // ************************************************************************* //