 |
Changeset 2812
- Timestamp:
- 11/08/07 16:16:18
(1 year ago)
- Author:
- sean
- Message:
Fixes ticket #738.
-
Files:
-
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
| r2808 |
r2812 |
|
| 77 | 77 | in that they will be assigned to the name instead of the suffix. In |
|---|
| 78 | 78 | addition, a '.' at the start of a name signifies it does not belong |
|---|
| 79 | | to the suffix i.e. ".file" is a name rather than a suffix. |
|---|
| | 79 | to the suffix i.e. ".file" is a name rather than a suffix. |
|---|
| 80 | 80 | |
|---|
| 81 | 81 | Note also that normalization of path-separators is supported by the |
|---|
| 82 | | set() method and via a constructor. Enabling normalization initiates |
|---|
| | 82 | set() method and via a constructor. Enabling normalization initiates |
|---|
| 83 | 83 | replacement of '/' for '\' (or vice versa) for the relevant platform. |
|---|
| 84 | 84 | |
|---|
| … | … | |
| 89 | 89 | |
|---|
| 90 | 90 | class FilePath : PathView |
|---|
| 91 | | { |
|---|
| | 91 | { |
|---|
| 92 | 92 | private char[] fp; // filepath with trailing 0 |
|---|
| 93 | 93 | |
|---|
| … | … | |
| 126 | 126 | /*********************************************************************** |
|---|
| 127 | 127 | |
|---|
| 128 | | Call-site shortcut to create a FilePath instance. This |
|---|
| | 128 | Call-site shortcut to create a FilePath instance. This |
|---|
| 129 | 129 | enables the same syntax as struct usage, so may expose |
|---|
| 130 | 130 | a migration path |
|---|
| … | … | |
| 168 | 168 | Thus, FilePath combines both as a single operation. |
|---|
| 169 | 169 | |
|---|
| 170 | | When enabled, option 'native' will normalize path separators |
|---|
| | 170 | When enabled, option 'native' will normalize path separators |
|---|
| 171 | 171 | to those of the native OS |
|---|
| 172 | 172 | |
|---|
| … | … | |
| 207 | 207 | |
|---|
| 208 | 208 | Note that the nul is always embedded within the string |
|---|
| 209 | | maintained by FilePath, so there's no heap overhead when |
|---|
| | 209 | maintained by FilePath, so there's no heap overhead when |
|---|
| 210 | 210 | making a C call |
|---|
| 211 | 211 | |
|---|
| … | … | |
| 290 | 290 | /*********************************************************************** |
|---|
| 291 | 291 | |
|---|
| 292 | | Suffix is like ext, but includes the separator e.g. path |
|---|
| | 292 | Suffix is like ext, but includes the separator e.g. path |
|---|
| 293 | 293 | "foo.bar" has suffix ".bar" |
|---|
| 294 | 294 | |
|---|
| … | … | |
| 370 | 370 | /*********************************************************************** |
|---|
| 371 | 371 | |
|---|
| 372 | | Returns true if this FilePath has a parent. Note that a |
|---|
| | 372 | Returns true if this FilePath has a parent. Note that a |
|---|
| 373 | 373 | parent is defined by the presence of a path-separator in |
|---|
| 374 | | the path. This means 'foo' within "\foo" is considered a |
|---|
| | 374 | the path. This means 'foo' within "\foo" is considered a |
|---|
| 375 | 375 | child of the root |
|---|
| 376 | 376 | |
|---|
| … | … | |
| 430 | 430 | /*********************************************************************** |
|---|
| 431 | 431 | |
|---|
| 432 | | Prepend a folder to this path. A trailing separator is added |
|---|
| | 432 | Prepend a folder to this path. A trailing separator is added |
|---|
| 433 | 433 | if needed |
|---|
| 434 | 434 | |
|---|
| … | … | |
| 455 | 455 | /*********************************************************************** |
|---|
| 456 | 456 | |
|---|
| 457 | | Reset the content of this path, and reparse. When enabled, |
|---|
| | 457 | Reset the content of this path, and reparse. When enabled, |
|---|
| 458 | 458 | option 'native' will normalize path separators to those of |
|---|
| 459 | 459 | the native OS |
|---|
| … | … | |
| 479 | 479 | /*********************************************************************** |
|---|
| 480 | 480 | |
|---|
| 481 | | Sidestep the normal lookup for paths that are known to |
|---|
| 482 | | be folders. Where folder is true, file-system lookups |
|---|
| | 481 | Sidestep the normal lookup for paths that are known to |
|---|
| | 482 | be folders. Where folder is true, file-system lookups |
|---|
| 483 | 483 | will be skipped. |
|---|
| 484 | 484 | |
|---|
| … | … | |
| 508 | 508 | /*********************************************************************** |
|---|
| 509 | 509 | |
|---|
| 510 | | Replace the folder portion of this path. The folder will be |
|---|
| | 510 | Replace the folder portion of this path. The folder will be |
|---|
| 511 | 511 | padded with a path-separator as required |
|---|
| 512 | 512 | |
|---|
| … | … | |
| 536 | 536 | /*********************************************************************** |
|---|
| 537 | 537 | |
|---|
| 538 | | Replace the suffix portion of this path. The suffix will be |
|---|
| | 538 | Replace the suffix portion of this path. The suffix will be |
|---|
| 539 | 539 | prefixed with a file-separator as required |
|---|
| 540 | 540 | |
|---|
| … | … | |
| 549 | 549 | /*********************************************************************** |
|---|
| 550 | 550 | |
|---|
| 551 | | Replace the root and folder portions of this path and |
|---|
| | 551 | Replace the root and folder portions of this path and |
|---|
| 552 | 552 | reparse. The replacement will be padded with a path |
|---|
| 553 | 553 | separator as required |
|---|
| 554 | | |
|---|
| | 554 | |
|---|
| 555 | 555 | ***********************************************************************/ |
|---|
| 556 | 556 | |
|---|
| … | … | |
| 563 | 563 | /*********************************************************************** |
|---|
| 564 | 564 | |
|---|
| 565 | | Replace the file and suffix portions of this path and |
|---|
| | 565 | Replace the file and suffix portions of this path and |
|---|
| 566 | 566 | reparse. The replacement will be prefixed with a suffix |
|---|
| 567 | 567 | separator as required |
|---|
| 568 | | |
|---|
| | 568 | |
|---|
| 569 | 569 | ***********************************************************************/ |
|---|
| 570 | 570 | |
|---|
| … | … | |
| 577 | 577 | /*********************************************************************** |
|---|
| 578 | 578 | |
|---|
| 579 | | Pop to the parent of the current filepath (in situ) |
|---|
| | 579 | Pop to the parent of the current filepath (in situ) |
|---|
| 580 | 580 | |
|---|
| 581 | 581 | ***********************************************************************/ |
|---|
| … | … | |
| 736 | 736 | /*********************************************************************** |
|---|
| 737 | 737 | |
|---|
| 738 | | Insert/delete internal content |
|---|
| | 738 | Insert/delete internal content |
|---|
| 739 | 739 | |
|---|
| 740 | 740 | ***********************************************************************/ |
|---|
| … | … | |
| 830 | 830 | FileSystem.toAbsolute() |
|---|
| 831 | 831 | |
|---|
| 832 | | Note that each segment is created as a folder, including the |
|---|
| | 832 | Note that each segment is created as a folder, including the |
|---|
| 833 | 833 | trailing segment. |
|---|
| 834 | 834 | |
|---|
| … | … | |
| 872 | 872 | --- |
|---|
| 873 | 873 | |
|---|
| 874 | | Returning true from the filter includes the given path, |
|---|
| | 874 | Returning true from the filter includes the given path, |
|---|
| 875 | 875 | whilst returning false excludes it. Parameter 'isFolder' |
|---|
| 876 | 876 | indicates whether the path is a file or folder. |
|---|
| … | … | |
| 890 | 890 | // test this entry for inclusion |
|---|
| 891 | 891 | if (filter is null || filter (p, info.folder)) |
|---|
| 892 | | paths ~= p; |
|---|
| | 892 | paths ~= p; |
|---|
| 893 | 893 | else |
|---|
| 894 | 894 | delete p; |
|---|
| … | … | |
| 914 | 914 | tmp [0 .. info.path.length] = info.path; |
|---|
| 915 | 915 | tmp [info.path.length .. len] = info.name; |
|---|
| 916 | | |
|---|
| | 916 | |
|---|
| 917 | 917 | return FilePath(tmp[0 .. len]).isFolder(info.folder); |
|---|
| 918 | 918 | } |
|---|
| … | … | |
| 966 | 966 | private wchar[] toUtf16 (wchar[] tmp, char[] path) |
|---|
| 967 | 967 | { |
|---|
| 968 | | auto i = MultiByteToWideChar (CP_UTF8, 0, |
|---|
| 969 | | path.ptr, path.length, |
|---|
| | 968 | auto i = MultiByteToWideChar (CP_UTF8, 0, |
|---|
| | 969 | path.ptr, path.length, |
|---|
| 970 | 970 | tmp.ptr, tmp.length); |
|---|
| 971 | 971 | return tmp [0..i]; |
|---|
| … | … | |
| 980 | 980 | private char[] toUtf8 (char[] tmp, wchar[] path) |
|---|
| 981 | 981 | { |
|---|
| 982 | | auto i = WideCharToMultiByte (CP_UTF8, 0, path.ptr, path.length, |
|---|
| | 982 | auto i = WideCharToMultiByte (CP_UTF8, 0, path.ptr, path.length, |
|---|
| 983 | 983 | tmp.ptr, tmp.length, null, null); |
|---|
| 984 | 984 | return tmp [0..i]; |
|---|
| … | … | |
| 1061 | 1061 | /*************************************************************** |
|---|
| 1062 | 1062 | |
|---|
| 1063 | | Is this file actually a folder/directory? |
|---|
| | 1063 | Is this file actually a folder/directory? |
|---|
| 1064 | 1064 | |
|---|
| 1065 | 1065 | ***************************************************************/ |
|---|
| … | … | |
| 1178 | 1178 | int result; |
|---|
| 1179 | 1179 | char[] cstr = dst ~ '\0'; |
|---|
| 1180 | | |
|---|
| | 1180 | |
|---|
| 1181 | 1181 | version (Win32SansUnicode) |
|---|
| 1182 | 1182 | result = MoveFileExA (this.cString.ptr, cstr.ptr, Typical); |
|---|
| … | … | |
| 1252 | 1252 | List the set of filenames within this folder. |
|---|
| 1253 | 1253 | |
|---|
| 1254 | | Each path and filename is passed to the provided |
|---|
| 1255 | | delegate, along with the path prefix and whether |
|---|
| | 1254 | Each path and filename is passed to the provided |
|---|
| | 1255 | delegate, along with the path prefix and whether |
|---|
| 1256 | 1256 | the entry is a folder or not. |
|---|
| 1257 | 1257 | |
|---|
| … | … | |
| 1401 | 1401 | static Time convert (timeval* tv) |
|---|
| 1402 | 1402 | { |
|---|
| 1403 | | return cast(Time) (Time.TicksTo1970 + (1_000_000L * |
|---|
| | 1403 | return cast(Time) (Time.TicksTo1970 + (1_000_000L * |
|---|
| 1404 | 1404 | tv.tv_sec + tv.tv_usec) * 10); |
|---|
| 1405 | 1405 | } |
|---|
| … | … | |
| 1548 | 1548 | List the set of filenames within this folder. |
|---|
| 1549 | 1549 | |
|---|
| 1550 | | Each path and filename is passed to the provided |
|---|
| 1551 | | delegate, along with the path prefix and whether |
|---|
| | 1550 | Each path and filename is passed to the provided |
|---|
| | 1551 | delegate, along with the path prefix and whether |
|---|
| 1552 | 1552 | the entry is a folder or not. |
|---|
| 1553 | 1553 | |
|---|
| … | … | |
| 1596 | 1596 | if (stat (sfnbuf.ptr, &sbuf)) |
|---|
| 1597 | 1597 | exception; |
|---|
| 1598 | | |
|---|
| | 1598 | |
|---|
| 1599 | 1599 | FileInfo info = void; |
|---|
| 1600 | 1600 | info.name = str; |
|---|
| … | … | |
| 1603 | 1603 | info.bytes = (sbuf.st_mode & S_IFREG) != 0 ? sbuf.st_size : 0; |
|---|
| 1604 | 1604 | |
|---|
| 1605 | | if ((ret = dg(&info)) != 0) |
|---|
| | 1605 | if ((ret = dg(info)) != 0) |
|---|
| 1606 | 1606 | break; |
|---|
| 1607 | 1607 | } |
|---|
| … | … | |
| 1692 | 1692 | /*********************************************************************** |
|---|
| 1693 | 1693 | |
|---|
| 1694 | | Suffix is like ext, but includes the separator e.g. path |
|---|
| | 1694 | Suffix is like ext, but includes the separator e.g. path |
|---|
| 1695 | 1695 | "foo.bar" has suffix ".bar" |
|---|
| 1696 | 1696 | |
|---|
Download in other formats:
|
 |
 |
|
 |
Copyright © 2006-2008 Tango. All Rights Reserved. | Page Width:
Static or
Dynamic