 |
Changeset 3840
- Timestamp:
- 08/03/08 14:39:44
(4 months ago)
- Author:
- kris
- Message:
fixes 1172 :: PathParser? does not parse extension properly
suffix() is supposed to include all those '.' characters, but ext() is supposed to ignore them. Fixed a bug in the latter. Adjusted some comments to reflect this
Thanks for the heads' up, eXosypher
-
Files:
-
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
| r3819 |
r3840 |
|
| 14 | 14 | author: Kris |
|---|
| 15 | 15 | |
|---|
| 16 | | FilePath combined a means of efficiently editing and extracting |
|---|
| 17 | | path components and of accessing the underlying file system. |
|---|
| 18 | | |
|---|
| 19 | | Use module Path.d instead when you need only pedestrian access to |
|---|
| 20 | | the file-system, and are not manipulating the path components. Use |
|---|
| 21 | | FilePath for other scenarios, since it will often be notably more |
|---|
| 22 | | efficient |
|---|
| | 16 | FilePath provides a means to efficiently edit path components and |
|---|
| | 17 | of accessing the underlying file system. |
|---|
| | 18 | |
|---|
| | 19 | Use module Path.d instead when you need pedestrian access to the |
|---|
| | 20 | file-system, and are not mutating the path components themselves |
|---|
| 23 | 21 | |
|---|
| 24 | 22 | *******************************************************************************/ |
|---|
| … | … | |
| 51 | 49 | |
|---|
| 52 | 50 | FilePath is designed to be transformed, thus each mutating method |
|---|
| 53 | | modifies the internal content. There is a read-only base-class |
|---|
| 54 | | called PathView, which can be used to provide a view into the |
|---|
| 55 | | content as desired. |
|---|
| | 51 | modifies the internal content. |
|---|
| 56 | 52 | |
|---|
| 57 | 53 | Note that patterns of adjacent '.' separators are treated specially |
|---|
| 58 | | in that they will be assigned to the name instead of the suffix. In |
|---|
| 59 | | addition, a '.' at the start of a name signifies it does not belong |
|---|
| 60 | | to the suffix i.e. ".file" is a name rather than a suffix. |
|---|
| 61 | | |
|---|
| 62 | | Note also that normalization of path-separators occurs by default. |
|---|
| 63 | | This means that the use of '\' characters will be converted into |
|---|
| 64 | | '/' instead while parsing. To mutate the path into an O/S native |
|---|
| 65 | | version, use the native() method. To obtain a copy instead, use the |
|---|
| 66 | | path.dup.native sequence |
|---|
| | 54 | in that they will be assigned to the name where there is no distinct |
|---|
| | 55 | suffix. In addition, a '.' at the start of a name signifies it does |
|---|
| | 56 | not belong to the suffix i.e. ".file" is a name rather than a suffix. |
|---|
| | 57 | Patterns of intermediate '.' characters will otherwise be assigned |
|---|
| | 58 | to the suffix, such that "file....suffix" includes the dots within |
|---|
| | 59 | the suffix itself [see ext() for a suffix without dots]. |
|---|
| 67 | 60 | |
|---|
| 68 | 61 | *******************************************************************************/ |
|---|
| r3760 |
r3840 |
|
| 11 | 11 | A more direct route to the file-system than FilePath, but with |
|---|
| 12 | 12 | the potential overhead of heap activity. Use this if you don't |
|---|
| 13 | | need path editing or extraction features. For example, if all |
|---|
| 14 | | you want is to see if some path exists, using this module might |
|---|
| 15 | | be a more convenient option than FilePath: |
|---|
| | 13 | need path editing features. For example, if all you want is to |
|---|
| | 14 | see if some path exists, using this module would likely be more |
|---|
| | 15 | convenient than FilePath. For example: |
|---|
| 16 | 16 | --- |
|---|
| 17 | 17 | if (exists ("some/file/path")) |
|---|
| … | … | |
| 19 | 19 | --- |
|---|
| 20 | 20 | |
|---|
| 21 | | These functions can be less efficient than FilePath because they |
|---|
| | 21 | These functions may be less efficient than FilePath because they |
|---|
| 22 | 22 | may have to attach a null to the filename for each underlying O/S |
|---|
| 23 | 23 | call. Use Path when you need pedestrian access to the file-system, |
|---|
| 24 | | and are not manipulating the path components. Use FilePath for other |
|---|
| 25 | | scenarios. |
|---|
| | 24 | and are not manipulating the path components. Use FilePath where |
|---|
| | 25 | path editing or mutation is desired. |
|---|
| 26 | 26 | |
|---|
| 27 | 27 | We encourage the use of "scoped import" with this module, such as |
|---|
| … | … | |
| 904 | 904 | |
|---|
| 905 | 905 | Note that patterns of adjacent '.' separators are treated specially |
|---|
| 906 | | in that they will be assigned to the name instead of the suffix. In |
|---|
| 907 | | addition, a '.' at the start of a name signifies it does not belong |
|---|
| 908 | | to the suffix i.e. ".file" is a name rather than a suffix. |
|---|
| | 906 | in that they will be assigned to the name where there is no distinct |
|---|
| | 907 | suffix. In addition, a '.' at the start of a name signifies it does |
|---|
| | 908 | not belong to the suffix i.e. ".file" is a name rather than a suffix. |
|---|
| | 909 | Patterns of intermediate '.' characters will otherwise be assigned |
|---|
| | 910 | to the suffix, such that "file....suffix" includes the dots within |
|---|
| | 911 | the suffix itself [see ext() for a suffix without dots]. |
|---|
| 909 | 912 | |
|---|
| 910 | 913 | Note also that normalization of path-separators occurs by default. |
|---|
| … | … | |
| 918 | 921 | package char[] fp; // filepath with trailing |
|---|
| 919 | 922 | package int end_, // before any trailing 0 |
|---|
| | 923 | ext_, // after rightmost '.' |
|---|
| 920 | 924 | name_, // file/dir name |
|---|
| 921 | 925 | folder_, // path before name |
|---|
| 922 | | suffix_; // after rightmost '.' |
|---|
| | 926 | suffix_; // including leftmost '.' |
|---|
| 923 | 927 | |
|---|
| 924 | 928 | /*********************************************************************** |
|---|
| … | … | |
| 1028 | 1032 | Ext is the tail of the filename, rightward of the rightmost |
|---|
| 1029 | 1033 | '.' separator e.g. path "foo.bar" has ext "bar". Note that |
|---|
| 1030 | | patterns of adjacent separators are treated specially; for |
|---|
| | 1034 | patterns of adjacent separators are treated specially - for |
|---|
| 1031 | 1035 | example, ".." will wind up with no ext at all |
|---|
| 1032 | 1036 | |
|---|
| … | … | |
| 1037 | 1041 | auto x = suffix; |
|---|
| 1038 | 1042 | if (x.length) |
|---|
| 1039 | | x = x [1..$]; |
|---|
| | 1043 | { |
|---|
| | 1044 | if (ext_ is 0) |
|---|
| | 1045 | foreach (c; x) |
|---|
| | 1046 | if (c is '.') |
|---|
| | 1047 | ++ext_; |
|---|
| | 1048 | else |
|---|
| | 1049 | break; |
|---|
| | 1050 | x = x [ext_ .. $]; |
|---|
| | 1051 | } |
|---|
| 1040 | 1052 | return x; |
|---|
| 1041 | 1053 | } |
|---|
Download in other formats:
|
 |
 |
|
 |
Copyright © 2006-2008 Tango. All Rights Reserved. | Page Width:
Static or
Dynamic