00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include <iostream>
00028
00029
00030
00031 inline Foam::string::string()
00032 {}
00033
00034
00035 inline Foam::string::string(const std::string& stdStr)
00036 :
00037 std::string(stdStr)
00038 {}
00039
00040
00041
00042 inline Foam::string::string(const char* str)
00043 :
00044 std::string(str)
00045 {}
00046
00047
00048
00049 inline Foam::string::string(const char* str, const size_type len)
00050 :
00051 std::string(str, len)
00052 {}
00053
00054
00055
00056 inline Foam::string::string(const char c)
00057 :
00058 std::string(1, c)
00059 {}
00060
00061
00062
00063
00064 template<class String>
00065 inline bool Foam::string::valid(const string& s)
00066 {
00067 bool iv = false;
00068
00069 for (const_iterator iter = s.begin(); iter != s.end(); iter++)
00070 {
00071 if (!String::valid(*iter))
00072 {
00073 iv = true;
00074 break;
00075 }
00076 }
00077
00078 return !iv;
00079 }
00080
00081
00082 template<class String>
00083 inline bool Foam::string::stripInvalid(string& s)
00084 {
00085 if (!valid<String>(s))
00086 {
00087 register size_type nValid=0;
00088 iterator iter2 = s.begin();
00089
00090 for
00091 (
00092 const_iterator iter1 = iter2;
00093 iter1 != const_cast<const string&>(s).end();
00094 iter1++
00095 )
00096 {
00097 register char c = *iter1;
00098
00099 if (String::valid(c))
00100 {
00101 *iter2 = c;
00102 ++iter2;
00103 ++nValid;
00104 }
00105 }
00106
00107 s.resize(nValid);
00108
00109 return true;
00110 }
00111
00112 return false;
00113 }
00114
00115
00116 template<class String>
00117 inline String Foam::string::validate(const string& s)
00118 {
00119 string ss = s;
00120 stripInvalid<String>(ss);
00121 return ss;
00122 }
00123
00124
00125
00126
00127 inline Foam::string Foam::string::operator()
00128 (
00129 const size_type i,
00130 const size_type n
00131 ) const
00132 {
00133 return substr(i, n);
00134 }
00135
00136
00137 inline Foam::string Foam::string::operator()(const size_type n) const
00138 {
00139 return substr(0, n);
00140 }
00141
00142
00143 inline Foam::string::hash::hash()
00144 {}
00145
00146
00147 inline Foam::string::size_type Foam::string::hash::operator()
00148 (
00149 const string& key
00150 ) const
00151 {
00152 register size_type hashVal = 0;
00153
00154 for (string::const_iterator iter=key.begin(); iter!=key.end(); ++iter)
00155 {
00156 hashVal = hashVal<<1 ^ *iter;
00157 }
00158
00159 return hashVal;
00160 }
00161
00162
00163 inline Foam::string::size_type Foam::string::hash::operator()
00164 (
00165 const string& key,
00166 const size_type tableSize
00167 ) const
00168 {
00169 return ::abs(operator()(key)) % tableSize;
00170 }
00171
00172
00173
Copyright © 2000-2007 OpenCFD Ltd