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

Changeset 2812

Show
Ignore:
Timestamp:
11/08/07 16:16:18 (1 year ago)
Author:
sean
Message:

Fixes ticket #738.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/tango/io/FilePath.d

    r2808 r2812  
    7777        in that they will be assigned to the name instead of the suffix. In 
    7878        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. 
    8080 
    8181        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 
    8383        replacement of '/' for '\' (or vice versa) for the relevant platform. 
    8484 
     
    8989 
    9090class FilePath : PathView 
    91 {        
     91{ 
    9292        private char[]  fp;                     // filepath with trailing 0 
    9393 
     
    126126        /*********************************************************************** 
    127127 
    128                 Call-site shortcut to create a FilePath instance. This  
     128                Call-site shortcut to create a FilePath instance. This 
    129129                enables the same syntax as struct usage, so may expose 
    130130                a migration path 
     
    168168                Thus, FilePath combines both as a single operation. 
    169169 
    170                 When enabled, option 'native' will normalize path separators  
     170                When enabled, option 'native' will normalize path separators 
    171171                to those of the native OS 
    172172 
     
    207207 
    208208                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 
    210210                making a C call 
    211211 
     
    290290        /*********************************************************************** 
    291291 
    292                 Suffix is like ext, but includes the separator e.g. path  
     292                Suffix is like ext, but includes the separator e.g. path 
    293293                "foo.bar" has suffix ".bar" 
    294294 
     
    370370        /*********************************************************************** 
    371371 
    372                 Returns true if this FilePath has a parent. Note that a  
     372                Returns true if this FilePath has a parent. Note that a 
    373373                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 
    375375                child of the root 
    376376 
     
    430430        /*********************************************************************** 
    431431 
    432                 Prepend a folder to this path. A trailing separator is added  
     432                Prepend a folder to this path. A trailing separator is added 
    433433                if needed 
    434434 
     
    455455        /*********************************************************************** 
    456456 
    457                 Reset the content of this path, and reparse. When enabled,  
     457                Reset the content of this path, and reparse. When enabled, 
    458458                option 'native' will normalize path separators to those of 
    459459                the native OS 
     
    479479        /*********************************************************************** 
    480480 
    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 
    483483                will be skipped. 
    484484 
     
    508508        /*********************************************************************** 
    509509 
    510                 Replace the folder portion of this path. The folder will be  
     510                Replace the folder portion of this path. The folder will be 
    511511                padded with a path-separator as required 
    512512 
     
    536536        /*********************************************************************** 
    537537 
    538                 Replace the suffix portion of this path. The suffix will be  
     538                Replace the suffix portion of this path. The suffix will be 
    539539                prefixed with a file-separator as required 
    540540 
     
    549549        /*********************************************************************** 
    550550 
    551                 Replace the root and folder portions of this path and  
     551                Replace the root and folder portions of this path and 
    552552                reparse. The replacement will be padded with a path 
    553553                separator as required 
    554          
     554 
    555555        ***********************************************************************/ 
    556556 
     
    563563        /*********************************************************************** 
    564564 
    565                 Replace the file and suffix portions of this path and  
     565                Replace the file and suffix portions of this path and 
    566566                reparse. The replacement will be prefixed with a suffix 
    567567                separator as required 
    568          
     568 
    569569        ***********************************************************************/ 
    570570 
     
    577577        /*********************************************************************** 
    578578 
    579                 Pop to the parent of the current filepath (in situ)  
     579                Pop to the parent of the current filepath (in situ) 
    580580 
    581581        ***********************************************************************/ 
     
    736736        /*********************************************************************** 
    737737 
    738                 Insert/delete internal content  
     738                Insert/delete internal content 
    739739 
    740740        ***********************************************************************/ 
     
    830830                FileSystem.toAbsolute() 
    831831 
    832                 Note that each segment is created as a folder, including the  
     832                Note that each segment is created as a folder, including the 
    833833                trailing segment. 
    834834 
     
    872872                --- 
    873873 
    874                 Returning true from the filter includes the given path,  
     874                Returning true from the filter includes the given path, 
    875875                whilst returning false excludes it. Parameter 'isFolder' 
    876876                indicates whether the path is a file or folder. 
     
    890890                        // test this entry for inclusion 
    891891                        if (filter is null || filter (p, info.folder)) 
    892                             paths ~= p;                                                    
     892                            paths ~= p; 
    893893                        else 
    894894                           delete p; 
     
    914914                tmp [0 .. info.path.length] = info.path; 
    915915                tmp [info.path.length .. len] = info.name; 
    916          
     916 
    917917                return FilePath(tmp[0 .. len]).isFolder(info.folder); 
    918918        } 
     
    966966                private wchar[] toUtf16 (wchar[] tmp, char[] path) 
    967967                { 
    968                         auto i = MultiByteToWideChar (CP_UTF8, 0,  
    969                                                       path.ptr, path.length,  
     968                        auto i = MultiByteToWideChar (CP_UTF8, 0, 
     969                                                      path.ptr, path.length, 
    970970                                                      tmp.ptr, tmp.length); 
    971971                        return tmp [0..i]; 
     
    980980                private char[] toUtf8 (char[] tmp, wchar[] path) 
    981981                { 
    982                         auto i = WideCharToMultiByte (CP_UTF8, 0, path.ptr, path.length,  
     982                        auto i = WideCharToMultiByte (CP_UTF8, 0, path.ptr, path.length, 
    983983                                                      tmp.ptr, tmp.length, null, null); 
    984984                        return tmp [0..i]; 
     
    10611061                /*************************************************************** 
    10621062 
    1063                         Is this file actually a folder/directory?  
     1063                        Is this file actually a folder/directory? 
    10641064 
    10651065                ***************************************************************/ 
     
    11781178                        int     result; 
    11791179                        char[]  cstr = dst ~ '\0'; 
    1180                          
     1180 
    11811181                        version (Win32SansUnicode) 
    11821182                                 result = MoveFileExA (this.cString.ptr, cstr.ptr, Typical); 
     
    12521252                        List the set of filenames within this folder. 
    12531253 
    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 
    12561256                        the entry is a folder or not. 
    12571257 
     
    14011401                        static Time convert (timeval* tv) 
    14021402                        { 
    1403                                 return cast(Time) (Time.TicksTo1970 + (1_000_000L *  
     1403                                return cast(Time) (Time.TicksTo1970 + (1_000_000L * 
    14041404                                                   tv.tv_sec + tv.tv_usec) * 10); 
    14051405                        } 
     
    15481548                        List the set of filenames within this folder. 
    15491549 
    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 
    15521552                        the entry is a folder or not. 
    15531553 
     
    15961596                                 if (stat (sfnbuf.ptr, &sbuf)) 
    15971597                                     exception; 
    1598   
     1598 
    15991599                                 FileInfo info = void; 
    16001600                                 info.name   = str; 
     
    16031603                                 info.bytes  = (sbuf.st_mode & S_IFREG) != 0 ? sbuf.st_size : 0; 
    16041604 
    1605                                  if ((ret = dg(&info)) != 0) 
     1605                                 if ((ret = dg(info)) != 0) 
    16061606                                      break; 
    16071607                                 } 
     
    16921692        /*********************************************************************** 
    16931693 
    1694                 Suffix is like ext, but includes the separator e.g. path  
     1694                Suffix is like ext, but includes the separator e.g. path 
    16951695                "foo.bar" has suffix ".bar" 
    16961696