Download Reference Manual
The Developer's Library for D
About Wiki Forums Source Search Contact

Changeset 3840

Show
Ignore:
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
  • trunk/tango/io/FilePath.d

    r3819 r3840  
    1414        author:         Kris 
    1515 
    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 
    2321 
    2422*******************************************************************************/ 
     
    5149 
    5250        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.  
    5652 
    5753        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]. 
    6760 
    6861*******************************************************************************/ 
  • trunk/tango/io/Path.d

    r3760 r3840  
    1111        A more direct route to the file-system than FilePath, but with  
    1212        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
    1616        --- 
    1717        if (exists ("some/file/path"))  
     
    1919        --- 
    2020 
    21         These functions can be less efficient than FilePath because they  
     21        These functions may be less efficient than FilePath because they  
    2222        may have to attach a null to the filename for each underlying O/S 
    2323        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
    2626 
    2727        We encourage the use of "scoped import" with this module, such as 
     
    904904 
    905905        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]. 
    909912 
    910913        Note also that normalization of path-separators occurs by default.  
     
    918921        package char[]  fp;                     // filepath with trailing 
    919922        package int     end_,                   // before any trailing 0 
     923                        ext_,                   // after rightmost '.' 
    920924                        name_,                  // file/dir name 
    921925                        folder_,                // path before name 
    922                         suffix_;                // after rightmost '.' 
     926                        suffix_;                // including leftmost '.' 
    923927 
    924928        /*********************************************************************** 
     
    10281032                Ext is the tail of the filename, rightward of the rightmost 
    10291033                '.' 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 
    10311035                example, ".." will wind up with no ext at all 
    10321036 
     
    10371041                auto x = suffix; 
    10381042                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                   } 
    10401052                return x; 
    10411053        }