|
|
|
string.HGo to the documentation of this file.00001 /*---------------------------------------------------------------------------*\ 00002 ========= | 00003 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox 00004 \\ / O peration | 00005 \\ / A nd | Copyright (C) 1991-2009 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 the 00013 Free Software Foundation; either version 2 of the License, or (at your 00014 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, write to the Free Software Foundation, 00023 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00024 00025 Class 00026 Foam::string 00027 00028 Description 00029 A class for handling character strings derived from std::string. 00030 00031 Strings may contain any characters and therefore are delimited by quotes 00032 for IO : "any list of characters". 00033 00034 Used as a base class for word and fileName. 00035 00036 See Also 00037 Foam::findEtcFile() for information about the site/user OpenFOAM 00038 configuration directory 00039 00040 SourceFiles 00041 string.C 00042 stringIO.C 00043 00044 \*---------------------------------------------------------------------------*/ 00045 00046 #ifndef string_H 00047 #define string_H 00048 00049 #include "char.H" 00050 #include "Hasher.H" 00051 00052 #include <string> 00053 #include <cstring> 00054 #include <cstdlib> 00055 00056 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00057 00058 namespace Foam 00059 { 00060 00061 // Forward declaration of classes 00062 class Istream; 00063 class Ostream; 00064 00065 // Forward declaration of friend functions and operators 00066 class string; 00067 Istream& operator>>(Istream&, string&); 00068 Ostream& operator<<(Ostream&, const string&); 00069 Ostream& operator<<(Ostream&, const std::string&); 00070 00071 00072 /*---------------------------------------------------------------------------*\ 00073 Class string Declaration 00074 \*---------------------------------------------------------------------------*/ 00075 00076 class string 00077 : 00078 public std::string 00079 { 00080 public: 00081 00082 // Static data members 00083 00084 static const char* const typeName; 00085 static int debug; 00086 static const string null; 00087 00088 00089 //- Hashing function class, shared by all the derived classes 00090 class hash 00091 { 00092 public: 00093 hash() 00094 {} 00095 00096 inline unsigned operator()(const string&, unsigned seed = 0) const; 00097 }; 00098 00099 00100 // Constructors 00101 00102 //- Construct null 00103 inline string(); 00104 00105 //- Construct from std::string 00106 inline string(const std::string&); 00107 00108 //- Construct as copy of character array 00109 inline string(const char*); 00110 00111 //- Construct as copy of specified number of characters 00112 inline string(const char*, const size_type); 00113 00114 //- Construct from a single character 00115 inline string(const char); 00116 00117 //- Construct from Istream 00118 string(Istream&); 00119 00120 00121 // Member Functions 00122 00123 //- Count and return the number of a given character in the string 00124 size_type count(const char) const; 00125 00126 //- Is this string type valid? 00127 template<class String> 00128 static inline bool valid(const string&); 00129 00130 //- Does this string have particular meta-characters? 00131 // The meta characters can be optionally quoted. 00132 template<class String> 00133 static inline bool meta(const string&, const char quote='\\'); 00134 00135 //- Strip invalid characters from the given string 00136 template<class String> 00137 static inline bool stripInvalid(string&); 00138 00139 //- Return a valid String from the given string 00140 template<class String> 00141 static inline String validate(const string&); 00142 00143 //- Return a String with quoted meta-characters from the given string 00144 template<class String> 00145 static inline string quotemeta(const string&, const char quote='\\'); 00146 00147 //- Avoid masking the normal std::string replace 00148 using std::string::replace; 00149 00150 //- Replace first occurence of sub-string oldStr with newStr 00151 // starting at start 00152 string& replace 00153 ( 00154 const string& oldStr, 00155 const string& newStr, 00156 size_type start = 0 00157 ); 00158 00159 //- Replace all occurences of sub-string oldStr with newStr 00160 // starting at start 00161 string& replaceAll 00162 ( 00163 const string& oldStr, 00164 const string& newStr, 00165 size_type start = 0 00166 ); 00167 00168 //- Expand initial tildes and all occurences of environment variables 00169 // Expansion includes: 00170 // -# environment variables 00171 // - "$VAR", "${VAR}" 00172 // -# current directory 00173 // - leading "./" : the current directory 00174 // -# tilde expansion 00175 // - leading "~/" : home directory 00176 // - leading "~user" : home directory for specified user 00177 // - leading "~OpenFOAM" : site/user OpenFOAM configuration directory 00178 // 00179 // @sa 00180 // Foam::findEtcFile 00181 string& expand(); 00182 00183 //- Remove repeated characters returning true if string changed 00184 bool removeRepeated(const char); 00185 00186 //- Return string with repeated characters removed 00187 string removeRepeated(const char) const; 00188 00189 //- Remove trailing character returning true if string changed 00190 bool removeTrailing(const char); 00191 00192 //- Return string with trailing character removed 00193 string removeTrailing(const char) const; 00194 00195 00196 // Member Operators 00197 00198 //- Return the sub-string from the i-th character for @a n characters 00199 inline string operator() 00200 ( 00201 const size_type i, 00202 const size_type n 00203 ) const; 00204 00205 //- Return the sub-string from the first character for @a n characters 00206 inline string operator() 00207 ( 00208 const size_type n 00209 ) const; 00210 00211 00212 // IOstream Operators 00213 00214 friend Istream& operator>>(Istream&, string&); 00215 friend Ostream& operator<<(Ostream&, const string&); 00216 }; 00217 00218 00219 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00220 00221 } // End namespace Foam 00222 00223 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00224 00225 #include "stringI.H" 00226 00227 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00228 00229 #endif 00230 00231 // ************************************************************************* // |