fileName.C
Go to the documentation of this file.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 "fileName.H"
00028 #include "wordList.H"
00029 #include "DynamicList.H"
00030 #include "debug.H"
00031 #include "OSspecific.H"
00032
00033
00034
00035 const char* const Foam::fileName::typeName = "fileName";
00036 int Foam::fileName::debug(debug::debugSwitch(fileName::typeName, 0));
00037 const Foam::fileName Foam::fileName::null;
00038
00039
00040
00041 Foam::fileName::fileName(const wordList& lst)
00042 {
00043 forAll(lst, elemI)
00044 {
00045 operator=((*this)/lst[elemI]);
00046 }
00047 }
00048
00049
00050
00051
00052 Foam::fileName::Type Foam::fileName::type() const
00053 {
00054 return ::Foam::type(*this);
00055 }
00056
00057
00058 bool Foam::fileName::clean()
00059 {
00060 bool changed = false;
00061
00062 changed = this->removeRepeated('/') || changed;
00063 changed = this->removeTrailing('/') || changed;
00064
00065 return changed;
00066 }
00067
00068
00069
00070 Foam::fileName Foam::fileName::clean() const
00071 {
00072 fileName fName(*this);
00073 fName.clean();
00074 return fName;
00075 }
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090 Foam::word Foam::fileName::name() const
00091 {
00092 size_type i = rfind('/');
00093
00094 if (i == npos)
00095 {
00096 return *this;
00097 }
00098 else
00099 {
00100 return substr(i+1, npos);
00101 }
00102 }
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116 Foam::fileName Foam::fileName::path() const
00117 {
00118 size_type i = rfind('/');
00119
00120 if (i == npos)
00121 {
00122 return ".";
00123 }
00124 else if (i)
00125 {
00126 return substr(0, i);
00127 }
00128 else
00129 {
00130 return "/";
00131 }
00132 }
00133
00134
00135
00136 Foam::fileName Foam::fileName::lessExt() const
00137 {
00138 size_type i = find_last_of("./");
00139
00140 if (i == npos || i == 0 || operator[](i) == '/')
00141 {
00142 return *this;
00143 }
00144 else
00145 {
00146 return substr(0, i);
00147 }
00148 }
00149
00150
00151
00152 Foam::word Foam::fileName::ext() const
00153 {
00154 size_type i = find_last_of("./");
00155
00156 if (i == npos || i == 0 || operator[](i) == '/')
00157 {
00158 return word::null;
00159 }
00160 else
00161 {
00162 return substr(i+1, npos);
00163 }
00164 }
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180 Foam::wordList Foam::fileName::components(const char delimiter) const
00181 {
00182 DynamicList<word> wrdList(20);
00183
00184 size_type start=0, end=0;
00185
00186 while ((end = find(delimiter, start)) != npos)
00187 {
00188
00189 if (start < end)
00190 {
00191 wrdList.append(substr(start, end-start));
00192 }
00193 start = end + 1;
00194 }
00195
00196
00197 if (start < size())
00198 {
00199 wrdList.append(substr(start, npos));
00200 }
00201
00202
00203 return wordList(wrdList.xfer());
00204 }
00205
00206
00207
00208 Foam::word Foam::fileName::component
00209 (
00210 const size_type cmpt,
00211 const char delimiter
00212 ) const
00213 {
00214 return components(delimiter)[cmpt];
00215 }
00216
00217
00218
00219
00220 const Foam::fileName& Foam::fileName::operator=(const fileName& str)
00221 {
00222 string::operator=(str);
00223 return *this;
00224 }
00225
00226
00227 const Foam::fileName& Foam::fileName::operator=(const word& str)
00228 {
00229 string::operator=(str);
00230 return *this;
00231 }
00232
00233
00234 const Foam::fileName& Foam::fileName::operator=(const string& str)
00235 {
00236 string::operator=(str);
00237 stripInvalid();
00238 return *this;
00239 }
00240
00241
00242 const Foam::fileName& Foam::fileName::operator=(const std::string& str)
00243 {
00244 string::operator=(str);
00245 stripInvalid();
00246 return *this;
00247 }
00248
00249
00250 const Foam::fileName& Foam::fileName::operator=(const char* str)
00251 {
00252 string::operator=(str);
00253 stripInvalid();
00254 return *this;
00255 }
00256
00257
00258
00259
00260 Foam::fileName Foam::operator/(const string& a, const string& b)
00261 {
00262 if (a.size())
00263 {
00264 if (b.size())
00265 {
00266 return fileName(a + '/' + b);
00267 }
00268 else
00269 {
00270 return a;
00271 }
00272 }
00273 else
00274 {
00275 if (b.size())
00276 {
00277 return b;
00278 }
00279 else
00280 {
00281 return fileName();
00282 }
00283 }
00284 }
00285
00286
00287
Copyright © 2000-2009 OpenCFD Ltd