![]() |
|
00001 /*---------------------------------------------------------------------------*\ 00002 ========= | 00003 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox 00004 \\ / O peration | 00005 \\ / A nd | Copyright (C) 1991-2005 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 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 SourceFiles 00037 string.C 00038 stringIO.C 00039 00040 \*---------------------------------------------------------------------------*/ 00041 00042 #ifndef string_H 00043 #define string_H 00044 00045 #include "char.H" 00046 00047 #include <string> 00048 00049 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00050 00051 namespace Foam 00052 { 00053 00054 class Istream; 00055 class Ostream; 00056 00057 /*---------------------------------------------------------------------------*\ 00058 Class string Declaration 00059 \*---------------------------------------------------------------------------*/ 00060 00061 class string 00062 : 00063 public std::string 00064 { 00065 00066 protected: 00067 00068 // Protected member functions 00069 00070 public: 00071 00072 //- Debug switch 00073 static int debug; 00074 00075 //- Null string 00076 static const string null; 00077 00078 //- Hashing function class 00079 class hash 00080 { 00081 00082 public: 00083 00084 inline hash(); 00085 00086 inline size_type operator()(const string& key) const; 00087 00088 inline size_type operator() 00089 ( 00090 const string& key, 00091 const size_type tableSize 00092 ) const; 00093 }; 00094 00095 00096 // Constructors 00097 00098 //- Construct null 00099 inline string(); 00100 00101 //- Construct from std::string 00102 inline string(const std::string&); 00103 00104 //- Construct as copy of character array 00105 inline string(const char*); 00106 00107 //- Construct as copy of specified number of characters 00108 inline string(const char*, const size_type); 00109 00110 //- Construct from a single character 00111 inline string(const char); 00112 00113 //- Construct from Istream 00114 string(Istream&); 00115 00116 00117 // Member Functions 00118 00119 // Access 00120 00121 //- Count and return the number of a given character in the string 00122 size_type count(const char) const; 00123 00124 //- Is this string type valid 00125 template<class String> 00126 static inline bool valid(const string&); 00127 00128 00129 // Edit 00130 00131 //- Strip invalid characters from the given string 00132 template<class String> 00133 static inline bool stripInvalid(string&); 00134 00135 //- Return a valid String from the given string 00136 template<class String> 00137 static inline String validate(const string&); 00138 00139 //- Replace first occurence of sub-string oldStr with newStr 00140 // starting at start 00141 string& replace 00142 ( 00143 const string& oldStr, 00144 const string& newStr, 00145 size_type start = 0 00146 ); 00147 00148 //- Replace all occurences of sub-string oldStr with newStr 00149 // starting at start 00150 string& replaceAll 00151 ( 00152 const string& oldStr, 00153 const string& newStr, 00154 size_type start = 0 00155 ); 00156 00157 //- Expand all occurences of environment variables and ~ 00158 string& expand(); 00159 00160 00161 // Member Operators 00162 00163 // Return the sub-string from the ith character for l characters 00164 inline string operator() 00165 ( 00166 const size_type i, 00167 const size_type n 00168 ) const; 00169 00170 // Return the sub-string from the first character for l characters 00171 inline string operator() 00172 ( 00173 const size_type n 00174 ) const; 00175 00176 00177 // IOstream Operators 00178 00179 friend Istream& operator>>(Istream&, string&); 00180 friend Ostream& operator<<(Ostream&, const string&); 00181 }; 00182 00183 00184 Ostream& operator<<(Ostream&, const std::string&); 00185 00186 00187 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00188 00189 } // End namespace Foam 00190 00191 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00192 00193 #include "stringI.H" 00194 00195 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00196 00197 #endif 00198 00199 // ************************************************************************* //