00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 INLINE Filename::
00021 Filename(const string &filename) {
00022 _flags = 0;
00023 (*this) = filename;
00024 }
00025
00026
00027
00028
00029
00030
00031 INLINE Filename::
00032 Filename(const wstring &filename) {
00033 _flags = 0;
00034 (*this) = filename;
00035 }
00036
00037
00038
00039
00040
00041
00042 INLINE Filename::
00043 Filename(const char *filename) {
00044 _flags = 0;
00045 (*this) = filename;
00046 }
00047
00048
00049
00050
00051
00052
00053
00054 INLINE Filename::
00055 Filename(const Filename ©) :
00056 _filename(copy._filename.c_str()),
00057 _dirname_end(copy._dirname_end),
00058 _basename_start(copy._basename_start),
00059 _basename_end(copy._basename_end),
00060 _extension_start(copy._extension_start),
00061 _hash_start(copy._hash_start),
00062 _hash_end(copy._hash_end),
00063 _flags(copy._flags)
00064 {
00065 }
00066
00067
00068
00069
00070
00071
00072 INLINE Filename Filename::
00073 text_filename(const Filename &filename) {
00074 Filename result(filename);
00075 result.set_text();
00076 return result;
00077 }
00078
00079
00080
00081
00082
00083
00084 INLINE Filename Filename::
00085 text_filename(const string &filename) {
00086 Filename result(filename);
00087 result.set_text();
00088 return result;
00089 }
00090
00091
00092
00093
00094
00095
00096 INLINE Filename Filename::
00097 binary_filename(const Filename &filename) {
00098 Filename result(filename);
00099 result.set_binary();
00100 return result;
00101 }
00102
00103
00104
00105
00106
00107
00108 INLINE Filename Filename::
00109 binary_filename(const string &filename) {
00110 Filename result(filename);
00111 result.set_binary();
00112 return result;
00113 }
00114
00115
00116
00117
00118
00119
00120 INLINE Filename Filename::
00121 dso_filename(const string &filename) {
00122 Filename result(filename);
00123 result.set_type(T_dso);
00124 return result;
00125 }
00126
00127
00128
00129
00130
00131
00132 INLINE Filename Filename::
00133 executable_filename(const string &filename) {
00134 Filename result(filename);
00135 result.set_type(T_executable);
00136 return result;
00137 }
00138
00139
00140
00141
00142
00143
00144
00145 INLINE Filename Filename::
00146 pattern_filename(const string &filename) {
00147 Filename result(filename);
00148 result.set_pattern(true);
00149 return result;
00150 }
00151
00152
00153
00154
00155
00156
00157 INLINE Filename::
00158 ~Filename() {
00159 }
00160
00161
00162
00163
00164
00165
00166
00167 INLINE Filename &Filename::
00168 operator = (const string &filename) {
00169 _filename = filename;
00170
00171 locate_basename();
00172 locate_extension();
00173 locate_hash();
00174 return *this;
00175 }
00176
00177
00178
00179
00180
00181
00182 INLINE Filename &Filename::
00183 operator = (const wstring &filename) {
00184 TextEncoder encoder;
00185 encoder.set_encoding(get_filesystem_encoding());
00186 encoder.set_wtext(filename);
00187 return operator = (encoder.get_text());
00188 }
00189
00190
00191
00192
00193
00194
00195 INLINE Filename &Filename::
00196 operator = (const char *filename) {
00197 assert(filename != NULL);
00198 return (*this) = string(filename);
00199 }
00200
00201
00202
00203
00204
00205
00206 INLINE Filename &Filename::
00207 operator = (const Filename ©) {
00208 _filename = copy._filename;
00209 _dirname_end = copy._dirname_end;
00210 _basename_start = copy._basename_start;
00211 _basename_end = copy._basename_end;
00212 _extension_start = copy._extension_start;
00213 _hash_start = copy._hash_start;
00214 _hash_end = copy._hash_end;
00215 _flags = copy._flags;
00216 return *this;
00217 }
00218
00219
00220
00221
00222
00223
00224
00225 INLINE Filename::
00226 operator const string & () const {
00227 return _filename;
00228 }
00229
00230
00231
00232
00233
00234
00235 INLINE const char *Filename::
00236 c_str() const {
00237 return _filename.c_str();
00238 }
00239
00240
00241
00242
00243
00244
00245 INLINE bool Filename::
00246 empty() const {
00247 return _filename.empty();
00248 }
00249
00250
00251
00252
00253
00254
00255 INLINE size_t Filename::
00256 length() const {
00257 return _filename.length();
00258 }
00259
00260
00261
00262
00263
00264
00265 INLINE char Filename::
00266 operator [] (int n) const {
00267 assert(n >= 0 && n < (int)_filename.length());
00268 return _filename[n];
00269 }
00270
00271
00272
00273
00274
00275
00276 INLINE string Filename::
00277 substr(size_t begin, size_t end) const {
00278 return _filename.substr(begin, end);
00279 }
00280
00281
00282
00283
00284
00285
00286
00287
00288 INLINE void Filename::
00289 operator += (const string &other) {
00290 _filename += other;
00291 locate_basename();
00292 locate_extension();
00293 locate_hash();
00294 }
00295
00296
00297
00298
00299
00300
00301
00302 INLINE Filename Filename::
00303 operator + (const string &other) const {
00304 Filename a(*this);
00305 a += other;
00306 return a;
00307 }
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317 INLINE string Filename::
00318 get_fullpath() const {
00319 return _filename;
00320 }
00321
00322
00323
00324
00325
00326
00327
00328 INLINE wstring Filename::
00329 get_fullpath_w() const {
00330 TextEncoder encoder;
00331 encoder.set_encoding(get_filesystem_encoding());
00332 encoder.set_text(get_fullpath());
00333 return encoder.get_wtext();
00334 }
00335
00336
00337
00338
00339
00340
00341
00342
00343 INLINE string Filename::
00344 get_dirname() const {
00345 return _filename.substr(0, _dirname_end);
00346 }
00347
00348
00349
00350
00351
00352
00353
00354
00355 INLINE string Filename::
00356 get_basename() const {
00357 return _filename.substr(_basename_start);
00358 }
00359
00360
00361
00362
00363
00364
00365
00366
00367 INLINE string Filename::
00368 get_fullpath_wo_extension() const {
00369 return _filename.substr(0, _basename_end);
00370 }
00371
00372
00373
00374
00375
00376
00377
00378
00379 INLINE string Filename::
00380 get_basename_wo_extension() const {
00381 if (_basename_end == string::npos) {
00382 return _filename.substr(_basename_start);
00383 } else {
00384 return _filename.substr(_basename_start, _basename_end - _basename_start);
00385 }
00386 }
00387
00388
00389
00390
00391
00392
00393
00394
00395
00396 INLINE string Filename::
00397 get_extension() const {
00398 if (_extension_start == string::npos) {
00399 return string();
00400 } else {
00401 return _filename.substr(_extension_start);
00402 }
00403 }
00404
00405
00406
00407
00408
00409
00410
00411
00412
00413 INLINE void Filename::
00414 set_binary() {
00415 _flags = (_flags & ~F_text) | F_binary;
00416 }
00417
00418
00419
00420
00421
00422
00423
00424
00425
00426 INLINE void Filename::
00427 set_text() {
00428 _flags = (_flags & ~F_binary) | F_text;
00429 }
00430
00431
00432
00433
00434
00435
00436
00437
00438
00439
00440 INLINE bool Filename::
00441 is_binary() const {
00442 return ((_flags & F_binary) != 0);
00443 }
00444
00445
00446
00447
00448
00449
00450
00451
00452
00453 INLINE bool Filename::
00454 is_binary_or_text() const {
00455 return ((_flags & (F_binary | F_text)) != 0);
00456 }
00457
00458
00459
00460
00461
00462
00463
00464
00465
00466
00467 INLINE bool Filename::
00468 is_text() const {
00469 return ((_flags & F_text) != 0);
00470 }
00471
00472
00473
00474
00475
00476
00477
00478
00479
00480
00481
00482
00483 INLINE void Filename::
00484 set_type(Filename::Type type) {
00485 _flags = (_flags & ~F_type) | type;
00486 switch (type) {
00487 case T_dso:
00488 case T_executable:
00489 set_binary();
00490
00491 case T_general:
00492 break;
00493 }
00494 }
00495
00496
00497
00498
00499
00500
00501
00502 INLINE Filename::Type Filename::
00503 get_type() const {
00504 return (Type)(_flags & (int)F_type);
00505 }
00506
00507
00508
00509
00510
00511
00512
00513
00514
00515
00516
00517
00518
00519
00520
00521
00522
00523
00524
00525 INLINE void Filename::
00526 set_pattern(bool pattern) {
00527 if (pattern != get_pattern()) {
00528 if (pattern) {
00529 _flags |= F_pattern;
00530 } else {
00531 _flags &= ~F_pattern;
00532 }
00533 locate_hash();
00534 }
00535 }
00536
00537
00538
00539
00540
00541
00542
00543 INLINE bool Filename::
00544 get_pattern() const {
00545 return (_flags & F_pattern) != 0;
00546 }
00547
00548
00549
00550
00551
00552
00553
00554
00555
00556
00557
00558
00559 INLINE bool Filename::
00560 has_hash() const {
00561 return (_hash_start != _hash_end);
00562 }
00563
00564
00565
00566
00567
00568
00569
00570
00571 INLINE string Filename::
00572 get_hash_to_end() const {
00573 return _filename.substr(_hash_start);
00574 }
00575
00576
00577
00578
00579
00580
00581
00582
00583 INLINE bool Filename::
00584 is_local() const {
00585 return _filename.empty() || _filename[0] != '/';
00586 }
00587
00588
00589
00590
00591
00592
00593
00594
00595
00596
00597
00598
00599
00600
00601 INLINE bool Filename::
00602 is_fully_qualified() const {
00603 return
00604 (_filename.size() > 2 && _filename[0] == '.' && _filename[1] == '/') ||
00605 (!_filename.empty() && _filename[0] == '/');
00606 }
00607
00608
00609
00610
00611
00612
00613 INLINE bool Filename::
00614 operator == (const string &other) const {
00615 return (*(string *)this) == other;
00616 }
00617
00618
00619
00620
00621
00622
00623 INLINE bool Filename::
00624 operator != (const string &other) const {
00625 return (*(string *)this) != other;
00626 }
00627
00628
00629
00630
00631
00632
00633 INLINE bool Filename::
00634 operator < (const string &other) const {
00635 return (*(string *)this) < other;
00636 }
00637
00638
00639
00640
00641
00642
00643 INLINE int Filename::
00644 compare_to(const Filename &other) const {
00645 return strcmp(_filename.c_str(), other._filename.c_str());
00646 }
00647
00648
00649
00650
00651
00652
00653
00654
00655
00656
00657
00658
00659
00660
00661 INLINE bool Filename::
00662 __nonzero__() const {
00663 return !_filename.empty();
00664 }
00665
00666
00667
00668
00669
00670
00671 INLINE void Filename::
00672 output(ostream &out) const {
00673 out << _filename;
00674 }
00675
00676
00677
00678
00679
00680
00681
00682
00683
00684
00685 INLINE void Filename::
00686 set_filesystem_encoding(TextEncoder::Encoding encoding) {
00687 _filesystem_encoding = encoding;
00688 }
00689
00690
00691
00692
00693
00694
00695
00696
00697 INLINE TextEncoder::Encoding Filename::
00698 get_filesystem_encoding() {
00699 return _filesystem_encoding;
00700 }