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

Changeset 1641

Show
Ignore:
Timestamp:
02/08/07 20:58:27 (2 years ago)
Author:
kris
Message:

Altered how FilePath?.join() operates, according to feedback from Kirk.
Renamed existing join() functions to be append() instead, and reversed their polarity

Files:

Legend:

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

    r1586 r1641  
    308308        /*********************************************************************** 
    309309 
    310                 Join this FilePath with the provided prefix. 
    311  
    312                 Assumes prefix is a directory name. If this is an absolute 
    313                 path it will be returned intact, ignoring prefix. 
    314  
    315         ***********************************************************************/ 
    316  
    317         final FilePath join (char[] prefix) 
    318         { 
    319                 if (isAbsolute) 
    320                     return this; 
    321  
    322                 return new FilePath (asPadded(prefix) ~ toUtf8); 
    323         } 
    324  
    325         /*********************************************************************** 
    326  
    327                 Join this FilePath with the provided prefix. 
    328  
    329                 Assumes prefix is a directory name. If this is an absolute 
    330                 path it will be returned intact, ignoring prefix. 
    331  
    332         ***********************************************************************/ 
    333  
    334         final FilePath join (FilePath prefix) 
    335         { 
    336                 return join (prefix.toUtf8); 
     310                Join this FilePath with the provided suffix 
     311 
     312        ***********************************************************************/ 
     313 
     314        final char[] append (char[] path) 
     315        { 
     316                return asPadded(toUtf8) ~ path; 
     317        } 
     318 
     319        /*********************************************************************** 
     320 
     321                Join this FilePath with the provided suffix 
     322 
     323        ***********************************************************************/ 
     324 
     325        final FilePath append (FilePath path) 
     326        { 
     327                return new FilePath (append (path.toUtf8)); 
     328        } 
     329 
     330        /*********************************************************************** 
     331 
     332                Join a set of path specs together. A path separator is  
     333                potentially inserted between each of the segments. 
     334 
     335        ***********************************************************************/ 
     336 
     337        static char[] join (char[][] paths...) 
     338        { 
     339                char[] result; 
     340 
     341                foreach (path; paths) 
     342                         result ~= asPadded (path);          
     343 
     344                return result.length ? result [0 .. $-1] : null; 
    337345        } 
    338346 
     
    515523debug (UnitTest) 
    516524{ 
     525        void main() {} 
     526 
    517527        unittest 
    518528        { 
     
    679689                assert (fp.getExt == ""); 
    680690 
    681                 fp = new FilePath(r"foo\bar\"); 
    682                 assert(fp.join(r"c:\joe\bar").toUtf8 == r"c:\joe\bar\foo\bar\"); 
    683                 assert(fp.join(new FilePath(r"c:\joe\bar")).toUtf8 == r"c:\joe\bar\foo\bar\"); 
    684691                fp = new FilePath(r"c:\joe\bar"); 
    685                 assert(fp.join(r"foo\bar\").toUtf8 == r"c:\joe\bar"); 
    686                 assert(fp.join(new FilePath(r"foo\bar")).toUtf8 == r"c:\joe\bar"); 
    687  
    688                 fp = new FilePath(r"c:\bar"); 
    689                 assert(fp.join(r"foo").toUtf8 == r"c:\bar"); 
    690                 assert(fp.join(new FilePath(r"foo")).toUtf8 == r"c:\bar"); 
    691  
    692                 fp = new FilePath(r"bar\"); 
    693                 assert(fp.join(r"c:\foo").toUtf8 == r"c:\foo\bar\"); 
    694                 assert(fp.join(new FilePath(r"c:\foo")).toUtf8 == r"c:\foo\bar\"); 
     692                assert(fp.append(r"foo\bar\") == r"c:\joe\bar\foo\bar\"); 
     693                assert(fp.append(new FilePath(r"foo\bar")).toUtf8 == r"c:\joe\bar\foo\bar"); 
     694 
     695                assert (FilePath.join (r"a\b\c\d", r"e\f\" r"g") == r"a\b\c\d\e\f\g"); 
    695696 
    696697                fp = new FilePath(r"C:\foo\bar\test.bar"); 
     
    863864                assert (fp.getExt == ""); 
    864865 
    865                 fp = new FilePath(r"foo/bar/"); 
    866                 assert(fp.join(r"/joe/bar").toUtf8 == r"/joe/bar/foo/bar/"); 
    867                 assert(fp.join(new FilePath(r"/joe/bar")).toUtf8 == r"/joe/bar/foo/bar/"); 
    868                 fp = new FilePath(r"/joe/bar"); 
    869                 assert(fp.join(r"foo/bar/").toUtf8 == r"/joe/bar"); 
    870                 assert(fp.join(new FilePath(r"foo/bar")).toUtf8 == r"/joe/bar"); 
    871  
    872                 fp = new FilePath(r"/bar"); 
    873                 assert(fp.join(r"foo").toUtf8 == r"/bar"); 
    874                 assert(fp.join(new FilePath(r"foo")).toUtf8 == r"/bar"); 
    875  
    876                 fp = new FilePath(r"bar/"); 
    877                 assert(fp.join(r"/foo").toUtf8 == r"/foo/bar/"); 
    878                 assert(fp.join(new FilePath(r"/foo")).toUtf8 == r"/foo/bar/"); 
     866                fp = new FilePath("/joe/bar"); 
     867                assert(fp.append("foo/bar/") == "/joe/bar/foo/bar/"); 
     868                assert(fp.append(new FilePath("foo/bar")).toUtf8 == "/joe/bar/foo/bar"); 
     869 
     870                assert (FilePath.join ("a/b/c/d", "e/f/" "g") == "a/b/c/d/e/f/g"); 
    879871 
    880872                fp = new FilePath(r"/foo/bar/test.bar"); 
  • trunk/tango/io/FileSystem.d

    r1464 r1641  
    5454                    return path; 
    5555 
    56                 return path.join (getDirectory); 
     56                return getDirectory.append (path); 
    5757        } 
    5858